Skip to content

Commit 8ded5b8

Browse files
authored
bpo-32030: Add _PyCoreConfig.module_search_paths (#4954)
_PyCoreConfig_Read() is now responsible to compute sys.path. So sys.path is now computed before calling _Py_InitializeCore(). Changes: * Add module_search_path, module_search_paths, executable, prefix, base_prefix, exec_prefix and base_exec_prefix to _PyCoreConfig. * _PyMainInterpreterConfig_Read() now only converts wchar_t** lists into a Python list, it doesn't compute sys.path anymore.
1 parent 5de15f1 commit 8ded5b8

File tree

3 files changed

+231
-187
lines changed

3 files changed

+231
-187
lines changed

Include/pystate.h

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,24 @@ typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int);
2626

2727
typedef struct {
2828
int install_signal_handlers; /* Install signal handlers? -1 means unset */
29-
int ignore_environment; /* -E */
29+
30+
int ignore_environment; /* -E, Py_IgnoreEnvironmentFlag */
3031
int use_hash_seed; /* PYTHONHASHSEED=x */
3132
unsigned long hash_seed;
32-
int _disable_importlib; /* Needed by freeze_importlib */
3333
const char *allocator; /* Memory allocator: _PyMem_SetupAllocators() */
34-
int dev_mode; /* -X dev */
35-
int faulthandler; /* -X faulthandler */
36-
int tracemalloc; /* -X tracemalloc=N */
37-
int import_time; /* -X importtime */
34+
int dev_mode; /* PYTHONDEVMODE, -X dev */
35+
int faulthandler; /* PYTHONFAULTHANDLER, -X faulthandler */
36+
int tracemalloc; /* PYTHONTRACEMALLOC, -X tracemalloc=N */
37+
int import_time; /* PYTHONPROFILEIMPORTTIME, -X importtime */
3838
int show_ref_count; /* -X showrefcount */
3939
int show_alloc_count; /* -X showalloccount */
4040
int dump_refs; /* PYTHONDUMPREFS */
4141
int malloc_stats; /* PYTHONMALLOCSTATS */
4242
int coerce_c_locale; /* PYTHONCOERCECLOCALE, -1 means unknown */
4343
int coerce_c_locale_warn; /* PYTHONCOERCECLOCALE=warn */
44-
int utf8_mode; /* -X utf8 or PYTHONUTF8 environment variable,
45-
-1 means unknown */
44+
int utf8_mode; /* PYTHONUTF8, -X utf8; -1 means unknown */
4645

47-
wchar_t *module_search_path_env; /* PYTHONPATH environment variable */
48-
wchar_t *home; /* PYTHONHOME environment variable,
49-
see also Py_SetPythonHome(). */
5046
wchar_t *program_name; /* Program name, see also Py_GetProgramName() */
51-
5247
int argc; /* Number of command line arguments,
5348
-1 means unset */
5449
wchar_t **argv; /* Command line arguments */
@@ -59,6 +54,24 @@ typedef struct {
5954

6055
int nwarnoption; /* Number of warnings options */
6156
wchar_t **warnoptions; /* Warnings options */
57+
58+
/* Path configuration inputs */
59+
wchar_t *module_search_path_env; /* PYTHONPATH environment variable */
60+
wchar_t *home; /* PYTHONHOME environment variable,
61+
see also Py_SetPythonHome(). */
62+
63+
/* Path configuration outputs */
64+
int nmodule_search_path; /* Number of sys.path paths,
65+
-1 means unset */
66+
wchar_t **module_search_paths; /* sys.path paths */
67+
wchar_t *executable; /* sys.executable */
68+
wchar_t *prefix; /* sys.prefix */
69+
wchar_t *base_prefix; /* sys.base_prefix */
70+
wchar_t *exec_prefix; /* sys.exec_prefix */
71+
wchar_t *base_exec_prefix; /* sys.base_exec_prefix */
72+
73+
/* Private fields */
74+
int _disable_importlib; /* Needed by freeze_importlib */
6275
} _PyCoreConfig;
6376

6477
#define _PyCoreConfig_INIT \
@@ -67,7 +80,8 @@ typedef struct {
6780
.use_hash_seed = -1, \
6881
.coerce_c_locale = -1, \
6982
.utf8_mode = -1, \
70-
.argc = -1}
83+
.argc = -1, \
84+
.nmodule_search_path = -1}
7185
/* Note: _PyCoreConfig_INIT sets other fields to 0/NULL */
7286

7387
/* Placeholders while working on the new configuration API

0 commit comments

Comments
 (0)