summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2019-06-28 17:02:13 (GMT)
committerGitHub <noreply@github.com>2019-06-28 17:02:13 (GMT)
commitdb4d7ddb012ef8f087a8eb2a5b8a672d04a48e1a (patch)
tree81c2a632a9fdf0a6498dccd42b1fd8771f996648 /Python/sysmodule.c
parent99f2f851773c6e481e80e8e157d9f5ad4fc5cbb3 (diff)
downloadcpython-db4d7ddb012ef8f087a8eb2a5b8a672d04a48e1a.zip
cpython-db4d7ddb012ef8f087a8eb2a5b8a672d04a48e1a.tar.gz
cpython-db4d7ddb012ef8f087a8eb2a5b8a672d04a48e1a.tar.bz2
bpo-37369: Fixes path for sys.executable when running from the Microsoft Store (GH-14450)
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index d87b4e2..942a8b6 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -2448,8 +2448,6 @@ err_occurred:
return _Py_INIT_ERR("can't initialize sys module");
}
-#undef SET_SYS_FROM_STRING
-
/* Updating the sys namespace, returning integer error codes */
#define SET_SYS_FROM_STRING_INT_RESULT(key, value) \
do { \
@@ -2483,6 +2481,17 @@ _PySys_EndInit(PyObject *sysdict, _PyMainInterpreterConfig *config)
SET_SYS_FROM_STRING_BORROW("exec_prefix", config->exec_prefix);
SET_SYS_FROM_STRING_BORROW("base_exec_prefix", config->base_exec_prefix);
+#ifdef MS_WINDOWS
+ const wchar_t *baseExecutable = _wgetenv(L"__PYVENV_BASE_EXECUTABLE__");
+ if (baseExecutable) {
+ SET_SYS_FROM_STRING("_base_executable",
+ PyUnicode_FromWideChar(baseExecutable, -1));
+ _wputenv_s(L"__PYVENV_BASE_EXECUTABLE__", L"");
+ } else {
+ SET_SYS_FROM_STRING_BORROW("_base_executable", config->executable);
+ }
+#endif
+
if (config->argv != NULL) {
SET_SYS_FROM_STRING_BORROW("argv", config->argv);
}
@@ -2528,6 +2537,7 @@ err_occurred:
return -1;
}
+#undef SET_SYS_FROM_STRING
#undef SET_SYS_FROM_STRING_BORROW
#undef SET_SYS_FROM_STRING_INT_RESULT