summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-11-10 16:53:51 (GMT)
committerGitHub <noreply@github.com>2022-11-10 16:53:51 (GMT)
commitc9f2177d13925536c662c1c9237ed0875b8b67da (patch)
tree772e90034e768839985de39cec7bb7d9e540c3f9 /Modules
parentf9a68be6733fba8b5003119445b08dedace9367e (diff)
downloadcpython-c9f2177d13925536c662c1c9237ed0875b8b67da.zip
cpython-c9f2177d13925536c662c1c9237ed0875b8b67da.tar.gz
cpython-c9f2177d13925536c662c1c9237ed0875b8b67da.tar.bz2
gh-99204: Calculate base_executable by alternate names in POSIX venvs (GH-99206)
Check to see if `base_executable` exists. If it does not, attempt to use known alternative names of the python binary to find an executable in the path specified by `home`. If no alternative is found, previous behavior is preserved. Signed-off-by: Vincent Fazio <vfazio@gmail.com> (cherry picked from commit c41b13d39ccc2d6e239782de99ba8e3cdd061e5a) Co-authored-by: Vincent Fazio <vfazio@gmail.com> Signed-off-by: Vincent Fazio <vfazio@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/getpath.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Modules/getpath.py b/Modules/getpath.py
index 91d6fc9..b8ad53e 100644
--- a/Modules/getpath.py
+++ b/Modules/getpath.py
@@ -375,6 +375,25 @@ if not home and not py_setpath:
pass
if not base_executable:
base_executable = joinpath(executable_dir, basename(executable))
+ # It's possible "python" is executed from within a posix venv but that
+ # "python" is not available in the "home" directory as the standard
+ # `make install` does not create it and distros often do not provide it.
+ #
+ # In this case, try to fall back to known alternatives
+ if os_name != 'nt' and not isfile(base_executable):
+ base_exe = basename(executable)
+ for candidate in (DEFAULT_PROGRAM_NAME, f'python{VERSION_MAJOR}.{VERSION_MINOR}'):
+ candidate += EXE_SUFFIX if EXE_SUFFIX else ''
+ if base_exe == candidate:
+ continue
+ candidate = joinpath(executable_dir, candidate)
+ # Only set base_executable if the candidate exists.
+ # If no candidate succeeds, subsequent errors related to
+ # base_executable (like FileNotFoundError) remain in the
+ # context of the original executable name
+ if isfile(candidate):
+ base_executable = candidate
+ break
break
else:
venv_prefix = None