]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117786: Fix venv created from Windows Store install by restoring __PYVENV_LAUNCHER...
authorSteve Dower <steve.dower@python.org>
Wed, 24 Apr 2024 22:00:55 +0000 (23:00 +0100)
committerGitHub <noreply@github.com>
Wed, 24 Apr 2024 22:00:55 +0000 (23:00 +0100)
Lib/test/test_embed.py
Misc/NEWS.d/next/Windows/2024-04-12-13-18-42.gh-issue-117786.LpI01s.rst [new file with mode: 0644]
Modules/getpath.py
PC/venvlauncher.c

index ec928f935655f9030afcb8f639afb0048f95e9a3..d94c63a13b8ea40d177a3eda10ed162ed7e01f2f 100644 (file)
@@ -747,6 +747,9 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
             if value is self.IGNORE_CONFIG:
                 config.pop(key, None)
                 del expected[key]
+            # Resolve bool/int mismatches to reduce noise in diffs
+            if isinstance(value, (bool, int)) and isinstance(config.get(key), (bool, int)):
+                expected[key] = type(config[key])(expected[key])
         self.assertEqual(config, expected)
 
     def check_global_config(self, configs):
diff --git a/Misc/NEWS.d/next/Windows/2024-04-12-13-18-42.gh-issue-117786.LpI01s.rst b/Misc/NEWS.d/next/Windows/2024-04-12-13-18-42.gh-issue-117786.LpI01s.rst
new file mode 100644 (file)
index 0000000..a4cd9a9
--- /dev/null
@@ -0,0 +1,2 @@
+Fixes virtual environments not correctly launching when created from a Store
+install.
index 1410ffdbed8c70c557e56048f9e1b3e673ba613e..bc7053224aaf1613da6da87358bb8be366dae39c 100644 (file)
@@ -310,7 +310,10 @@ if ENV_PYTHONEXECUTABLE or ENV___PYVENV_LAUNCHER__:
         # and should not affect base_executable.
         base_executable = f"{dirname(library)}/bin/python{VERSION_MAJOR}.{VERSION_MINOR}"
     else:
-        base_executable = executable
+        # Use the real executable as our base, or argv[0] otherwise
+        # (on Windows, argv[0] is likely to be ENV___PYVENV_LAUNCHER__; on
+        # other platforms, real_executable is likely to be empty)
+        base_executable = real_executable or executable
 
     if not real_executable:
         real_executable = base_executable
@@ -408,13 +411,14 @@ if not base_executable:
 if not real_executable:
     real_executable = base_executable
 
-try:
-    real_executable = realpath(real_executable)
-except OSError as ex:
-    # Only warn if the file actually exists and was unresolvable
-    # Otherwise users who specify a fake executable may get spurious warnings.
-    if isfile(real_executable):
-        warn(f'Failed to find real location of {base_executable}')
+if real_executable:
+    try:
+        real_executable = realpath(real_executable)
+    except OSError as ex:
+        # Only warn if the file actually exists and was unresolvable
+        # Otherwise users who specify a fake executable may get spurious warnings.
+        if isfile(real_executable):
+            warn(f'Failed to find real location of {base_executable}')
 
 if not executable_dir and os_name == 'darwin' and library:
     # QUIRK: macOS checks adjacent to its library early
@@ -427,12 +431,12 @@ if not executable_dir and os_name == 'darwin' and library:
 
 # If we do not have the executable's directory, we can calculate it.
 # This is the directory used to find prefix/exec_prefix if necessary.
-if not executable_dir:
+if not executable_dir and real_executable:
     executable_dir = real_executable_dir = dirname(real_executable)
 
 # If we do not have the real executable's directory, we calculate it.
 # This is the directory used to detect build layouts.
-if not real_executable_dir:
+if not real_executable_dir and real_executable:
     real_executable_dir = dirname(real_executable)
 
 # ******************************************************************************
index fe97d32e93b5f69508ee28abc29f6cd4e1dceb8a..b1c8d0763d8c76aaaa29846876a1e15bfc65df38 100644 (file)
@@ -484,8 +484,8 @@ process(int argc, wchar_t ** argv)
 
     // We do not update argv[0] to point at the target runtime, and so we do not
     // pass through our original argv[0] in an environment variable.
-    //exitCode = smuggle_path();
-    //if (exitCode) return exitCode;
+    exitCode = smuggle_path();
+    if (exitCode) return exitCode;
 
     exitCode = launch(home_path, GetCommandLineW());
     return exitCode;