bpo-34170: Add _PyCoreConfig.isolated#8417
Conversation
* _PyCoreConfig: add isolated and site_import attributes * Replace Py_IgnoreEnvironment with config->ignore_environment when reading the current configuration * _PyCoreConfig_Read() now sets ignore_environment, utf8_mode, isolated and site_import from Py_IgnoreEnvironment, Py_UTF8Mode, Py_IsolatedFlag and Py_NoSiteFlag * _Py_InitializeCore() now sets Py_xxx flags from the configuration * pymain_read_conf() now uses _PyCoreConfig_Copy() to save/restore the configuration.
|
@ncoghlan, @ericsnowcurrently, @emilyemorehouse: OK, this PR should be big enhancement for the PEP 432 :-) Previously, _PyCoreConfig "tried" to be isolated from Py_xxx global configuration variables like Py_IsolatedFlag. In practice, it already contained ignore_environment and utf8_mode which duplicated Py_IgnoreEnvironment and Py_UTF8Mode global configuration which can lead to inconsistency. With this change, the priority becomes more explicit: _PyCoreConfig has now the priority over Py_xxx. To get a smooth transition, _PyCoreConfig are initialized to -1 which means "unset": in that case, the fields are initialized from Py_xxx. Core config has the priority: Backward compatibility: This change simplify and clarify main.c:
|
Sorry, something went wrong.
|
This PR also removes the ugly hack added by the commit f2626ce: two It was a temporary hack until I make this more brave change. |
Sorry, something went wrong.
* Rename _disable_importlib of _PyCoreConfig to _install_importlib * _PyCoreConfig_SetGlobalConfig() now also set Py_HashRandomizationFlag * Replace !Py_NoSiteFlag with core_config->site_import
ncoghlan
left a comment
There was a problem hiding this comment.
The changes themselves look good to me (with one minor fix to a comment), but it would be good to add a test case that ensures the settings in the config struct override the preconfigured ones in the environment (or not, as the case may be).
My suggestion would be to have a test embed helper command that runs 3 cases:
- global variables set to 1, core config fields set to -1 -> sys.flags reports 1
- global variables set to 1, core config fields set to 0 -> sys.flags reports 0
- global variables set to 0, core config fields set to 1 -> sys.flags reports 1
The embedding helper would just run import sys; print(sys.flags); sys.stdout.flush(), and then the Python test case would handle checking the output flags matched what the test excepted for each case.
Sorry, something went wrong.
|
Write more tests is a good idea! But this change is already big enough, I will write them in my following change. I plan to move all "cmdline" fields into the core config. |
Sorry, something went wrong.
reading the current configuration
isolated and site_import from Py_IgnoreEnvironment, Py_UTF8Mode,
Py_IsolatedFlag and Py_NoSiteFlag
the configuration.
https://bugs.python.org/issue34170