bpo-42260: Compute the path config in the main init (GH-23211)

The path configuration is now computed in the "main" initialization.
The core initialization no longer computes it.

* Add _PyConfig_Read() function to read the configuration without
  computing the path configuration.
* pyinit_core() no longer computes the path configuration: it is now
  computed by init_interp_main().
* The path configuration output members of PyConfig are now optional:

  * executable
  * base_executable
  * prefix
  * base_prefix
  * exec_prefix
  * base_exec_prefix

* _PySys_UpdateConfig() now skips NULL strings in PyConfig.
* _testembed: Rename test_set_config() to test_init_set_config() for
  consistency with other tests.
This commit is contained in:
Victor Stinner 2020-11-10 13:21:52 +01:00 committed by GitHub
parent 38811d68ca
commit 9e1b828265
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 85 additions and 74 deletions

View file

@ -619,15 +619,6 @@ config_check_consistency(const PyConfig *config)
assert(_PyWideStringList_CheckConsistency(&config->warnoptions));
assert(_PyWideStringList_CheckConsistency(&config->module_search_paths));
assert(config->module_search_paths_set >= 0);
if (config->_install_importlib) {
/* don't check config->module_search_paths */
assert(config->executable != NULL);
assert(config->base_executable != NULL);
assert(config->prefix != NULL);
assert(config->base_prefix != NULL);
assert(config->exec_prefix != NULL);
assert(config->base_exec_prefix != NULL);
}
assert(config->platlibdir != NULL);
assert(config->filesystem_encoding != NULL);
assert(config->filesystem_errors != NULL);
@ -1297,24 +1288,15 @@ _PyConfig_FromDict(PyConfig *config, PyObject *dict)
GET_WSTR_OPT(home);
GET_WSTR(platlibdir);
// Path configuration output
GET_UINT(module_search_paths_set);
GET_WSTRLIST(module_search_paths);
if (config->_install_importlib) {
GET_WSTR(executable);
GET_WSTR(base_executable);
GET_WSTR(prefix);
GET_WSTR(base_prefix);
GET_WSTR(exec_prefix);
GET_WSTR(base_exec_prefix);
}
else {
GET_WSTR_OPT(executable);
GET_WSTR_OPT(base_executable);
GET_WSTR_OPT(prefix);
GET_WSTR_OPT(base_prefix);
GET_WSTR_OPT(exec_prefix);
GET_WSTR_OPT(base_exec_prefix);
}
GET_WSTR_OPT(executable);
GET_WSTR_OPT(base_executable);
GET_WSTR_OPT(prefix);
GET_WSTR_OPT(base_prefix);
GET_WSTR_OPT(exec_prefix);
GET_WSTR_OPT(base_exec_prefix);
GET_UINT(skip_source_first_line);
GET_WSTR_OPT(run_command);
@ -2043,7 +2025,7 @@ config_init_fs_encoding(PyConfig *config, const PyPreConfig *preconfig)
static PyStatus
config_read(PyConfig *config)
config_read(PyConfig *config, int compute_path_config)
{
PyStatus status;
const PyPreConfig *preconfig = &_PyRuntime.preconfig;
@ -2087,7 +2069,7 @@ config_read(PyConfig *config)
}
}
if (config->_install_importlib) {
if (compute_path_config && config->_install_importlib) {
status = _PyConfig_InitPathConfig(config);
if (_PyStatus_EXCEPTION(status)) {
return status;
@ -2834,7 +2816,7 @@ PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list,
The only side effects are to modify config and to call _Py_SetArgcArgv(). */
PyStatus
PyConfig_Read(PyConfig *config)
_PyConfig_Read(PyConfig *config, int compute_path_config)
{
PyStatus status;
@ -2877,7 +2859,7 @@ PyConfig_Read(PyConfig *config)
goto done;
}
status = config_read(config);
status = config_read(config, compute_path_config);
if (_PyStatus_EXCEPTION(status)) {
goto done;
}
@ -2892,6 +2874,13 @@ done:
}
PyStatus
PyConfig_Read(PyConfig *config)
{
return _PyConfig_Read(config, 1);
}
PyObject*
_Py_GetConfigsAsDict(void)
{