From 24574ec0c2813bf923b9967716b54d8c0a541afc Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Wed, 22 May 2024 19:46:31 +0100 Subject: [PATCH 1/2] gh-119070: Fix py.exe handling of /usr/bin/env commands missing extension --- Lib/site-packages/README.txt | 2 -- Lib/test/test_launcher.py | 8 ++++++++ .../2024-05-22-19-43-29.gh-issue-119070._enton.rst | 3 +++ PC/launcher2.c | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) delete mode 100644 Lib/site-packages/README.txt create mode 100644 Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst diff --git a/Lib/site-packages/README.txt b/Lib/site-packages/README.txt deleted file mode 100644 index 273f6251a7f9d9..00000000000000 --- a/Lib/site-packages/README.txt +++ /dev/null @@ -1,2 +0,0 @@ -This directory exists so that 3rd party packages can be installed -here. Read the source for site.py for more details. diff --git a/Lib/test/test_launcher.py b/Lib/test/test_launcher.py index 2528a51240fbf7..6d358ac6f16a27 100644 --- a/Lib/test/test_launcher.py +++ b/Lib/test/test_launcher.py @@ -764,3 +764,11 @@ def test_shebang_command_in_venv(self): with self.script(f'#! /usr/bin/env {exe.stem} arg1') as script: data = self.run_py([script], env=env) self.assertEqual(data["stdout"].strip(), f"{quote(exe)} arg1 {quote(script)}") + + def test_shebang_executable_extension(self): + with self.script('#! /usr/bin/env python3.12') as script: + data = self.run_py([script]) + expect = "# Search PATH for python3.12.exe" + actual = [line.strip() for line in data["stderr"].splitlines() + if line.startswith("# Search PATH")] + self.assertEqual([expect], actual) diff --git a/Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst b/Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst new file mode 100644 index 00000000000000..aab26f57209864 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2024-05-22-19-43-29.gh-issue-119070._enton.rst @@ -0,0 +1,3 @@ +Fixes ``py.exe`` handling of shebangs like ``/usr/bin/env python3.12``, +which were previously interpreted as ``python3.exe`` instead of +``python3.12.exe``. diff --git a/PC/launcher2.c b/PC/launcher2.c index 98231613efb26f..b372044e353202 100644 --- a/PC/launcher2.c +++ b/PC/launcher2.c @@ -853,7 +853,7 @@ searchPath(SearchInfo *search, const wchar_t *shebang, int shebangLength) } wchar_t filename[MAXLEN]; - if (wcsncpy_s(filename, MAXLEN, command, lastDot)) { + if (wcsncpy_s(filename, MAXLEN, command, commandLength)) { return RC_BAD_VIRTUAL_PATH; } From 78cd3da7e4805dd3225809a619b4a43d2448c120 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Tue, 28 May 2024 13:29:17 +0100 Subject: [PATCH 2/2] Restore deleted file --- Lib/site-packages/README.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Lib/site-packages/README.txt diff --git a/Lib/site-packages/README.txt b/Lib/site-packages/README.txt new file mode 100644 index 00000000000000..273f6251a7f9d9 --- /dev/null +++ b/Lib/site-packages/README.txt @@ -0,0 +1,2 @@ +This directory exists so that 3rd party packages can be installed +here. Read the source for site.py for more details.