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