Skip to content

Commit 4b10e20

Browse files
authored
gh-117786: Fix venv created from Windows Store install by restoring __PYVENV_LAUNCHER__ smuggling (GH-117814)
1 parent 8942bf4 commit 4b10e20

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

Lib/test/test_embed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,9 @@ def check_config(self, configs, expected):
747747
if value is self.IGNORE_CONFIG:
748748
config.pop(key, None)
749749
del expected[key]
750+
# Resolve bool/int mismatches to reduce noise in diffs
751+
if isinstance(value, (bool, int)) and isinstance(config.get(key), (bool, int)):
752+
expected[key] = type(config[key])(expected[key])
750753
self.assertEqual(config, expected)
751754

752755
def check_global_config(self, configs):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixes virtual environments not correctly launching when created from a Store
2+
install.

Modules/getpath.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,10 @@ def search_up(prefix, *landmarks, test=isfile):
310310
# and should not affect base_executable.
311311
base_executable = f"{dirname(library)}/bin/python{VERSION_MAJOR}.{VERSION_MINOR}"
312312
else:
313-
base_executable = executable
313+
# Use the real executable as our base, or argv[0] otherwise
314+
# (on Windows, argv[0] is likely to be ENV___PYVENV_LAUNCHER__; on
315+
# other platforms, real_executable is likely to be empty)
316+
base_executable = real_executable or executable
314317

315318
if not real_executable:
316319
real_executable = base_executable
@@ -408,13 +411,14 @@ def search_up(prefix, *landmarks, test=isfile):
408411
if not real_executable:
409412
real_executable = base_executable
410413

411-
try:
412-
real_executable = realpath(real_executable)
413-
except OSError as ex:
414-
# Only warn if the file actually exists and was unresolvable
415-
# Otherwise users who specify a fake executable may get spurious warnings.
416-
if isfile(real_executable):
417-
warn(f'Failed to find real location of {base_executable}')
414+
if real_executable:
415+
try:
416+
real_executable = realpath(real_executable)
417+
except OSError as ex:
418+
# Only warn if the file actually exists and was unresolvable
419+
# Otherwise users who specify a fake executable may get spurious warnings.
420+
if isfile(real_executable):
421+
warn(f'Failed to find real location of {base_executable}')
418422

419423
if not executable_dir and os_name == 'darwin' and library:
420424
# QUIRK: macOS checks adjacent to its library early
@@ -427,12 +431,12 @@ def search_up(prefix, *landmarks, test=isfile):
427431

428432
# If we do not have the executable's directory, we can calculate it.
429433
# This is the directory used to find prefix/exec_prefix if necessary.
430-
if not executable_dir:
434+
if not executable_dir and real_executable:
431435
executable_dir = real_executable_dir = dirname(real_executable)
432436

433437
# If we do not have the real executable's directory, we calculate it.
434438
# This is the directory used to detect build layouts.
435-
if not real_executable_dir:
439+
if not real_executable_dir and real_executable:
436440
real_executable_dir = dirname(real_executable)
437441

438442
# ******************************************************************************

PC/venvlauncher.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ process(int argc, wchar_t ** argv)
484484

485485
// We do not update argv[0] to point at the target runtime, and so we do not
486486
// pass through our original argv[0] in an environment variable.
487-
//exitCode = smuggle_path();
488-
//if (exitCode) return exitCode;
487+
exitCode = smuggle_path();
488+
if (exitCode) return exitCode;
489489

490490
exitCode = launch(home_path, GetCommandLineW());
491491
return exitCode;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy