Mailing List Archive

bpo-45582: Ensure PYTHONHOME still overrides detected build prefixes (GH-29948)
https://github.com/python/cpython/commit/b7ef27bc084665ce58d89fc69530c6f9d2d37754
commit: b7ef27bc084665ce58d89fc69530c6f9d2d37754
branch: main
author: Steve Dower <steve.dower@python.org>
committer: zooba <steve.dower@microsoft.com>
date: 2021-12-07T00:07:35Z
summary:

bpo-45582: Ensure PYTHONHOME still overrides detected build prefixes (GH-29948)

files:
M Lib/test/test_getpath.py
M Modules/getpath.py

diff --git a/Lib/test/test_getpath.py b/Lib/test/test_getpath.py
index c18689c0590d4..9dd167b9975c0 100644
--- a/Lib/test/test_getpath.py
+++ b/Lib/test/test_getpath.py
@@ -208,6 +208,36 @@ def test_symlink_buildtree_win32(self):
actual = getpath(ns, expected)
self.assertEqual(expected, actual)

+ def test_buildtree_pythonhome_win32(self):
+ "Test an out-of-build-tree layout on Windows with PYTHONHOME override."
+ ns = MockNTNamespace(
+ argv0=r"C:\Out\python.exe",
+ real_executable=r"C:\Out\python.exe",
+ ENV_PYTHONHOME=r"C:\CPython",
+ )
+ ns.add_known_xfile(r"C:\Out\python.exe")
+ ns.add_known_file(r"C:\CPython\Lib\os.py")
+ ns.add_known_file(r"C:\Out\pybuilddir.txt", [""])
+ expected = dict(
+ executable=r"C:\Out\python.exe",
+ base_executable=r"C:\Out\python.exe",
+ prefix=r"C:\CPython",
+ exec_prefix=r"C:\CPython",
+ # This build_prefix is a miscalculation, because we have
+ # moved the output direction out of the prefix.
+ # Specify PYTHONHOME to get the correct prefix/exec_prefix
+ build_prefix="C:\\",
+ _is_python_build=1,
+ module_search_paths_set=1,
+ module_search_paths=[
+ r"C:\Out\python98.zip",
+ r"C:\CPython\Lib",
+ r"C:\Out",
+ ],
+ )
+ actual = getpath(ns, expected)
+ self.assertEqual(expected, actual)
+
def test_normal_posix(self):
"Test a 'standard' install layout on *nix"
ns = MockPosixNamespace(
diff --git a/Modules/getpath.py b/Modules/getpath.py
index 2eadfba1dfda2..4ef49a8847dd2 100644
--- a/Modules/getpath.py
+++ b/Modules/getpath.py
@@ -500,6 +500,8 @@ def search_up(prefix, *landmarks, test=isfile):
prefix, had_delim, exec_prefix = home.partition(DELIM)
if not had_delim:
exec_prefix = prefix
+ # Reset the standard library directory if it was already set
+ stdlib_dir = None


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

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins