summaryrefslogtreecommitdiffstats
path: root/PC
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-11-22 23:12:09 (GMT)
committerGitHub <noreply@github.com>2017-11-22 23:12:09 (GMT)
commitd4341109746aa15e1909e63b30b93b6133ffe401 (patch)
tree8982cc677ace3953484d4e4e34c8b154d0b9fb35 /PC
parent82656276caf4cb889193572d2d14dbc5f3d2bdff (diff)
downloadcpython-d4341109746aa15e1909e63b30b93b6133ffe401.zip
cpython-d4341109746aa15e1909e63b30b93b6133ffe401.tar.gz
cpython-d4341109746aa15e1909e63b30b93b6133ffe401.tar.bz2
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.
Diffstat (limited to 'PC')
-rw-r--r--PC/getpathp.c27
1 files changed, 19 insertions, 8 deletions
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 @@ error:
static void
-calculate_path(void)
+calculate_path(_PyCoreConfig *core_config)
{
wchar_t argv0_path[MAXPATHLEN+1];
wchar_t *buf;
@@ -637,8 +637,13 @@ calculate_path(void)
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 @@ calculate_path(void)
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 @@ Py_SetPath(const wchar_t *path)
}
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 @@ wchar_t *
Py_GetPrefix(void)
{
if (!module_search_path)
- calculate_path();
+ calculate_path(NULL);
return prefix;
}
@@ -922,7 +933,7 @@ wchar_t *
Py_GetProgramFullPath(void)
{
if (!module_search_path)
- calculate_path();
+ calculate_path(NULL);
return progpath;
}