Skip to content

Commit cee42c4

Browse files
committed
Merge 3.6 - allow ensurepip w/o ssl
2 parents 629dda5 + c96b8fc commit cee42c4

File tree

3 files changed

+0
-93
lines changed

3 files changed

+0
-93
lines changed

Lib/ensurepip/__init__.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@
1212

1313
_PIP_VERSION = "9.0.0"
1414

15-
# pip currently requires ssl support, so we try to provide a nicer
16-
# error message when that is missing (http://bugs.python.org/issue19744)
17-
_MISSING_SSL_MESSAGE = ("pip {} requires SSL/TLS".format(_PIP_VERSION))
18-
try:
19-
import ssl
20-
except ImportError:
21-
ssl = None
22-
def _require_ssl_for_pip():
23-
raise RuntimeError(_MISSING_SSL_MESSAGE)
24-
else:
25-
def _require_ssl_for_pip():
26-
pass
27-
2815
_PROJECTS = [
2916
("setuptools", _SETUPTOOLS_VERSION),
3017
("pip", _PIP_VERSION),
@@ -71,7 +58,6 @@ def bootstrap(*, root=None, upgrade=False, user=False,
7158
if altinstall and default_pip:
7259
raise ValueError("Cannot use altinstall and default_pip together")
7360

74-
_require_ssl_for_pip()
7561
_disable_pip_configuration_settings()
7662

7763
# By default, installing pip and setuptools installs all of the
@@ -133,7 +119,6 @@ def _uninstall_helper(*, verbosity=0):
133119
print(msg.format(pip.__version__, _PIP_VERSION), file=sys.stderr)
134120
return
135121

136-
_require_ssl_for_pip()
137122
_disable_pip_configuration_settings()
138123

139124
# Construct the arguments to be passed to the pip command
@@ -145,11 +130,6 @@ def _uninstall_helper(*, verbosity=0):
145130

146131

147132
def _main(argv=None):
148-
if ssl is None:
149-
print("Ignoring ensurepip failure: {}".format(_MISSING_SSL_MESSAGE),
150-
file=sys.stderr)
151-
return
152-
153133
import argparse
154134
parser = argparse.ArgumentParser(prog="python -m ensurepip")
155135
parser.add_argument(

Lib/test/test_ensurepip.py

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@
99
import ensurepip
1010
import ensurepip._uninstall
1111

12-
# pip currently requires ssl support, so we ensure we handle
13-
# it being missing (http://bugs.python.org/issue19744)
14-
ensurepip_no_ssl = test.support.import_fresh_module("ensurepip",
15-
blocked=["ssl"])
16-
try:
17-
import ssl
18-
except ImportError:
19-
def requires_usable_pip(f):
20-
deco = unittest.skip(ensurepip._MISSING_SSL_MESSAGE)
21-
return deco(f)
22-
else:
23-
def requires_usable_pip(f):
24-
return f
2512

2613
class TestEnsurePipVersion(unittest.TestCase):
2714

@@ -47,7 +34,6 @@ def setUp(self):
4734

4835
class TestBootstrap(EnsurepipMixin, unittest.TestCase):
4936

50-
@requires_usable_pip
5137
def test_basic_bootstrapping(self):
5238
ensurepip.bootstrap()
5339

@@ -62,7 +48,6 @@ def test_basic_bootstrapping(self):
6248
additional_paths = self.run_pip.call_args[0][1]
6349
self.assertEqual(len(additional_paths), 2)
6450

65-
@requires_usable_pip
6651
def test_bootstrapping_with_root(self):
6752
ensurepip.bootstrap(root="/foo/bar/")
6853

@@ -75,7 +60,6 @@ def test_bootstrapping_with_root(self):
7560
unittest.mock.ANY,
7661
)
7762

78-
@requires_usable_pip
7963
def test_bootstrapping_with_user(self):
8064
ensurepip.bootstrap(user=True)
8165

@@ -87,7 +71,6 @@ def test_bootstrapping_with_user(self):
8771
unittest.mock.ANY,
8872
)
8973

90-
@requires_usable_pip
9174
def test_bootstrapping_with_upgrade(self):
9275
ensurepip.bootstrap(upgrade=True)
9376

@@ -99,7 +82,6 @@ def test_bootstrapping_with_upgrade(self):
9982
unittest.mock.ANY,
10083
)
10184

