@@ -150,7 +150,7 @@ class RunPyMixin:
150150 @classmethod
151151 def find_py (cls ):
152152 py_exe = None
153- if sysconfig .is_python_build (True ):
153+ if sysconfig .is_python_build ():
154154 py_exe = Path (sys .executable ).parent / PY_EXE
155155 else :
156156 for p in os .getenv ("PATH" ).split (";" ):
@@ -188,7 +188,7 @@ def find_py(cls):
188188 )
189189 return py_exe
190190
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 ):
192192 if not self .py_exe :
193193 self .py_exe = self .find_py ()
194194
@@ -199,9 +199,12 @@ def run_py(self, args, env=None, allow_fail=False, expect_returncode=0):
199199 "PYLAUNCHER_DEBUG" : "1" ,
200200 "PYLAUNCHER_DRYRUN" : "1" ,
201201 }
202+ if not argv :
203+ argv = [self .py_exe , * args ]
202204 with subprocess .Popen (
203- [ self . py_exe , * args ] ,
205+ argv ,
204206 env = env ,
207+ executable = self .py_exe ,
205208 stdin = subprocess .PIPE ,
206209 stdout = subprocess .PIPE ,
207210 stderr = subprocess .PIPE ,
@@ -540,6 +543,15 @@ def test_py3_shebang_nl(self):
540543 self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
541544 self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { script } -postarg" , data ["stdout" ].strip ())
542545
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+
543555 def test_install (self ):
544556 data = self .run_py (["-V:3.10" ], env = {"PYLAUNCHER_ALWAYS_INSTALL" : "1" }, expect_returncode = 111 )
545557 cmd = data ["stdout" ].strip ()
0 commit comments