summaryrefslogtreecommitdiffstats
path: root/Modules/getpath.py
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2022-01-18 15:46:26 (GMT)
committerGitHub <noreply@github.com>2022-01-18 15:46:26 (GMT)
commit7407fe4c25ba0308d49e3e88e4a107ef32251cdc (patch)
tree38712e77d784e1beb2e1e5bf19d39db596ef6c0f /Modules/getpath.py
parent32398294fb3fcf4ee74da54722fd0221c4e6cb74 (diff)
downloadcpython-7407fe4c25ba0308d49e3e88e4a107ef32251cdc.zip
cpython-7407fe4c25ba0308d49e3e88e4a107ef32251cdc.tar.gz
cpython-7407fe4c25ba0308d49e3e88e4a107ef32251cdc.tar.bz2
bpo-46028: Calculate base_executable by resolving symlinks in a venv (GH-30144)
Diffstat (limited to 'Modules/getpath.py')
-rw-r--r--Modules/getpath.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/getpath.py b/Modules/getpath.py
index 6f2e038..f84e6e8 100644
--- a/Modules/getpath.py
+++ b/Modules/getpath.py
@@ -351,7 +351,18 @@ if not home and not py_setpath:
key, had_equ, value = line.partition('=')
if had_equ and key.strip().lower() == 'home':
executable_dir = real_executable_dir = value.strip()
- base_executable = joinpath(executable_dir, basename(executable))
+ if not base_executable:
+ # First try to resolve symlinked executables, since that may be
+ # more accurate than assuming the executable in 'home'.
+ try:
+ base_executable = realpath(executable)
+ if base_executable == executable:
+ # No change, so probably not a link. Clear it and fall back
+ base_executable = ''
+ except OSError:
+ pass
+ if not base_executable:
+ base_executable = joinpath(executable_dir, basename(executable))
break
else:
venv_prefix = None