bpo-32030: Add _PyCoreConfig.module_search_path_env (#4504)
Changes:
* Py_Main() initializes _PyCoreConfig.module_search_path_env from
the PYTHONPATH environment variable.
* PyInterpreterState_New() now initializes core_config and config
fields
* Compute sys.path a little bit ealier in
_Py_InitializeMainInterpreter() and new_interpreter()
* Add _Py_GetPathWithConfig() private function.
diff --git a/PC/getpathp.c b/PC/getpathp.c
index 9bbc7bf..b182ae6 100644
--- a/PC/getpathp.c
+++ b/PC/getpathp.c
@@ -624,7 +624,7 @@
static void
-calculate_path(void)
+calculate_path(_PyCoreConfig *core_config)
{
wchar_t argv0_path[MAXPATHLEN+1];
wchar_t *buf;
@@ -637,8 +637,13 @@
wchar_t *userpath = NULL;
wchar_t zip_path[MAXPATHLEN+1];
- if (!Py_IgnoreEnvironmentFlag) {
+ if (core_config) {
+ envpath = core_config->module_search_path_env;
+ }
+ else if (!Py_IgnoreEnvironmentFlag) {
envpath = _wgetenv(L"PYTHONPATH");
+ if (envpath && *envpath == '\0')
+ envpath = NULL;
}
get_progpath();
@@ -709,9 +714,6 @@
else
wcscpy_s(prefix, MAXPATHLEN+1, pythonhome);
- if (envpath && *envpath == '\0')
- envpath = NULL;
-
skiphome = pythonhome==NULL ? 0 : 1;
#ifdef Py_ENABLE_SHARED
@@ -897,10 +899,19 @@
}
wchar_t *
+_Py_GetPathWithConfig(_PyCoreConfig *core_config)
+{
+ if (!module_search_path) {
+ calculate_path(core_config);
+ }
+ return module_search_path;
+}
+
+wchar_t *
Py_GetPath(void)
{
if (!module_search_path)
- calculate_path();
+ calculate_path(NULL);
return module_search_path;
}
@@ -908,7 +919,7 @@
Py_GetPrefix(void)
{
if (!module_search_path)
- calculate_path();
+ calculate_path(NULL);
return prefix;
}
@@ -922,7 +933,7 @@
Py_GetProgramFullPath(void)
{
if (!module_search_path)
- calculate_path();
+ calculate_path(NULL);
return progpath;
}