https://github.com/python/cpython/commit/3683b2f9e5972a2feb67a051fcf898a1b58a54fe
commit: 3683b2f9e5972a2feb67a051fcf898a1b58a54fe
branch: main
author: Filipe LaΓ­ns πŸ‡΅πŸ‡Έ <[email protected]>
committer: FFY00 <[email protected]>
date: 2024-12-15T15:40:19Z
summary:

getpath: Add comments highlighing details of the pyvenv.cfg detection (#127966)

files:
M Modules/getpath.py

diff --git a/Modules/getpath.py b/Modules/getpath.py
index 7949fd813d0d07..b14f985a0d5f97 100644
--- a/Modules/getpath.py
+++ b/Modules/getpath.py
@@ -363,10 +363,20 @@ def search_up(prefix, *landmarks, test=isfile):
         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 @@ def search_up(prefix, *landmarks, test=isfile):
                                 break
             break
     else:
+        # We didn't find a 'home' key in pyvenv.cfg (no break), reset 
venv_prefix.
         venv_prefix = None
 
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to