@@ -149,7 +149,7 @@ class RunPyMixin:
149
149
@classmethod
150
150
def find_py (cls ):
151
151
py_exe = None
152
- if sysconfig .is_python_build (True ):
152
+ if sysconfig .is_python_build ():
153
153
py_exe = Path (sys .executable ).parent / PY_EXE
154
154
else :
155
155
for p in os .getenv ("PATH" ).split (";" ):
@@ -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 , argv = None ):
191
191
if not self .py_exe :
192
192
self .py_exe = self .find_py ()
193
193
@@ -198,9 +198,12 @@ 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
+ if not argv :
202
+ argv = [self .py_exe , * args ]
201
203
with subprocess .Popen (
202
- [ self . py_exe , * args ] ,
204
+ argv ,
203
205
env = env ,
206
+ executable = self .py_exe ,
204
207
stdin = subprocess .PIPE ,
205
208
stdout = subprocess .PIPE ,
206
209
stderr = subprocess .PIPE ,
@@ -539,6 +542,15 @@ def test_py3_shebang_nl(self):
539
542
self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
540
543
self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { script } -postarg" , data ["stdout" ].strip ())
541
544
545
+ def test_py_shebang_short_argv0 (self ):
546
+ with self .py_ini (TEST_PY_COMMANDS ):
547
+ with self .script ("#! /usr/bin/env python -prearg" ) as script :
548
+ # Override argv to only pass "py.exe" as the command
549
+ data = self .run_py ([script , "-postarg" ], argv = f'"py.exe" "{ script } " -postarg' )
550
+ self .assertEqual ("PythonTestSuite" , data ["SearchInfo.company" ])
551
+ self .assertEqual ("3.100" , data ["SearchInfo.tag" ])
552
+ self .assertEqual (f'X.Y.exe -prearg "{ script } " -postarg' , data ["stdout" ].strip ())
553
+
542
554
def test_install (self ):
543
555
data = self .run_py (["-V:3.10" ], env = {"PYLAUNCHER_ALWAYS_INSTALL" : "1" }, expect_returncode = 111 )
544
556
cmd = data ["stdout" ].strip ()
0 commit comments