Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-91985: Ensure in-tree builds override platstdlib_dir in every path calculation#93641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
zooba merged 19 commits intopython:mainfromneonene:intree
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
1ae7f87
gh-91985: Ensure in-tree builds override platstdlib_dir in every path…
neoneneJun 9, 2022
0be59f2
test, etc.
neoneneJun 11, 2022
19fb85d
less redundant test
neoneneJun 11, 2022
f336113
Fix test (place a landmark)
neoneneJun 11, 2022
0e75c9c
assert()
neoneneJun 12, 2022
0df156b
add case
neoneneJun 12, 2022
b085759
add platstdlib_dir
neoneneJun 12, 2022
bc861bf
reword
neoneneJun 13, 2022
5cb5e2b
remove test
neoneneJun 13, 2022
3051b55
new test case in test_embed
neoneneJun 13, 2022
4f08be9
reword
neoneneJun 13, 2022
6bb3323
rerun test
neoneneJun 13, 2022
19e1428
apply suggested changes
neoneneJun 14, 2022
1919590
move stdlib upper
neoneneJun 14, 2022
8b15917
comment, etc.
neoneneJun 15, 2022
bf5bc28
less lines
neoneneJun 15, 2022
39c851c
putenv()
neoneneJun 15, 2022
500cb81
move comment upper
neoneneJun 15, 2022
7636f73
a comment
neoneneJun 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletionsLib/test/test_embed.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1303,6 +1303,66 @@ def test_init_setpythonhome(self):
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']
Expand Down
3 changes: 2 additions & 1 deletionModules/getpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -461,7 +461,8 @@ def search_up(prefix, *landmarks, test=isfile):

build_prefix = None

if not home_was_set and real_executable_dir and not py_setpath:
if ((not home_was_set and real_executable_dir and not py_setpath)
or config.get('_is_python_build', 0) > 0):
# Detect a build marker and use it to infer prefix, exec_prefix,
# stdlib_dir and the platstdlib_dir directories.
try:
Expand Down
41 changes: 41 additions & 0 deletionsPrograms/_testembed.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1550,6 +1550,46 @@ static int test_init_setpythonhome(void)
}


static int test_init_is_python_build(void)
{
// gh-91985: in-tree builds fail to check for build directory landmarks
// under the effect of 'home' or PYTHONHOME environment variable.
char *env = getenv("TESTHOME");
if (!env) {
error("missing TESTHOME env var");
return 1;
}
wchar_t *home = Py_DecodeLocale(env, NULL);
if (home == NULL) {
error("failed to decode TESTHOME");
return 1;
}

PyConfig config;
_PyConfig_InitCompatConfig(&config);
config_set_program_name(&config);
config_set_string(&config, &config.home, home);
PyMem_RawFree(home);
putenv("TESTHOME=");

// Use an impossible value so we can detect whether it isn't updated
// during initialization.
config._is_python_build = INT_MAX;
env = getenv("NEGATIVE_ISPYTHONBUILD");
if (env && strcmp(env, "0") != 0) {
config._is_python_build++;
}
init_from_config_clear(&config);
Py_Finalize();
// Second initialization
config._is_python_build = -1;
init_from_config_clear(&config);
dump_config(); // home and _is_python_build are cached in _Py_path_config
Py_Finalize();
return 0;
}


static int test_init_warnoptions(void)
{
putenv("PYTHONWARNINGS=ignore:::env1,ignore:::env2");
Expand DownExpand Up@@ -1965,6 +2005,7 @@ static struct TestCase TestCases[] = {
{"test_init_setpath", test_init_setpath},
{"test_init_setpath_config", test_init_setpath_config},
{"test_init_setpythonhome", test_init_setpythonhome},
{"test_init_is_python_build", test_init_is_python_build},
{"test_init_warnoptions", test_init_warnoptions},
{"test_init_set_config", test_init_set_config},
{"test_run_main", test_run_main},
Expand Down
23 changes: 22 additions & 1 deletionPython/pathconfig.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,10 +36,11 @@ typedef struct _PyPathConfig {
wchar_t *program_name;
/* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
wchar_t *home;
int _is_python_build;
} _PyPathConfig;

# define _PyPathConfig_INIT \
{.module_search_path = NULL}
{.module_search_path = NULL, ._is_python_build = 0}


_PyPathConfig _Py_path_config = _PyPathConfig_INIT;
Expand DownExpand Up@@ -72,6 +73,7 @@ _PyPathConfig_ClearGlobal(void)
CLEAR(calculated_module_search_path);
CLEAR(program_name);
CLEAR(home);
_Py_path_config._is_python_build = 0;

#undef CLEAR

Expand DownExpand Up@@ -99,15 +101,25 @@ _PyPathConfig_ReadGlobal(PyConfig *config)
} \
} while (0)

#define COPY_INT(ATTR) \
do { \
assert(_Py_path_config.ATTR >= 0); \
if ((_Py_path_config.ATTR >= 0) && (config->ATTR <= 0)) { \
config->ATTR = _Py_path_config.ATTR; \
} \
} while (0)

COPY(prefix);
COPY(exec_prefix);
COPY(stdlib_dir);
COPY(program_name);
COPY(home);
COPY2(executable, program_full_path);
COPY_INT(_is_python_build);
// module_search_path must be initialised - not read
#undef COPY
#undef COPY2
#undef COPY_INT

done:
return status;
Expand DownExpand Up@@ -137,14 +149,23 @@ _PyPathConfig_UpdateGlobal(const PyConfig *config)
} \
} while (0)

#define COPY_INT(ATTR) \
do { \
if (config->ATTR > 0) { \
_Py_path_config.ATTR = config->ATTR; \
} \
} while (0)

COPY(prefix);
COPY(exec_prefix);
COPY(stdlib_dir);
COPY(program_name);
COPY(home);
COPY2(program_full_path, executable);
COPY_INT(_is_python_build);
#undef COPY
#undef COPY2
#undef COPY_INT

PyMem_RawFree(_Py_path_config.module_search_path);
_Py_path_config.module_search_path = NULL;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp