@@ -66,6 +66,8 @@ def create(self, env_dir):
66
66
self .setup_python (context )
67
67
if self .with_pip :
68
68
self ._setup_pip (context )
69
+ # Truffle change: patch shebang
70
+ self ._patch_shebang (context )
69
71
if not self .upgrade :
70
72
self .setup_scripts (context )
71
73
self .post_setup (context )
@@ -179,6 +181,28 @@ def create_if_needed(d):
179
181
create_if_needed (binpath )
180
182
return context
181
183
184
+ def _patch_shebang (self , context ):
185
+ # Truffle change: we need to patch the pip/pip3 (and maybe other)
186
+ # launchers on Darwin because the shebang tries to invoke our
187
+ # graalpython shell script but Darwin strictly requires a binary
188
+ # in the shebang.
189
+ if sys .platform == "darwin" :
190
+ bin_dir = os .path .join (context .env_dir , context .bin_name )
191
+ python_exe = os .path .join (bin_dir , context .python_exe )
192
+ for entry in os .listdir (bin_dir ):
193
+ abs_entry = os .path .join (bin_dir , entry )
194
+ if os .path .isfile (abs_entry ):
195
+ with open (abs_entry , "r+" ) as f :
196
+ content = f .read ()
197
+ expected_shebang = "#!" + python_exe
198
+ if content .startswith (expected_shebang ):
199
+ f .seek (0 )
200
+ f .truncate ()
201
+ logging .info ("replacing shebang of {} (originally '{}') with '{}'" .format (entry , expected_shebang , "#!/bin/sh " + python_exe ))
202
+ content = content .replace (expected_shebang , "#!/bin/sh " + python_exe )
203
+ f .write (content )
204
+
205
+
182
206
def create_configuration (self , context ):
183
207
"""
184
208
Create a configuration file indicating where the environment's Python
0 commit comments