]> granicus.if.org Git - python/commitdiff
bpo-35811: Avoid propagating venv settings when launching via py.exe (GH-11677)
authorSteve Dower <steve.dower@microsoft.com>
Fri, 25 Jan 2019 22:59:58 +0000 (14:59 -0800)
committerGitHub <noreply@github.com>
Fri, 25 Jan 2019 22:59:58 +0000 (14:59 -0800)
Misc/NEWS.d/next/Windows/2019-01-25-12-46-36.bpo-35811.2hU-mm.rst [new file with mode: 0644]
PC/launcher.c

diff --git a/Misc/NEWS.d/next/Windows/2019-01-25-12-46-36.bpo-35811.2hU-mm.rst b/Misc/NEWS.d/next/Windows/2019-01-25-12-46-36.bpo-35811.2hU-mm.rst
new file mode 100644 (file)
index 0000000..3207c95
--- /dev/null
@@ -0,0 +1 @@
+Avoid propagating venv settings when launching via py.exe
index 4c620dab7c096447f122d432a8cc33aaff627b4d..a78620a8924fdd7143fa603c8ed1b915c85a3cc9 100644 (file)
@@ -1707,6 +1707,17 @@ process(int argc, wchar_t ** argv)
     command = skip_me(GetCommandLineW());
     debug(L"Called with command line: %ls\n", command);
 
+#if !defined(VENV_REDIRECT)
+    /* bpo-35811: The __PYVENV_LAUNCHER__ variable is used to
+     * override sys.executable and locate the original prefix path. 
+     * However, if it is silently inherited by a non-venv Python
+     * process, that process will believe it is running in the venv
+     * still. This is the only place where *we* can clear it (that is,
+     * when py.exe is being used to launch Python), so we do.
+     */
+    SetEnvironmentVariableW(L"__PYVENV_LAUNCHER__", NULL);
+#endif
+
 #if defined(SCRIPT_WRAPPER)
     /* The launcher is being used in "script wrapper" mode.
      * There should therefore be a Python script named <exename>-script.py in