102-
@requires_usable_pip
10385
def test_bootstrapping_with_verbosity_1(self):
10486
ensurepip.bootstrap(verbosity=1)
10587

@@ -111,7 +93,6 @@ def test_bootstrapping_with_verbosity_1(self):
11193
unittest.mock.ANY,
11294
)
11395

114-
@requires_usable_pip
11596
def test_bootstrapping_with_verbosity_2(self):
11697
ensurepip.bootstrap(verbosity=2)
11798

@@ -123,7 +104,6 @@ def test_bootstrapping_with_verbosity_2(self):
123104
unittest.mock.ANY,
124105
)
125106

126-
@requires_usable_pip
127107
def test_bootstrapping_with_verbosity_3(self):
128108
ensurepip.bootstrap(verbosity=3)
129109

@@ -135,17 +115,14 @@ def test_bootstrapping_with_verbosity_3(self):
135115
unittest.mock.ANY,
136116
)
137117

138-
@requires_usable_pip
139118
def test_bootstrapping_with_regular_install(self):
140119
ensurepip.bootstrap()
141120
self.assertEqual(self.os_environ["ENSUREPIP_OPTIONS"], "install")
142121

143-
@requires_usable_pip
144122
def test_bootstrapping_with_alt_install(self):
145123
ensurepip.bootstrap(altinstall=True)
146124
self.assertEqual(self.os_environ["ENSUREPIP_OPTIONS"], "altinstall")
147125

148-
@requires_usable_pip
149126
def test_bootstrapping_with_default_pip(self):
150127
ensurepip.bootstrap(default_pip=True)
151128
self.assertNotIn("ENSUREPIP_OPTIONS", self.os_environ)
@@ -155,15 +132,13 @@ def test_altinstall_default_pip_conflict(self):
155132
ensurepip.bootstrap(altinstall=True, default_pip=True)
156133
self.assertFalse(self.run_pip.called)
157134

158-
@requires_usable_pip
159135
def test_pip_environment_variables_removed(self):
160136
# ensurepip deliberately ignores all pip environment variables
161137
# See http://bugs.python.org/issue19734 for details
162138
self.os_environ["PIP_THIS_SHOULD_GO_AWAY"] = "test fodder"
163139
ensurepip.bootstrap()
164140
self.assertNotIn("PIP_THIS_SHOULD_GO_AWAY", self.os_environ)
165141

166-
@requires_usable_pip
167142
def test_pip_config_file_disabled(self):
168143
# ensurepip deliberately ignores the pip config file
169144
# See http://bugs.python.org/issue20053 for details
@@ -205,7 +180,6 @@ def test_uninstall_skipped_with_warning_for_wrong_version(self):
205180
self.assertFalse(self.run_pip.called)
206181

207182

208-
@requires_usable_pip
209183
def test_uninstall(self):
210184
with fake_pip():
211185
ensurepip._uninstall_helper()
@@ -217,7 +191,6 @@ def test_uninstall(self):
217191
]
218192
)
219193

220-
@requires_usable_pip
221194
def test_uninstall_with_verbosity_1(self):
222195
with fake_pip():
223196
ensurepip._uninstall_helper(verbosity=1)
@@ -229,7 +202,6 @@ def test_uninstall_with_verbosity_1(self):
229202
]
230203
)
231204

232-
@requires_usable_pip
233205
def test_uninstall_with_verbosity_2(self):
234206
with fake_pip():
235207
ensurepip._uninstall_helper(verbosity=2)
@@ -241,7 +213,6 @@ def test_uninstall_with_verbosity_2(self):
241213
]
242214
)
243215

244-
@requires_usable_pip
245216
def test_uninstall_with_verbosity_3(self):
246217
with fake_pip():
247218
ensurepip._uninstall_helper(verbosity=3)
@@ -253,7 +224,6 @@ def test_uninstall_with_verbosity_3(self):
253224
]
254225
)
255226

256-
@requires_usable_pip
257227
def test_pip_environment_variables_removed(self):
258228
# ensurepip deliberately ignores all pip environment variables
259229
# See http://bugs.python.org/issue19734 for details
@@ -262,7 +232,6 @@ def test_pip_environment_variables_removed(self):
262232
ensurepip._uninstall_helper()
263233
self.assertNotIn("PIP_THIS_SHOULD_GO_AWAY", self.os_environ)
264234

265-
@requires_usable_pip
266235
def test_pip_config_file_disabled(self):
267236
# ensurepip deliberately ignores the pip config file
268237
# See http://bugs.python.org/issue20053 for details
@@ -271,44 +240,12 @@ def test_pip_config_file_disabled(self):
271240
self.assertEqual(self.os_environ["PIP_CONFIG_FILE"], os.devnull)
272241

273242

274-
class TestMissingSSL(EnsurepipMixin, unittest.TestCase):
275-
276-
def setUp(self):
277-
sys.modules["ensurepip"] = ensurepip_no_ssl
278-
@self.addCleanup
279-
def restore_module():
280-
sys.modules["ensurepip"] = ensurepip
281-
super().setUp()
282-
283-
def test_bootstrap_requires_ssl(self):
284-
self.os_environ["PIP_THIS_SHOULD_STAY"] = "test fodder"
285-
with self.assertRaisesRegex(RuntimeError, "requires SSL/TLS"):
286-
ensurepip_no_ssl.bootstrap()
287-
self.assertFalse(self.run_pip.called)
288-
self.assertIn("PIP_THIS_SHOULD_STAY", self.os_environ)
289-
290-
def test_uninstall_requires_ssl(self):
291-
self.os_environ["PIP_THIS_SHOULD_STAY"] = "test fodder"
292-
with self.assertRaisesRegex(RuntimeError, "requires SSL/TLS"):
293-
with fake_pip():
294-
ensurepip_no_ssl._uninstall_helper()
295-
self.assertFalse(self.run_pip.called)
296-
self.assertIn("PIP_THIS_SHOULD_STAY", self.os_environ)
297-
298-
def test_main_exits_early_with_warning(self):
299-
with test.support.captured_stderr() as stderr:
300-
ensurepip_no_ssl._main(["--version"])
301-
warning = stderr.getvalue().strip()
302-
self.assertTrue(warning.endswith("requires SSL/TLS"), warning)
303-
self.assertFalse(self.run_pip.called)
304-
305243
# Basic testing of the main functions and their argument parsing
306244

307245
EXPECTED_VERSION_OUTPUT = "pip " + ensurepip._PIP_VERSION
308246

309247
class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
310248

311-
@requires_usable_pip
312249
def test_bootstrap_version(self):
313250
with test.support.captured_stdout() as stdout:
314251
with self.assertRaises(SystemExit):
@@ -317,7 +254,6 @@ def test_bootstrap_version(self):
317254
self.assertEqual(result, EXPECTED_VERSION_OUTPUT)
318255
self.assertFalse(self.run_pip.called)
319256

320-
@requires_usable_pip
321257
def test_basic_bootstrapping(self):
322258
ensurepip._main([])
323259

@@ -342,7 +278,6 @@ def test_uninstall_version(self):
342278
self.assertEqual(result, EXPECTED_VERSION_OUTPUT)
343279
self.assertFalse(self.run_pip.called)
344280

345-
@requires_usable_pip
346281
def test_basic_uninstall(self):
347282
with fake_pip():
348283
ensurepip._uninstall._main([])

Lib/test/test_venv.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
import unittest
1919
import venv
2020

21-
# pip currently requires ssl support, so we ensure we handle
22-
# it being missing (http://bugs.python.org/issue19744)
23-
try:
24-
import ssl
25-
except ImportError:
26-
ssl = None
2721

2822
try:
2923
import threading
@@ -337,8 +331,6 @@ def test_devnull(self):
337331
self.assertTrue(os.path.exists(os.devnull))
338332

339333

340-
# Requesting pip fails without SSL (http://bugs.python.org/issue19744)
341-
@unittest.skipIf(ssl is None, ensurepip._MISSING_SSL_MESSAGE)
342334
@unittest.skipUnless(threading, 'some dependencies of pip import threading'
343335
' module unconditionally')
344336
# Issue #26610: pip/pep425tags.py requires ctypes

0 commit comments

Comments
 (0)