@@ -149,7 +149,7 @@ class RunPyMixin:
149149 @classmethod
150150 def find_py (cls ):
151151 py_exe = None
152- if sysconfig .is_python_build (True ):
152+ if sysconfig .is_python_build ():
153153 py_exe = Path (sys .executable ).parent / PY_EXE
154154 else :
155155 for p in os .getenv ("PATH" ).split (";" ):
@@ -187,7 +187,7 @@ def find_py(cls):
187187 )
188188 return py_exe
189189
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 ):
191191 if not self .py_exe :
192192 self .py_exe = self .find_py ()
193193
@@ -198,9 +198,12 @@ def run_py(self, args, env=None, allow_fail=False, expect_returncode=0):
198198 "PYLAUNCHER_DEBUG" : "1" ,
199199 "PYLAUNCHER_DRYRUN" : "1" ,
200200 }
201+ if not argv :
202+ argv = [self .py_exe , * args ]
201203 with subprocess .Popen (
202- [ self . py_exe , * args ] ,
204+ argv ,
203205 env = env ,
206+ executable = self .py_exe ,
204207 stdin = subprocess .PIPE ,
205208 stdout = subprocess .PIPE ,
206209 stderr = subprocess .PIPE ,
@@ -539,6 +542,15 @@ def test_py3_shebang_nl(self):
539542 self .assertEqual ("3.100-arm64" , data ["SearchInfo.tag" ])
540543 self .assertEqual (f"X.Y-arm64.exe -X fake_arg_for_test -prearg { script } -postarg" , data ["stdout" ].strip ())
541544
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+
542554 def test_install (self ):
543555 data = self .run_py (["-V:3.10" ], env = {"PYLAUNCHER_ALWAYS_INSTALL" : "1" }, expect_returncode = 111 )
544556 cmd = data ["stdout" ].strip ()
0 commit comments