@@ -187,7 +187,7 @@ def find_py(cls):
187
187
)
188
188
return py_exe
189
189
190
- def run_py (self , args , env = None , allow_fail = False , expect_returncode = 0 ):
190
+ def run_py (self , args , env = None , allow_fail = False , expect_returncode = 0 , short_argv0 = False ):
191
191
if not self .py_exe :
192
192
self .py_exe = self .find_py ()
193
193
@@ -198,9 +198,14 @@ def run_py(self, args, env=None, allow_fail=False, expect_returncode=0):
198
198
"PYLAUNCHER_DEBUG" : "1" ,
199
199
"PYLAUNCHER_DRYRUN" : "1" ,
200
200
}
201
+ cwd , py_exe = None , self .py_exe
202
+ if short_argv0 :
203
+ cwd , py_exe = str (py_exe .parent ), f'"{ py_exe .name } "'
201
204
with subprocess .Popen (
202
- [self . py_exe , * args ],
205
+ [py_exe , * args ],
203
206
env = env ,
207
+ cwd = cwd ,
208
+ executable = self .py_exe ,
204
209
stdin = subprocess .PIPE ,
205
210
stdout = subprocess .PIPE ,
206
211
stderr = subprocess .PIPE ,
@@ -539,6 +544,14 @@ def test_py3_shebang_nl(self):
539
544
self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
540
545
self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { script } -postarg" , data ["stdout" ].strip ())
541
546
547
+ def test_py_shebang_short_argv0 (self ):
548
+ with self .py_ini (TEST_PY_COMMANDS ):
549
+ with self .script ("#! /usr/bin/env python -prearg" ) as script :
550
+ data = self .run_py ([script , "-postarg" ], short_argv0 = True )
551
+ self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
552
+ self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
553
+ self .assertEqual (f"X.Y.exe -prearg { script } -postarg" , data ["stdout" ].strip ())
554
+
542
555
def test_install (self ):
543
556
data = self .run_py (["-V:3.10" ], env = {"PYLAUNCHER_ALWAYS_INSTALL" : "1" }, expect_returncode = 111 )
544
557
cmd = data ["stdout" ].strip ()
0 commit comments