Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-117786: Fix venv created from Windows Store install by restoring __PYVENV_LAUNCHER__ smuggling #117814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,9 @@ def check_config(self, configs, expected):
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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes virtual environments not correctly launching when created from a Store
install.
24 changes: 14 additions & 10 deletions Modules/getpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ def search_up(prefix, *landmarks, test=isfile):
# 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
Expand Down Expand Up @@ -408,13 +411,14 @@ def search_up(prefix, *landmarks, test=isfile):
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
Expand All @@ -427,12 +431,12 @@ def search_up(prefix, *landmarks, test=isfile):

# 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)

# ******************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions PC/venvlauncher.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down