Repository navigation
Py_Initialize(): computing path configuration must not have side effect (PEP 432) #78351
Description
Activity
- added3.8 (EOL)end of lifeend of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Jul 20, 2018 Attached PR reworks _PyCoreConfig_Read() to leave _Py_path_config unchanged: *reading* the core configuration must not *modify* the path configuration.
The PR adds _PyCoreConfig.dll_path field.
The change is related to the PEP-432.
See also bpo-34008: "Do we support calling Py_Main() after Py_Initialize()?".
PR 8353 is the last piece of my long work on Py_Main() to separate code *reading* configuration and code *applying* a new configuration. My work on the new _PyPathConfig structure, and the PR should finish that work.
Extract of the commit message:
"A new _PyCoreConfig_SetPathConfig() function now recreates the path configuration from the core configuration. This function is now called very late in _Py_InitializeCore(), just before calling initimport()."
Reminder for myself: I have to write unit tests :-)
#8417 (review)I added many fields to _PyCoreConfig which duplicate global configuration varibles: _PyConfigCore.isolated duplicates Py_IsolatedFlag.
I started to modify Python to read the core configuration rather than global configuration flags. The problem is that sometimes, global configuration flags are updated, but not their duplicated core configuration fields.
Example from Modules/main.c:
static void pymain_repl(_PyMain *pymain, _PyCoreConfig *config, PyCompilerFlags *cf) { /* Check this environment variable at the end, to give programs the opportunity to set it from Python. */ if (!Py_InspectFlag && config_get_env_var(config, "PYTHONINSPECT")) { Py_InspectFlag = 1; } ... }
Only Py_InspectFlag is not, not core_config.inspect.
TODO list, open questions:
- Should isolated=1 always imply config->ignore_environment=1 and config->user_site_directory = 0?
- Should we rename debug to parser_debug? "debug" is a very generic term, whereas this flag is really specific to the parser
- Remove _Py_CheckHashBasedPycsMode: replace it with config._check_hash_pycs_mode?
I created bpo-34228 "Allow PYTHONTRACEMALLOC=0 and -X tracemalloc=0 to disable explicitly tracemalloc" that I need to write unit tests on Python initiallization.
1 remaining item
New changeset 6c785c0 by Victor Stinner in branch 'master':
bpo-34170: Add Python/coreconfig.c for _PyCoreConfig (GH-8607)
6c785c0"""
TODO list, open questions:- Should isolated=1 always imply config->ignore_environment=1 and config->user_site_directory = 0?
- Should we rename debug to parser_debug? "debug" is a very generic term, whereas this flag is really specific to the parser
- Remove _Py_CheckHashBasedPycsMode: replace it with config._check_hash_pycs_mode?
"""
=> DONE!
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: