mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-106718: Treat PyConfig.stdlib_dir as highest-priority setting for stdlib_dir when calculating paths (GH-108730)
This commit is contained in:
parent
821a7ac493
commit
834b7c18d7
3 changed files with 30 additions and 10 deletions
|
@ -818,6 +818,20 @@ class MockGetPathTests(unittest.TestCase):
|
||||||
actual = getpath(ns, expected)
|
actual = getpath(ns, expected)
|
||||||
self.assertEqual(expected, actual)
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
def test_explicitly_set_stdlib_dir(self):
|
||||||
|
"""Test the explicitly set stdlib_dir in the config is respected."""
|
||||||
|
ns = MockPosixNamespace(
|
||||||
|
PREFIX="/usr",
|
||||||
|
argv0="python",
|
||||||
|
ENV_PATH="/usr/bin",
|
||||||
|
)
|
||||||
|
ns["config"]["stdlib_dir"] = "/custom_stdlib_dir"
|
||||||
|
expected = dict(
|
||||||
|
stdlib_dir="/custom_stdlib_dir",
|
||||||
|
)
|
||||||
|
actual = getpath(ns, expected)
|
||||||
|
self.assertEqual(expected, actual)
|
||||||
|
|
||||||
|
|
||||||
# ******************************************************************************
|
# ******************************************************************************
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
When PyConfig.stdlib_dir is explicitly set, it's now respected and won't be
|
||||||
|
overridden by PyConfig.home.
|
|
@ -229,9 +229,10 @@ use_environment = config.get('use_environment', 1)
|
||||||
|
|
||||||
pythonpath = config.get('module_search_paths')
|
pythonpath = config.get('module_search_paths')
|
||||||
pythonpath_was_set = config.get('module_search_paths_set')
|
pythonpath_was_set = config.get('module_search_paths_set')
|
||||||
|
stdlib_dir = config.get('stdlib_dir')
|
||||||
|
stdlib_dir_was_set_in_config = bool(stdlib_dir)
|
||||||
|
|
||||||
real_executable_dir = None
|
real_executable_dir = None
|
||||||
stdlib_dir = None
|
|
||||||
platstdlib_dir = None
|
platstdlib_dir = None
|
||||||
|
|
||||||
# ******************************************************************************
|
# ******************************************************************************
|
||||||
|
@ -507,11 +508,12 @@ if ((not home_was_set and real_executable_dir and not py_setpath)
|
||||||
build_stdlib_prefix = build_prefix
|
build_stdlib_prefix = build_prefix
|
||||||
else:
|
else:
|
||||||
build_stdlib_prefix = search_up(build_prefix, *BUILDSTDLIB_LANDMARKS)
|
build_stdlib_prefix = search_up(build_prefix, *BUILDSTDLIB_LANDMARKS)
|
||||||
# Always use the build prefix for stdlib
|
# Use the build prefix for stdlib when not explicitly set
|
||||||
if build_stdlib_prefix:
|
if not stdlib_dir_was_set_in_config:
|
||||||
stdlib_dir = joinpath(build_stdlib_prefix, 'Lib')
|
if build_stdlib_prefix:
|
||||||
else:
|
stdlib_dir = joinpath(build_stdlib_prefix, 'Lib')
|
||||||
stdlib_dir = joinpath(build_prefix, 'Lib')
|
else:
|
||||||
|
stdlib_dir = joinpath(build_prefix, 'Lib')
|
||||||
# Only use the build prefix for prefix if it hasn't already been set
|
# Only use the build prefix for prefix if it hasn't already been set
|
||||||
if not prefix:
|
if not prefix:
|
||||||
prefix = build_stdlib_prefix
|
prefix = build_stdlib_prefix
|
||||||
|
@ -543,8 +545,9 @@ else:
|
||||||
prefix, had_delim, exec_prefix = home.partition(DELIM)
|
prefix, had_delim, exec_prefix = home.partition(DELIM)
|
||||||
if not had_delim:
|
if not had_delim:
|
||||||
exec_prefix = prefix
|
exec_prefix = prefix
|
||||||
# Reset the standard library directory if it was already set
|
# Reset the standard library directory if it was not explicitly set
|
||||||
stdlib_dir = None
|
if not stdlib_dir_was_set_in_config:
|
||||||
|
stdlib_dir = None
|
||||||
|
|
||||||
|
|
||||||
# First try to detect prefix by looking alongside our runtime library, if known
|
# First try to detect prefix by looking alongside our runtime library, if known
|
||||||
|
@ -560,7 +563,8 @@ else:
|
||||||
if STDLIB_SUBDIR and STDLIB_LANDMARKS and not prefix:
|
if STDLIB_SUBDIR and STDLIB_LANDMARKS and not prefix:
|
||||||
if any(isfile(joinpath(library_dir, f)) for f in STDLIB_LANDMARKS):
|
if any(isfile(joinpath(library_dir, f)) for f in STDLIB_LANDMARKS):
|
||||||
prefix = library_dir
|
prefix = library_dir
|
||||||
stdlib_dir = joinpath(prefix, STDLIB_SUBDIR)
|
if not stdlib_dir_was_set_in_config:
|
||||||
|
stdlib_dir = joinpath(prefix, STDLIB_SUBDIR)
|
||||||
|
|
||||||
|
|
||||||
# Detect prefix by looking for zip file
|
# Detect prefix by looking for zip file
|
||||||
|
@ -571,7 +575,7 @@ else:
|
||||||
prefix = executable_dir
|
prefix = executable_dir
|
||||||
else:
|
else:
|
||||||
prefix = search_up(executable_dir, ZIP_LANDMARK)
|
prefix = search_up(executable_dir, ZIP_LANDMARK)
|
||||||
if prefix:
|
if prefix and not stdlib_dir_was_set_in_config:
|
||||||
stdlib_dir = joinpath(prefix, STDLIB_SUBDIR)
|
stdlib_dir = joinpath(prefix, STDLIB_SUBDIR)
|
||||||
if not isdir(stdlib_dir):
|
if not isdir(stdlib_dir):
|
||||||
stdlib_dir = None
|
stdlib_dir = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue