]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Close #19694: venv now runs ensurepip in isolated mode
authorNick Coghlan <ncoghlan@gmail.com>
Sat, 23 Nov 2013 01:37:28 +0000 (11:37 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Sat, 23 Nov 2013 01:37:28 +0000 (11:37 +1000)
Lib/test/test_venv.py
Lib/venv/__init__.py

index 6047f874c313debaa2aaef1807b5747148cba258..87d727e8cb83d81e247e752b58c68fe7f9e201ca 100644 (file)
@@ -12,7 +12,7 @@ import subprocess
 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 @@ class EnsurePipTest(BaseTest):
 
     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,
index 2991c6692f5745aab28426f3485421870c21c724..14158e97d59f80ebaedfe8c3ab4edf9b479b4e31 100644 (file)
@@ -234,8 +234,11 @@ class EnvBuilder:
 
     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):