10000 gh-95285: py.exe launcher fails with short argv0 (GH-95295) · python/cpython@7ac5bb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ac5bb3

Browse files
authored
gh-95285: py.exe launcher fails with short argv0 (GH-95295)
1 parent 51c56f8 commit 7ac5bb3

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

Lib/test/test_launcher.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :ref:`launcher` handling of command lines where it is only passed a
2+
short executable name.

PC/launcher2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,9 @@ parseCommandLine(SearchInfo *search)
580580
break;
581581
}
582582
}
583+
if (tail == search->originalCmdLine && tail[0] == L'"') {
584+
++tail;
585+
}
583586
// Without special cases, we can now fill in the search struct
584587
int tailLen = (int)(end ? (end - tail) : wcsnlen_s(tail, MAXLEN));
585588
search->executableLength = -1;

0 commit comments

Comments
 (0)
0