Skip to content

Commit 7a25310

Browse files
authored
gh-101543: Ensure Windows registry path is only used when stdlib can't be found (GH-101544)
1 parent 46416b9 commit 7a25310

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ensure the install path in the registry is only used when the standard
2+
library hasn't been located in any other way.

Modules/getpath.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ def search_up(prefix, *landmarks, test=isfile):
582582
# Detect prefix by searching from our executable location for the stdlib_dir
583583
if STDLIB_SUBDIR and STDLIB_LANDMARKS and executable_dir and not prefix:
584584
prefix = search_up(executable_dir, *STDLIB_LANDMARKS)
585-
if prefix:
585+
if prefix and not stdlib_dir:
586586
stdlib_dir = joinpath(prefix, STDLIB_SUBDIR)
587587

588588
if PREFIX and not prefix:
@@ -631,20 +631,6 @@ def search_up(prefix, *landmarks, test=isfile):
631631
warn('Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]')
632632

633633

634-
# If we haven't set [plat]stdlib_dir already, set them now
635-
if not stdlib_dir:
636-
if prefix:
637-
stdlib_dir = joinpath(prefix, STDLIB_SUBDIR)
638-
else:
639-
stdlib_dir = ''
640-
641-
if not platstdlib_dir:
642-
if exec_prefix:
643-
platstdlib_dir = joinpath(exec_prefix, PLATSTDLIB_LANDMARK)
644-
else:
645-
platstdlib_dir = ''
646-
647-
648634
# For a venv, update the main prefix/exec_prefix but leave the base ones unchanged
649635
# XXX: We currently do not update prefix here, but it happens in site.py
650636
#if venv_prefix:
@@ -706,8 +692,9 @@ def search_up(prefix, *landmarks, test=isfile):
706692
pythonpath.extend(v.split(DELIM))
707693
i += 1
708694
# Paths from the core key get appended last, but only
709-
# when home was not set and we aren't in a build dir
710-
if not home_was_set and not venv_prefix and not build_prefix:
695+
# when home was not set and we haven't found our stdlib
696+
# some other way.
697+
if not home and not stdlib_dir:
711698
v = winreg.QueryValue(key, None)
712699
if isinstance(v, str):
713700
pythonpath.extend(v.split(DELIM))
@@ -722,6 +709,11 @@ def search_up(prefix, *landmarks, test=isfile):
722709
pythonpath.append(joinpath(prefix, p))
723710

724711
# Then add stdlib_dir and platstdlib_dir
712+
if not stdlib_dir and prefix:
713+
stdlib_dir = joinpath(prefix, STDLIB_SUBDIR)
714+
if not platstdlib_dir and exec_prefix:
715+
platstdlib_dir = joinpath(exec_prefix, PLATSTDLIB_LANDMARK)
716+
725717
if os_name == 'nt':
726718
# QUIRK: Windows generates paths differently
727719
if platstdlib_dir:
@@ -792,5 +784,6 @@ def search_up(prefix, *landmarks, test=isfile):
792784
config['base_exec_prefix'] = base_exec_prefix or exec_prefix
793785

794786
config['platlibdir'] = platlibdir
795-
config['stdlib_dir'] = stdlib_dir
796-
config['platstdlib_dir'] = platstdlib_dir
787+
# test_embed expects empty strings, not None
788+
config['stdlib_dir'] = stdlib_dir or ''
789+
config['platstdlib_dir'] = platstdlib_dir or ''

0 commit comments

Comments
 (0)