[Python-checkins] cpython: Close #19694: venv now runs ensurepip in isolated mode

nick.coghlan python-checkins at python.org
Sat Nov 23 02:38:25 CET 2013


http://hg.python.org/cpython/rev/0ce8d68181a2
changeset:   87391:0ce8d68181a2
user:        Nick Coghlan <ncoghlan at gmail.com>
date:        Sat Nov 23 11:37:28 2013 +1000
summary:
  Close #19694: venv now runs ensurepip in isolated mode

files:
  Lib/test/test_venv.py |  9 +++++++--
  Lib/venv/__init__.py  |  7 +++++--
  2 files changed, 12 insertions(+), 4 deletions(-)


diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -12,7 +12,7 @@
 import sys
 import tempfile
 from test.support import (captured_stdout, captured_stderr, run_unittest,
-                          can_symlink)
+                          can_symlink, EnvironmentVarGuard)
 import unittest
 import venv
 
@@ -280,7 +280,12 @@
 
     def test_with_pip(self):
         shutil.rmtree(self.env_dir)
-        self.run_with_capture(venv.create, self.env_dir, with_pip=True)
+        with EnvironmentVarGuard() as envvars:
+            # pip's cross-version compatibility may trigger deprecation
+            # warnings in current versions of Python. Ensure related
+            # environment settings don't cause venv to fail.
+            envvars["PYTHONWARNINGS"] = "e"
+            self.run_with_capture(venv.create, self.env_dir, with_pip=True)
         envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe)
         cmd = [envpy, '-m', 'pip', '--version']
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -234,8 +234,11 @@
 
     def _setup_pip(self, context):
         """Installs or upgrades pip in a virtual environment"""
-        cmd = [context.env_exe, '-m', 'ensurepip', '--upgrade',
-                                                   '--default-pip']
+        # We run ensurepip in isolated mode to avoid side effects from
+        # environment vars, the current directory and anything else
+        # intended for the global Python environment
+        cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade',
+                                                    '--default-pip']
         subprocess.check_output(cmd)
 
     def setup_scripts(self, context):

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list