Skip to content

Commit d19d8d5

Browse files
authored
bpo-34170: Add _PyCoreConfig.isolated (GH-8417)
* _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. * Rename _disable_importlib of _PyCoreConfig to _install_importlib * _PyCoreConfig_SetGlobalConfig() now also set Py_HashRandomizationFlag * Replace !Py_NoSiteFlag with core_config->site_import
1 parent ac0b3c2 commit d19d8d5

File tree

7 files changed

+412
-354
lines changed

7 files changed

+412
-354
lines changed

Include/internal/pystate.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ typedef struct _PyPathConfig {
5252
wchar_t *program_name;
5353
/* Set by Py_SetPythonHome() or PYTHONHOME environment variable */
5454
wchar_t *home;
55-
/* isolated and no_site_import are used to set Py_IsolatedFlag and
55+
/* isolated and site_import are used to set Py_IsolatedFlag and
5656
Py_NoSiteFlag flags on Windows in read_pth_file(). These fields
5757
are ignored when their value are equal to -1 (unset). */
5858
int isolated;
59-
int no_site_import;
59+
int site_import;
6060
} _PyPathConfig;
6161

6262
#define _PyPathConfig_INIT \
6363
{.module_search_path = NULL, \
6464
.isolated = -1, \
65-
.no_site_import = -1}
65+
.site_import = -1}
6666
/* Note: _PyPathConfig_INIT sets other fields to 0/NULL */
6767

6868
PyAPI_DATA(_PyPathConfig) _Py_path_config;

Include/pylifecycle.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,16 @@ PyAPI_FUNC(int) Py_SetStandardStreamEncoding(const char *encoding,
5454
PyAPI_FUNC(_PyInitError) _Py_InitializeCore(const _PyCoreConfig *);
5555
PyAPI_FUNC(int) _Py_IsCoreInitialized(void);
5656

57-
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(
58-
_PyCoreConfig *config,
59-
int *isolated,
60-
int *no_site_import);
57+
PyAPI_FUNC(_PyInitError) _PyCoreConfig_Read(_PyCoreConfig *config);
6158
PyAPI_FUNC(void) _PyCoreConfig_Clear(_PyCoreConfig *);
6259
PyAPI_FUNC(int) _PyCoreConfig_Copy(
6360
_PyCoreConfig *config,
6461
const _PyCoreConfig *config2);
65-
PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig(
66-
_PyCoreConfig *config,
67-
int *isolated,
68-
int *no_site_import);
62+
PyAPI_FUNC(_PyInitError) _PyCoreConfig_InitPathConfig(_PyCoreConfig *config);
6963
PyAPI_FUNC(_PyInitError) _PyCoreConfig_SetPathConfig(
7064
const _PyCoreConfig *config);
65+
PyAPI_FUNC(void) _PyCoreConfig_SetGlobalConfig(const _PyCoreConfig *config);
66+
7167

7268
PyAPI_FUNC(_PyInitError) _PyMainInterpreterConfig_Read(
7369
_PyMainInterpreterConfig *config,

Include/pystate.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);
2828
typedef struct {
2929
int install_signal_handlers; /* Install signal handlers? -1 means unset */
3030

31-
int ignore_environment; /* -E, Py_IgnoreEnvironmentFlag */
31+
int ignore_environment; /* -E, Py_IgnoreEnvironmentFlag, -1 means unset */
3232
int use_hash_seed; /* PYTHONHASHSEED=x */
3333
unsigned long hash_seed;
3434
const char *allocator; /* Memory allocator: _PyMem_SetupAllocators() */
@@ -75,18 +75,42 @@ typedef struct {
7575
wchar_t *dll_path; /* Windows DLL path */
7676
#endif
7777

78-
/* Private fields */
79-
int _disable_importlib; /* Needed by freeze_importlib */
78+
/* If greater than 0, enable isolated mode: sys.path contains
79+
neither the script's directory nor the user's site-packages directory.
80+
81+
Set to 1 by the -I command line option. If set to -1 (default), inherit
82+
Py_IsolatedFlag value. */
83+
int isolated;
84+
85+
/* If equal to zero, disable the import of the module site and the
86+
site-dependent manipulations of sys.path that it entails. Also disable
87+
these manipulations if site is explicitly imported later (call
88+
site.main() if you want them to be triggered).
89+
90+
Set to 0 by the -S command line option. If set to -1 (default), set to
91+
the negative value of Py_NoSiteFlag. */
92+
int site_import;
93+
94+
/* --- Private fields -------- */
95+
96+
/* Install importlib? If set to 0, importlib is not initialized at all.
97+
Needed by freeze_importlib: see install_importlib argument of
98+
_Py_InitializeEx_Private(). */
99+
int _install_importlib;
80100
} _PyCoreConfig;
81101

82102
#define _PyCoreConfig_INIT \
83103
(_PyCoreConfig){ \
84104
.install_signal_handlers = -1, \
105+
.ignore_environment = -1, \
85106
.use_hash_seed = -1, \
86107
.coerce_c_locale = -1, \
87108
.utf8_mode = -1, \
88109
.argc = -1, \
89-
.nmodule_search_path = -1}
110+
.nmodule_search_path = -1, \
111+
.isolated = -1, \
112+
.site_import = -1, \
113+
._install_importlib = 1}
90114
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
91115

92116
/* Placeholders while working on the new configuration API

0 commit comments

Comments
 (0)