GH-126985: Don't override venv detection with PYTHONHOME (#127968)

This commit is contained in:
Filipe Laíns 🇵🇸 2024-12-15 21:12:13 +00:00 committed by GitHub
parent 46006a1b35
commit b74c8f58e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 3 deletions

View file

@ -832,6 +832,37 @@ def test_explicitly_set_stdlib_dir(self):
actual = getpath(ns, expected)
self.assertEqual(expected, actual)
def test_PYTHONHOME_in_venv(self):
"Make sure prefix/exec_prefix still point to the venv if PYTHONHOME was used."
ns = MockPosixNamespace(
argv0="/venv/bin/python",
PREFIX="/usr",
ENV_PYTHONHOME="/pythonhome",
)
# Setup venv
ns.add_known_xfile("/venv/bin/python")
ns.add_known_file("/venv/pyvenv.cfg", [
r"home = /usr/bin"
])
# Seutup PYTHONHOME
ns.add_known_file("/pythonhome/lib/python9.8/os.py")
ns.add_known_dir("/pythonhome/lib/python9.8/lib-dynload")
expected = dict(
executable="/venv/bin/python",
prefix="/venv",
exec_prefix="/venv",
base_prefix="/pythonhome",
base_exec_prefix="/pythonhome",
module_search_paths_set=1,
module_search_paths=[
"/pythonhome/lib/python98.zip",
"/pythonhome/lib/python9.8",
"/pythonhome/lib/python9.8/lib-dynload",
],
)
actual = getpath(ns, expected)
self.assertEqual(expected, actual)
# ******************************************************************************