diff options
author | Victor Stinner <vstinner@python.org> | 2020-11-10 13:21:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 13:21:52 +0100 |
commit | 9e1b828265e6bfb58f1e0299bd78d8ff6347a2ba (patch) | |
tree | 6062eedbc8405d7a9d20caad2080c41ae01cdd00 /Python/initconfig.c | |
parent | 38811d68caf9b782ea7168479acb09557e126efe (diff) | |
download | cpython-9e1b828265e6bfb58f1e0299bd78d8ff6347a2ba.tar.gz cpython-9e1b828265e6bfb58f1e0299bd78d8ff6347a2ba.zip |
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.
Diffstat (limited to 'Python/initconfig.c')
-rw-r--r-- | Python/initconfig.c | 47 |
1 files changed, 18 insertions, 29 deletions
diff --git a/Python/initconfig.c b/Python/initconfig.c index e0811b56cb3..11db4a3ef59 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -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) { |