summaryrefslogtreecommitdiffstats
path: root/Modules/getpath.py
diff options
context:
space:
mode:
authorFilipe LaΓ­ns πŸ‡΅πŸ‡Έ <lains@riseup.net>2024-12-15 15:40:19 (GMT)
committerGitHub <noreply@github.com>2024-12-15 15:40:19 (GMT)
commit3683b2f9e5972a2feb67a051fcf898a1b58a54fe (patch)
tree4c0d2f369d4b7df387ed3bcf751d639d48d8de0c /Modules/getpath.py
parentab05beb8cea62636bd86f6f7cf1a82d7efca7162 (diff)
downloadcpython-3683b2f9e5972a2feb67a051fcf898a1b58a54fe.zip
cpython-3683b2f9e5972a2feb67a051fcf898a1b58a54fe.tar.gz
cpython-3683b2f9e5972a2feb67a051fcf898a1b58a54fe.tar.bz2
getpath: Add comments highlighing details of the pyvenv.cfg detection (#127966)
Diffstat (limited to 'Modules/getpath.py')
-rw-r--r--Modules/getpath.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Modules/getpath.py b/Modules/getpath.py
index 7949fd8..b14f985 100644
--- a/Modules/getpath.py
+++ b/Modules/getpath.py
@@ -363,10 +363,20 @@ if not home and not py_setpath:
venv_prefix = None
pyvenvcfg = []
+ # Search for the 'home' key in pyvenv.cfg. Currently, we don't consider the
+ # presence of a pyvenv.cfg file without a 'home' key to signify the
+ # existence of a virtual environment β€” we quietly ignore them.
+ # XXX: If we don't find a 'home' key, we don't look for another pyvenv.cfg!
for line in pyvenvcfg:
key, had_equ, value = line.partition('=')
if had_equ and key.strip().lower() == 'home':
+ # Override executable_dir/real_executable_dir with the value from 'home'.
+ # These values may be later used to calculate prefix/base_prefix, if a more
+ # reliable source β€” like the runtime library (libpython) path β€” isn't available.
executable_dir = real_executable_dir = value.strip()
+ # If base_executable β€” which points to the Python interpreted from
+ # the base installation β€” isn't set (eg. when embedded), try to find
+ # it in 'home'.
if not base_executable:
# First try to resolve symlinked executables, since that may be
# more accurate than assuming the executable in 'home'.
@@ -400,6 +410,7 @@ if not home and not py_setpath:
break
break
else:
+ # We didn't find a 'home' key in pyvenv.cfg (no break), reset venv_prefix.
venv_prefix = None