]> granicus.if.org Git - python/commitdiff
Allow ensurepip even when ssl is unavailable
authorDonald Stufft <donald@stufft.io>
Thu, 3 Nov 2016 00:32:37 +0000 (20:32 -0400)
committerDonald Stufft <donald@stufft.io>
Thu, 3 Nov 2016 00:32:37 +0000 (20:32 -0400)
Lib/ensurepip/__init__.py
Lib/test/test_ensurepip.py
Lib/test/test_venv.py

index 68853ef0129ee6716bd285037d020e84f15bca37..7fd81c4ceadb044d36c0c393b442b4bf83f6a1e7 100644 (file)
@@ -12,19 +12,6 @@ _SETUPTOOLS_VERSION = "28.7.1"
 
 _PIP_VERSION = "9.0.0"
 
-# pip currently requires ssl support, so we try to provide a nicer
-# error message when that is missing (http://bugs.python.org/issue19744)
-_MISSING_SSL_MESSAGE = ("pip {} requires SSL/TLS".format(_PIP_VERSION))
-try:
-    import ssl
-except ImportError:
-    ssl = None
-    def _require_ssl_for_pip():
-        raise RuntimeError(_MISSING_SSL_MESSAGE)
-else:
-    def _require_ssl_for_pip():
-        pass
-
 _PROJECTS = [
     ("setuptools", _SETUPTOOLS_VERSION),
     ("pip", _PIP_VERSION),
@@ -71,7 +58,6 @@ def bootstrap(*, root=None, upgrade=False, user=False,
     if altinstall and default_pip:
         raise ValueError("Cannot use altinstall and default_pip together")
 
-    _require_ssl_for_pip()
     _disable_pip_configuration_settings()
 
     # By default, installing pip and setuptools installs all of the
@@ -133,7 +119,6 @@ def _uninstall_helper(*, verbosity=0):
         print(msg.format(pip.__version__, _PIP_VERSION), file=sys.stderr)
         return
 
-    _require_ssl_for_pip()
     _disable_pip_configuration_settings()
 
     # Construct the arguments to be passed to the pip command
@@ -145,11 +130,6 @@ def _uninstall_helper(*, verbosity=0):
 
 
 def _main(argv=None):
-    if ssl is None:
-        print("Ignoring ensurepip failure: {}".format(_MISSING_SSL_MESSAGE),
-              file=sys.stderr)
-        return
-
     import argparse
     parser = argparse.ArgumentParser(prog="python -m ensurepip")
     parser.add_argument(
index a78ca14886b8893915b512b527ebd7640befc2f4..9b04c18b0e296882487642744f54784946eb9607 100644 (file)
@@ -9,19 +9,6 @@ import sys
 import ensurepip
 import ensurepip._uninstall
 
-# pip currently requires ssl support, so we ensure we handle
-# it being missing (http://bugs.python.org/issue19744)
-ensurepip_no_ssl = test.support.import_fresh_module("ensurepip",
-                                                    blocked=["ssl"])
-try:
-    import ssl
-except ImportError:
-    def requires_usable_pip(f):
-        deco = unittest.skip(ensurepip._MISSING_SSL_MESSAGE)
-        return deco(f)
-else:
-    def requires_usable_pip(f):
-        return f
 
 class TestEnsurePipVersion(unittest.TestCase):
 
@@ -47,7 +34,6 @@ class EnsurepipMixin:
 
 class TestBootstrap(EnsurepipMixin, unittest.TestCase):
 
-    @requires_usable_pip
     def test_basic_bootstrapping(self):
         ensurepip.bootstrap()
 
@@ -62,7 +48,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
         additional_paths = self.run_pip.call_args[0][1]
         self.assertEqual(len(additional_paths), 2)
 
-    @requires_usable_pip
     def test_bootstrapping_with_root(self):
         ensurepip.bootstrap(root="/foo/bar/")
 
@@ -75,7 +60,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
             unittest.mock.ANY,
         )
 
-    @requires_usable_pip
     def test_bootstrapping_with_user(self):
         ensurepip.bootstrap(user=True)
 
@@ -87,7 +71,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
             unittest.mock.ANY,
         )
 
-    @requires_usable_pip
     def test_bootstrapping_with_upgrade(self):
         ensurepip.bootstrap(upgrade=True)
 
@@ -99,7 +82,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
             unittest.mock.ANY,
         )
 
-    @requires_usable_pip
     def test_bootstrapping_with_verbosity_1(self):
         ensurepip.bootstrap(verbosity=1)
 
@@ -111,7 +93,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
             unittest.mock.ANY,
         )
 
-    @requires_usable_pip
     def test_bootstrapping_with_verbosity_2(self):
         ensurepip.bootstrap(verbosity=2)
 
@@ -123,7 +104,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
             unittest.mock.ANY,
         )
 
-    @requires_usable_pip
     def test_bootstrapping_with_verbosity_3(self):
         ensurepip.bootstrap(verbosity=3)
 
@@ -135,17 +115,14 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
             unittest.mock.ANY,
         )
 
-    @requires_usable_pip
     def test_bootstrapping_with_regular_install(self):
         ensurepip.bootstrap()
         self.assertEqual(self.os_environ["ENSUREPIP_OPTIONS"], "install")
 
-    @requires_usable_pip
     def test_bootstrapping_with_alt_install(self):
         ensurepip.bootstrap(altinstall=True)
         self.assertEqual(self.os_environ["ENSUREPIP_OPTIONS"], "altinstall")
 
-    @requires_usable_pip
     def test_bootstrapping_with_default_pip(self):
         ensurepip.bootstrap(default_pip=True)
         self.assertNotIn("ENSUREPIP_OPTIONS", self.os_environ)
@@ -155,7 +132,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
             ensurepip.bootstrap(altinstall=True, default_pip=True)
         self.assertFalse(self.run_pip.called)
 
-    @requires_usable_pip
     def test_pip_environment_variables_removed(self):
         # ensurepip deliberately ignores all pip environment variables
         # See http://bugs.python.org/issue19734 for details
@@ -163,7 +139,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase):
         ensurepip.bootstrap()
         self.assertNotIn("PIP_THIS_SHOULD_GO_AWAY", self.os_environ)
 
-    @requires_usable_pip
     def test_pip_config_file_disabled(self):
         # ensurepip deliberately ignores the pip config file
         # See http://bugs.python.org/issue20053 for details
@@ -205,7 +180,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase):
         self.assertFalse(self.run_pip.called)
 
 
-    @requires_usable_pip
     def test_uninstall(self):
         with fake_pip():
             ensurepip._uninstall_helper()
@@ -217,7 +191,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase):
             ]
         )
 
-    @requires_usable_pip
     def test_uninstall_with_verbosity_1(self):
         with fake_pip():
             ensurepip._uninstall_helper(verbosity=1)
@@ -229,7 +202,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase):
             ]
         )
 
-    @requires_usable_pip
     def test_uninstall_with_verbosity_2(self):
         with fake_pip():
             ensurepip._uninstall_helper(verbosity=2)
@@ -241,7 +213,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase):
             ]
         )
 
-    @requires_usable_pip
     def test_uninstall_with_verbosity_3(self):
         with fake_pip():
             ensurepip._uninstall_helper(verbosity=3)
@@ -253,7 +224,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase):
             ]
         )
 
-    @requires_usable_pip
     def test_pip_environment_variables_removed(self):
         # ensurepip deliberately ignores all pip environment variables
         # See http://bugs.python.org/issue19734 for details
@@ -262,7 +232,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase):
             ensurepip._uninstall_helper()
         self.assertNotIn("PIP_THIS_SHOULD_GO_AWAY", self.os_environ)
 
