diff options
author | Steve Dower <steve.dower@python.org> | 2021-10-07 20:26:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-07 20:26:12 (GMT) |
commit | 6811fdaec825bd6ab64e358a4b480108f5634d2d (patch) | |
tree | d8fec7b6f35c5cc93ec36341a0a0a9ab4fe95cbf /Lib/venv | |
parent | 8deb7afbaaaad847656842375119f8dbef8aea54 (diff) | |
download | cpython-6811fdaec825bd6ab64e358a4b480108f5634d2d.zip cpython-6811fdaec825bd6ab64e358a4b480108f5634d2d.tar.gz cpython-6811fdaec825bd6ab64e358a4b480108f5634d2d.tar.bz2 |
bpo-45337: Use the realpath of the new executable when creating a venv on Windows (GH-28663)
Diffstat (limited to 'Lib/venv')
-rw-r--r-- | Lib/venv/__init__.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index b007e25..6f1af29 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -142,6 +142,20 @@ class EnvBuilder: context.bin_name = binname context.env_exe = os.path.join(binpath, exename) create_if_needed(binpath) + # Assign and update the command to use when launching the newly created + # environment, in case it isn't simply the executable script (e.g. bpo-45337) + context.env_exec_cmd = context.env_exe + if sys.platform == 'win32': + # bpo-45337: Fix up env_exec_cmd to account for file system redirections. + # Some redirects only apply to CreateFile and not CreateProcess + real_env_exe = os.path.realpath(context.env_exe) + if os.path.normcase(real_env_exe) != os.path.normcase(context.env_exe): + logger.warning('Actual environment location may have moved due to ' + 'redirects, links or junctions.\n' + ' Requested location: "%s"\n' + ' Actual location: "%s"', + context.env_exe, real_env_exe) + context.env_exec_cmd = real_env_exe return context def create_configuration(self, context): @@ -294,8 +308,8 @@ class EnvBuilder: # We run ensurepip in isolated mode to avoid side effects from # environment vars, the current directory and anything else # intended for the global Python environment - cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade', - '--default-pip'] + cmd = [context.env_exec_cmd, '-Im', 'ensurepip', '--upgrade', + '--default-pip'] subprocess.check_output(cmd, stderr=subprocess.STDOUT) def setup_scripts(self, context): @@ -395,11 +409,7 @@ class EnvBuilder: logger.debug( f'Upgrading {CORE_VENV_DEPS} packages in {context.bin_path}' ) - if sys.platform == 'win32': - python_exe = os.path.join(context.bin_path, 'python.exe') - else: - python_exe = os.path.join(context.bin_path, 'python') - cmd = [python_exe, '-m', 'pip', 'install', '--upgrade'] + cmd = [context.env_exec_cmd, '-m', 'pip', 'install', '--upgrade'] cmd.extend(CORE_VENV_DEPS) subprocess.check_call(cmd) |