From b08755ae1c4a568776fd306a6b2c790c71e4df62 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Mon, 28 Oct 2024 19:51:00 +0100 Subject: [PATCH 1/8] Fix venvwlauncher to run pythonw Fixes #126084 --- PCbuild/venvwlauncher.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PCbuild/venvwlauncher.vcxproj b/PCbuild/venvwlauncher.vcxproj index 1b61718201367f..db7128272f06db 100644 --- a/PCbuild/venvwlauncher.vcxproj +++ b/PCbuild/venvwlauncher.vcxproj @@ -92,7 +92,7 @@ - EXENAME=L"$(PyExeName)$(PyDebugExt).exe";_WINDOWS;%(PreprocessorDefinitions) + EXENAME=L"$(PyWExeName)$(PyDebugExt).exe";_WINDOWS;%(PreprocessorDefinitions) MultiThreaded From 4127748fbd8a8fd181b2b0467f139311df6c54d7 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Tue, 29 Oct 2024 09:39:25 +0100 Subject: [PATCH 2/8] Add NEWS entry --- .../next/Windows/2024-10-29-09-39-06.gh-issue-126084.3wAL8o.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Windows/2024-10-29-09-39-06.gh-issue-126084.3wAL8o.rst diff --git a/Misc/NEWS.d/next/Windows/2024-10-29-09-39-06.gh-issue-126084.3wAL8o.rst b/Misc/NEWS.d/next/Windows/2024-10-29-09-39-06.gh-issue-126084.3wAL8o.rst new file mode 100644 index 00000000000000..319053d95db19e --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2024-10-29-09-39-06.gh-issue-126084.3wAL8o.rst @@ -0,0 +1,2 @@ +Fix venvwlauncher to launch pythonw instead of python so no extra console +window is created. From 58f9d7a912e8cf0a198085928ec8a5dc12f35d96 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Tue, 29 Oct 2024 10:36:07 +0100 Subject: [PATCH 3/8] Add test --- Lib/test/test_venv.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 6b2127bd31e40a..5325df10f909d1 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -872,6 +872,23 @@ def test_venv_same_path(self): else: self.assertFalse(same_path(path1, path2)) + # gh-126084: venvwlauncher should run pythonw, not python + @requireVenvCreate + @unittest.skipUnless(os.name == 'nt', 'only relevant on Windows') + def test_venvwlauncher(self): + """ + Test that the GUI launcher runs the GUI python. + """ + rmtree(self.env_dir) + venv.create(self.env_dir) + pythonw = os.path.join(self.env_dir, self.bindir, "pythonw.exe") + try: + subprocess.check_call([pythonw, "-c", "import _winapi; " + "assert _winapi.GetModuleFileName(0).endswith('pythonw.exe')"]) + except subprocess.CalledProcessError: + self.fail("venvwlauncher.exe did not run pythonw.exe") + + @requireVenvCreate class EnsurePipTest(BaseTest): """Test venv module installation of pip.""" From f55f29fd95878d29190cc7a0cf779a64fdc51a67 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Tue, 29 Oct 2024 13:11:46 +0100 Subject: [PATCH 4/8] Improve test And perhaps make it work on GitHub ... --- Lib/test/test_venv.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 5325df10f909d1..2da47b5cddf3d7 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -881,12 +881,13 @@ def test_venvwlauncher(self): """ rmtree(self.env_dir) venv.create(self.env_dir) - pythonw = os.path.join(self.env_dir, self.bindir, "pythonw.exe") + exename = "pythonw.exe" + envpyw = os.path.join(os.path.realpath(self.env_dir), self.bindir, exename) try: - subprocess.check_call([pythonw, "-c", "import _winapi; " - "assert _winapi.GetModuleFileName(0).endswith('pythonw.exe')"]) + subprocess.check_call([envpyw, "-c", "import _winapi; " + "assert _winapi.GetModuleFileName(0).endswith('%s')" % exename]) except subprocess.CalledProcessError: - self.fail("venvwlauncher.exe did not run pythonw.exe") + self.fail("venvwlauncher.exe did not run %s" % exename) @requireVenvCreate From 859b5e9e3bff8d77414507db8b17823e42da9b2c Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Tue, 29 Oct 2024 13:30:17 +0100 Subject: [PATCH 5/8] Revert failed attempt to fix the test --- Lib/test/test_venv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 2da47b5cddf3d7..78e377471f52c7 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -882,7 +882,7 @@ def test_venvwlauncher(self): rmtree(self.env_dir) venv.create(self.env_dir) exename = "pythonw.exe" - envpyw = os.path.join(os.path.realpath(self.env_dir), self.bindir, exename) + envpyw = os.path.join(self.env_dir, self.bindir, exename) try: subprocess.check_call([envpyw, "-c", "import _winapi; " "assert _winapi.GetModuleFileName(0).endswith('%s')" % exename]) From b4c7e61e84804db35a30138ca9e7bb225c86701c Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Tue, 29 Oct 2024 14:00:02 +0100 Subject: [PATCH 6/8] Try another way --- Lib/test/test_venv.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 78e377471f52c7..458d4ecfc0ee7c 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -884,8 +884,8 @@ def test_venvwlauncher(self): exename = "pythonw.exe" envpyw = os.path.join(self.env_dir, self.bindir, exename) try: - subprocess.check_call([envpyw, "-c", "import _winapi; " - "assert _winapi.GetModuleFileName(0).endswith('%s')" % exename]) + subprocess.check_call([envpyw, "-c", "import sys; " + "assert sys._base_executable.endswith('%s')" % exename]) except subprocess.CalledProcessError: self.fail("venvwlauncher.exe did not run %s" % exename) From 57c89cd294f744305a997c247a0cd6aed36c75d5 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Tue, 29 Oct 2024 14:18:36 +0100 Subject: [PATCH 7/8] And another --- Lib/test/test_venv.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 458d4ecfc0ee7c..259eaae322aa7a 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -881,7 +881,7 @@ def test_venvwlauncher(self): """ rmtree(self.env_dir) venv.create(self.env_dir) - exename = "pythonw.exe" + exename = "pythonw_d.exe" envpyw = os.path.join(self.env_dir, self.bindir, exename) try: subprocess.check_call([envpyw, "-c", "import sys; " From c455ab0d687b9988ef9c699053c0680e7922d3c5 Mon Sep 17 00:00:00 2001 From: Christian Ullrich Date: Tue, 29 Oct 2024 14:42:13 +0100 Subject: [PATCH 8/8] And one more --- Lib/test/test_venv.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 259eaae322aa7a..0b09010c69d4ea 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -881,7 +881,10 @@ def test_venvwlauncher(self): """ rmtree(self.env_dir) venv.create(self.env_dir) - exename = "pythonw_d.exe" + exename = self.exe + # Retain the debug suffix if present + if "python" in exename and not "pythonw" in exename: + exename = exename.replace("python", "pythonw") envpyw = os.path.join(self.env_dir, self.bindir, exename) try: subprocess.check_call([envpyw, "-c", "import sys; "