mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-91985: Ensure in-tree builds override platstdlib_dir in every path calculation (GH-93641)
This commit is contained in:
parent
f8e576be0a
commit
38af903506
4 changed files with 125 additions and 2 deletions
|
@ -1303,6 +1303,66 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
|
|||
self.check_all_configs("test_init_setpythonhome", config,
|
||||
api=API_COMPAT, env=env)
|
||||
|
||||
def test_init_is_python_build_with_home(self):
|
||||
# Test _Py_path_config._is_python_build configuration (gh-91985)
|
||||
config = self._get_expected_config()
|
||||
paths = config['config']['module_search_paths']
|
||||
paths_str = os.path.pathsep.join(paths)
|
||||
|
||||
for path in paths:
|
||||
if not os.path.isdir(path):
|
||||
continue
|
||||
if os.path.exists(os.path.join(path, 'os.py')):
|
||||
home = os.path.dirname(path)
|
||||
break
|
||||
else:
|
||||
self.fail(f"Unable to find home in {paths!r}")
|
||||
|
||||
prefix = exec_prefix = home
|
||||
if MS_WINDOWS:
|
||||
stdlib = os.path.join(home, "Lib")
|
||||
# Because we are specifying 'home', module search paths
|
||||
# are fairly static
|
||||
expected_paths = [paths[0], stdlib, os.path.join(home, 'DLLs')]
|
||||
else:
|
||||
version = f'{sys.version_info.major}.{sys.version_info.minor}'
|
||||
stdlib = os.path.join(home, sys.platlibdir, f'python{version}')
|
||||
expected_paths = self.module_search_paths(prefix=home, exec_prefix=home)
|
||||
|
||||
config = {
|
||||
'home': home,
|
||||
'module_search_paths': expected_paths,
|
||||
'prefix': prefix,
|
||||
'base_prefix': prefix,
|
||||
'exec_prefix': exec_prefix,
|
||||
'base_exec_prefix': exec_prefix,
|
||||
'pythonpath_env': paths_str,
|
||||
'stdlib_dir': stdlib,
|
||||
}
|
||||
# The code above is taken from test_init_setpythonhome()
|
||||
env = {'TESTHOME': home, 'PYTHONPATH': paths_str}
|
||||
|
||||
env['NEGATIVE_ISPYTHONBUILD'] = '1'
|
||||
config['_is_python_build'] = 0
|
||||
self.check_all_configs("test_init_is_python_build", config,
|
||||
api=API_COMPAT, env=env)
|
||||
|
||||
env['NEGATIVE_ISPYTHONBUILD'] = '0'
|
||||
config['_is_python_build'] = 1
|
||||
exedir = os.path.dirname(sys.executable)
|
||||
with open(os.path.join(exedir, 'pybuilddir.txt'), encoding='utf8') as f:
|
||||
expected_paths[2] = os.path.normpath(
|
||||
os.path.join(exedir, f'{f.read()}\n$'.splitlines()[0]))
|
||||
if not MS_WINDOWS:
|
||||
# PREFIX (default) is set when running in build directory
|
||||
prefix = exec_prefix = sys.prefix
|
||||
# stdlib calculation (/Lib) is not yet supported
|
||||
expected_paths[0] = self.module_search_paths(prefix=prefix)[0]
|
||||
config.update(prefix=prefix, base_prefix=prefix,
|
||||
exec_prefix=exec_prefix, base_exec_prefix=exec_prefix)
|
||||
self.check_all_configs("test_init_is_python_build", config,
|
||||
api=API_COMPAT, env=env)
|
||||
|
||||
def copy_paths_by_env(self, config):
|
||||
all_configs = self._get_expected_config()
|
||||
paths = all_configs['config']['module_search_paths']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue