From: Donald Stufft Date: Wed, 2 Nov 2016 20:20:20 +0000 (-0400) Subject: pip 9.0 works fine without the ssl module X-Git-Tag: v2.7.13rc1~50 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d01b516e9fca1a5665762035c1130cc8193c159a;p=python pip 9.0 works fine without the ssl module --- diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 1bf8e2dd84..91d77d3c2e 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -16,20 +16,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), @@ -77,7 +63,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 @@ -143,7 +128,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 @@ -155,11 +139,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( diff --git a/Lib/test/test_ensurepip.py b/Lib/test/test_ensurepip.py index 8645f058da..3316fcfaa1 100644 --- a/Lib/test/test_ensurepip.py +++ b/Lib/test/test_ensurepip.py @@ -9,22 +9,6 @@ import test.test_support 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.test_support.import_fresh_module("ensurepip", - blocked=["ssl"]) -try: - import ssl -except ImportError: - ssl = None - - 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): @@ -51,7 +35,6 @@ class EnsurepipMixin: class TestBootstrap(EnsurepipMixin, unittest.TestCase): - @requires_usable_pip def test_basic_bootstrapping(self): ensurepip.bootstrap() @@ -66,7 +49,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/") @@ -79,7 +61,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): mock.ANY, ) - @requires_usable_pip def test_bootstrapping_with_user(self): ensurepip.bootstrap(user=True) @@ -91,7 +72,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): mock.ANY, ) - @requires_usable_pip def test_bootstrapping_with_upgrade(self): ensurepip.bootstrap(upgrade=True) @@ -103,7 +83,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): mock.ANY, ) - @requires_usable_pip def test_bootstrapping_with_verbosity_1(self): ensurepip.bootstrap(verbosity=1) @@ -115,7 +94,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): mock.ANY, ) - @requires_usable_pip def test_bootstrapping_with_verbosity_2(self): ensurepip.bootstrap(verbosity=2) @@ -127,7 +105,6 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): mock.ANY, ) - @requires_usable_pip def test_bootstrapping_with_verbosity_3(self): ensurepip.bootstrap(verbosity=3) @@ -139,17 +116,14 @@ class TestBootstrap(EnsurepipMixin, unittest.TestCase): 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) @@ -159,7 +133,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 @@ -167,7 +140,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 @@ -210,7 +182,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase): self.assertIn("only uninstall a matching version", warning) self.assertFalse(self.run_pip.called) - @requires_usable_pip def test_uninstall(self): with fake_pip(): ensurepip._uninstall_helper() @@ -222,7 +193,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase): ] ) - @requires_usable_pip def test_uninstall_with_verbosity_1(self): with fake_pip(): ensurepip._uninstall_helper(verbosity=1) @@ -234,7 +204,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase): ] ) - @requires_usable_pip def test_uninstall_with_verbosity_2(self): with fake_pip(): ensurepip._uninstall_helper(verbosity=2) @@ -246,7 +215,6 @@ class TestUninstall(EnsurepipMixin, unittest.TestCase): ] ) - @requires_usable_pip def test_uninstall_with_verbosity_3(self): with fake_pip(): ensurepip._uninstall_helper(verbosity=3) @@ -258,7 +226,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 @@ -267,7 +234,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 @@ -276,38 +242,6 @@ 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(TestMissingSSL, self).setUp() - - def test_bootstrap_requires_ssl(self): - self.os_environ["PIP_THIS_SHOULD_STAY"] = "test fodder" - with self.assertRaisesRegexp(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.assertRaisesRegexp(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.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 @@ -315,7 +249,6 @@ EXPECTED_VERSION_OUTPUT = "pip " + ensurepip._PIP_VERSION class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase): - @requires_usable_pip def test_bootstrap_version(self): with test.test_support.captured_stderr() as stderr: with self.assertRaises(SystemExit): @@ -324,7 +257,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([]) @@ -350,7 +282,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([])