Skip to content

Commit b7ef27b

Browse files
authored
bpo-45582: Ensure PYTHONHOME still overrides detected build prefixes (GH-29948)
1 parent 265918b commit b7ef27b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

Lib/test/test_getpath.py

+30
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,36 @@ def test_symlink_buildtree_win32(self):
208208
actual = getpath(ns, expected)
209209
self.assertEqual(expected, actual)
210210

211+
def test_buildtree_pythonhome_win32(self):
212+
"Test an out-of-build-tree layout on Windows with PYTHONHOME override."
213+
ns = MockNTNamespace(
214+
argv0=r"C:\Out\python.exe",
215+
real_executable=r"C:\Out\python.exe",
216+
ENV_PYTHONHOME=r"C:\CPython",
217+
)
218+
ns.add_known_xfile(r"C:\Out\python.exe")
219+
ns.add_known_file(r"C:\CPython\Lib\os.py")
220+
ns.add_known_file(r"C:\Out\pybuilddir.txt", [""])
221+
expected = dict(
222+
executable=r"C:\Out\python.exe",
223+
base_executable=r"C:\Out\python.exe",
224+
prefix=r"C:\CPython",
225+
exec_prefix=r"C:\CPython",
226+
# This build_prefix is a miscalculation, because we have
227+
# moved the output direction out of the prefix.
228+
# Specify PYTHONHOME to get the correct prefix/exec_prefix
229+
build_prefix="C:\\",
230+
_is_python_build=1,
231+
module_search_paths_set=1,
232+
module_search_paths=[
233+
r"C:\Out\python98.zip",
234+
r"C:\CPython\Lib",
235+
r"C:\Out",
236+
],
237+
)
238+
actual = getpath(ns, expected)
239+
self.assertEqual(expected, actual)
240+
211241
def test_normal_posix(self):
212242
"Test a 'standard' install layout on *nix"
213243
ns = MockPosixNamespace(

Modules/getpath.py

+2
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,8 @@ def search_up(prefix, *landmarks, test=isfile):
500500
prefix, had_delim, exec_prefix = home.partition(DELIM)
501501
if not had_delim:
502502
exec_prefix = prefix
503+
# Reset the standard library directory if it was already set
504+
stdlib_dir = None
503505

504506

505507
# First try to detect prefix by looking alongside our runtime library, if known

0 commit comments

Comments
 (0)