[Python-checkins] bpo-35811: Avoid propagating venv settings when launching via py.exe (GH-11677)

Steve Dower webhook-mailer at python.org
Fri Jan 25 18:00:01 EST 2019


https://github.com/python/cpython/commit/adad9e68013aac166c84ffe4e23f3a5464f41840
commit: adad9e68013aac166c84ffe4e23f3a5464f41840
branch: master
author: Steve Dower <steve.dower at microsoft.com>
committer: GitHub <noreply at github.com>
date: 2019-01-25T14:59:58-08:00
summary:

bpo-35811: Avoid propagating venv settings when launching via py.exe (GH-11677)

files:
A Misc/NEWS.d/next/Windows/2019-01-25-12-46-36.bpo-35811.2hU-mm.rst
M 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
index 000000000000..3207c955bff4
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2019-01-25-12-46-36.bpo-35811.2hU-mm.rst
@@ -0,0 +1 @@
+Avoid propagating venv settings when launching via py.exe
diff --git a/PC/launcher.c b/PC/launcher.c
index 4c620dab7c09..a78620a8924f 100644
--- a/PC/launcher.c
+++ b/PC/launcher.c
@@ -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



More information about the Python-checkins mailing list