Skip to content

Commit 3683b2f

Browse files
authored
getpath: Add comments highlighing details of the pyvenv.cfg detection (#127966)
1 parent ab05beb commit 3683b2f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Modules/getpath.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,20 @@ def search_up(prefix, *landmarks, test=isfile):
363363
venv_prefix = None
364364
pyvenvcfg = []
365365

366+
# Search for the 'home' key in pyvenv.cfg. Currently, we don't consider the
367+
# presence of a pyvenv.cfg file without a 'home' key to signify the
368+
# existence of a virtual environment — we quietly ignore them.
369+
# XXX: If we don't find a 'home' key, we don't look for another pyvenv.cfg!
366370
for line in pyvenvcfg:
367371
key, had_equ, value = line.partition('=')
368372
if had_equ and key.strip().lower() == 'home':
373+
# Override executable_dir/real_executable_dir with the value from 'home'.
374+
# These values may be later used to calculate prefix/base_prefix, if a more
375+
# reliable source — like the runtime library (libpython) path — isn't available.
369376
executable_dir = real_executable_dir = value.strip()
377+
# If base_executable — which points to the Python interpreted from
378+
# the base installation — isn't set (eg. when embedded), try to find
379+
# it in 'home'.
370380
if not base_executable:
371381
# First try to resolve symlinked executables, since that may be
372382
# more accurate than assuming the executable in 'home'.
@@ -400,6 +410,7 @@ def search_up(prefix, *landmarks, test=isfile):
400410
break
401411
break
402412
else:
413+
# We didn't find a 'home' key in pyvenv.cfg (no break), reset venv_prefix.
403414
venv_prefix = None
404415

405416

0 commit comments

Comments
 (0)