-    @requires_usable_pip
     def test_pip_config_file_disabled(self):
         # ensurepip deliberately ignores the pip config file
         # See http://bugs.python.org/issue20053 for details
@@ -271,44 +240,12 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase):
         self.assertEqual(self.os_environ["PIP_CONFIG_FILE"], os.devnull)
 
 
-class TestMissingSSL(EnsurepipMixin, unittest.TestCase):
-
-    def setUp(self):
-        sys.modules["ensurepip"] = ensurepip_no_ssl
-        @self.addCleanup
-        def restore_module():
-            sys.modules["ensurepip"] = ensurepip
-        super().setUp()
-
-    def test_bootstrap_requires_ssl(self):
-        self.os_environ["PIP_THIS_SHOULD_STAY"] = "test fodder"
-        with self.assertRaisesRegex(RuntimeError, "requires SSL/TLS"):
-            ensurepip_no_ssl.bootstrap()
-        self.assertFalse(self.run_pip.called)
-        self.assertIn("PIP_THIS_SHOULD_STAY", self.os_environ)
-
-    def test_uninstall_requires_ssl(self):
-        self.os_environ["PIP_THIS_SHOULD_STAY"] = "test fodder"
-        with self.assertRaisesRegex(RuntimeError, "requires SSL/TLS"):
-            with fake_pip():
-                ensurepip_no_ssl._uninstall_helper()
-        self.assertFalse(self.run_pip.called)
-        self.assertIn("PIP_THIS_SHOULD_STAY", self.os_environ)
-
-    def test_main_exits_early_with_warning(self):
-        with test.support.captured_stderr() as stderr:
-            ensurepip_no_ssl._main(["--version"])
-        warning = stderr.getvalue().strip()
-        self.assertTrue(warning.endswith("requires SSL/TLS"), warning)
-        self.assertFalse(self.run_pip.called)
-
 # Basic testing of the main functions and their argument parsing
 
 EXPECTED_VERSION_OUTPUT = "pip " + ensurepip._PIP_VERSION
 
 class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
 
-    @requires_usable_pip
     def test_bootstrap_version(self):
         with test.support.captured_stdout() as stdout:
             with self.assertRaises(SystemExit):
@@ -317,7 +254,6 @@ class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
         self.assertEqual(result, EXPECTED_VERSION_OUTPUT)
         self.assertFalse(self.run_pip.called)
 
-    @requires_usable_pip
     def test_basic_bootstrapping(self):
         ensurepip._main([])
 
@@ -342,7 +278,6 @@ class TestUninstallationMainFunction(EnsurepipMixin, unittest.TestCase):
         self.assertEqual(result, EXPECTED_VERSION_OUTPUT)
         self.assertFalse(self.run_pip.called)
 
-    @requires_usable_pip
     def test_basic_uninstall(self):
         with fake_pip():
             ensurepip._uninstall._main([])
index f4ad7c7c5c86a045bcf37bac1c33a6001c916b47..0ff978fc8ca2c8097b5565c3e306fdaf156a3c81 100644 (file)
@@ -18,12 +18,6 @@ from test.support import (captured_stdout, captured_stderr,
 import unittest
 import venv
 
-# pip currently requires ssl support, so we ensure we handle
-# it being missing (http://bugs.python.org/issue19744)
-try:
-    import ssl
-except ImportError:
-    ssl = None
 
 try:
     import threading
@@ -337,8 +331,6 @@ class EnsurePipTest(BaseTest):
             self.assertTrue(os.path.exists(os.devnull))
 
 
-    # Requesting pip fails without SSL (http://bugs.python.org/issue19744)
-    @unittest.skipIf(ssl is None, ensurepip._MISSING_SSL_MESSAGE)
     @unittest.skipUnless(threading, 'some dependencies of pip import threading'
                                     ' module unconditionally')
     # Issue #26610: pip/pep425tags.py requires ctypes