Skip to content

Commit 6939d48

Browse files
committed
Stop installing setuptools as a part of ensurepip and venv
This is no longer necessary since newer versions of pip are able to operate in environments that do not contain setuptools.
1 parent 82bf244 commit 6939d48

File tree

9 files changed

+25
-36
lines changed

9 files changed

+25
-36
lines changed

.github/workflows/verify-ensurepip-wheels.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Verify bundled pip and setuptools
1+
name: Verify bundled pip
22

33
on:
44
workflow_dispatch:
@@ -28,5 +28,5 @@ jobs:
2828
- uses: actions/setup-python@v4
2929
with:
3030
python-version: '3'
31-
- name: Compare checksums of bundled pip and setuptools to ones published on PyPI
31+
- name: Compare checksums of bundled pip to ones published on PyPI
3232
run: ./Tools/build/verify_ensurepip_wheels.py

Doc/library/venv.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,14 @@ creation according to their needs, the :class:`EnvBuilder` class.
284284

285285
.. method:: upgrade_dependencies(context)
286286

287-
Upgrades the core venv dependency packages (currently ``pip`` and
288-
``setuptools``) in the environment. This is done by shelling out to the
287+
Upgrades the core venv dependency packages (currently ``pip``)
288+
in the environment. This is done by shelling out to the
289289
``pip`` executable in the environment.
290290

291291
.. versionadded:: 3.9
292+
.. versionchanged:: 3.12
293+
294+
``setuptools`` is no longer a core venv dependency.
292295

293296
.. method:: post_setup(context)
294297

Lib/ensurepip/__init__.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99

1010

1111
__all__ = ["version", "bootstrap"]
12-
_PACKAGE_NAMES = ('setuptools', 'pip')
13-
_SETUPTOOLS_VERSION = "65.5.0"
12+
_PACKAGE_NAMES = ('pip',)
1413
_PIP_VERSION = "22.3.1"
1514
_PROJECTS = [
16-
("setuptools", _SETUPTOOLS_VERSION, "py3"),
1715
("pip", _PIP_VERSION, "py3"),
1816
]
1917

@@ -153,10 +151,10 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
153151

154152
_disable_pip_configuration_settings()
155153

156-
# By default, installing pip and setuptools installs all of the
154+
# By default, installing pip installs all of the
157155
# following scripts (X.Y == running Python version):
158156
#
159-
# pip, pipX, pipX.Y, easy_install, easy_install-X.Y
157+
# pip, pipX, pipX.Y
160158
#
161159
# pip 1.5+ allows ensurepip to request that some of those be left out
162160
if altinstall:
Binary file not shown.

Lib/test/test_ensurepip.py

+12-23
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def test_version(self):
2020
# Test version()
2121
with tempfile.TemporaryDirectory() as tmpdir:
2222
self.touch(tmpdir, "pip-1.2.3b1-py2.py3-none-any.whl")
23-
self.touch(tmpdir, "setuptools-49.1.3-py3-none-any.whl")
2423
with (unittest.mock.patch.object(ensurepip, '_PACKAGES', None),
2524
unittest.mock.patch.object(ensurepip, '_WHEEL_PKG_DIR', tmpdir)):
2625
self.assertEqual(ensurepip.version(), '1.2.3b1')
@@ -36,15 +35,12 @@ def test_get_packages_no_dir(self):
3635

3736
# use bundled wheel packages
3837
self.assertIsNotNone(packages['pip'].wheel_name)
39-
self.assertIsNotNone(packages['setuptools'].wheel_name)
4038

4139
def test_get_packages_with_dir(self):
4240
# Test _get_packages() with a wheel package directory
43-
setuptools_filename = "setuptools-49.1.3-py3-none-any.whl"
4441
pip_filename = "pip-20.2.2-py2.py3-none-any.whl"
4542

4643
with tempfile.TemporaryDirectory() as tmpdir:
47-
self.touch(tmpdir, setuptools_filename)
4844
self.touch(tmpdir, pip_filename)
4945
# not used, make sure that it's ignored
5046
self.touch(tmpdir, "wheel-0.34.2-py2.py3-none-any.whl")
@@ -53,15 +49,12 @@ def test_get_packages_with_dir(self):
5349
unittest.mock.patch.object(ensurepip, '_WHEEL_PKG_DIR', tmpdir)):
5450
packages = ensurepip._get_packages()
5551

56-
self.assertEqual(packages['setuptools'].version, '49.1.3')
57-
self.assertEqual(packages['setuptools'].wheel_path,
58-
os.path.join(tmpdir, setuptools_filename))
5952
self.assertEqual(packages['pip'].version, '20.2.2')
6053
self.assertEqual(packages['pip'].wheel_path,
6154
os.path.join(tmpdir, pip_filename))
6255

6356
# wheel package is ignored
64-
self.assertEqual(sorted(packages), ['pip', 'setuptools'])
57+
self.assertEqual(sorted(packages), ['pip'])
6558

6659

6760
class EnsurepipMixin:
@@ -92,13 +85,13 @@ def test_basic_bootstrapping(self):
9285
self.run_pip.assert_called_once_with(
9386
[
9487
"install", "--no-cache-dir", "--no-index", "--find-links",
95-
unittest.mock.ANY, "setuptools", "pip",
88+
unittest.mock.ANY, "pip",
9689
],
9790
unittest.mock.ANY,
9891
)
9992

10093
additional_paths = self.run_pip.call_args[0][1]
101-
self.assertEqual(len(additional_paths), 2)
94+
self.assertEqual(len(additional_paths), 1)
10295

10396
def test_bootstrapping_with_root(self):
10497
ensurepip.bootstrap(root="/foo/bar/")
@@ -107,7 +100,7 @@ def test_bootstrapping_with_root(self):
107100
[
108101
"install", "--no-cache-dir", "--no-index", "--find-links",
109102
unittest.mock.ANY, "--root", "/foo/bar/",
110-
"setuptools", "pip",
103+
"pip",
111104
],
112105
unittest.mock.ANY,
113106
)
@@ -118,7 +111,7 @@ def test_bootstrapping_with_user(self):
118111
self.run_pip.assert_called_once_with(
119112
[
120113
"install", "--no-cache-dir", "--no-index", "--find-links",
121-
unittest.mock.ANY, "--user", "setuptools", "pip",
114+
unittest.mock.ANY, "--user", "pip",
122115
],
123116
unittest.mock.ANY,
124117
)
@@ -129,7 +122,7 @@ def test_bootstrapping_with_upgrade(self):
129122
self.run_pip.assert_called_once_with(
130123
[
131124
"install", "--no-cache-dir", "--no-index", "--find-links",
132-
unittest.mock.ANY, "--upgrade", "setuptools", "pip",
125+
unittest.mock.ANY, "--upgrade", "pip",
133126
],
134127
unittest.mock.ANY,
135128
)
@@ -140,7 +133,7 @@ def test_bootstrapping_with_verbosity_1(self):
140133
self.run_pip.assert_called_once_with(
141134
[
142135
"install", "--no-cache-dir", "--no-index", "--find-links",
143-
unittest.mock.ANY, "-v", "setuptools", "pip",
136+
unittest.mock.ANY, "-v", "pip",
144137
],
145138
unittest.mock.ANY,
146139
)
@@ -151,7 +144,7 @@ def test_bootstrapping_with_verbosity_2(self):
151144
self.run_pip.assert_called_once_with(
152145
[
153146
"install", "--no-cache-dir", "--no-index", "--find-links",
154-
unittest.mock.ANY, "-vv", "setuptools", "pip",
147+
unittest.mock.ANY, "-vv", "pip",
155148
],
156149
unittest.mock.ANY,
157150
)
@@ -162,7 +155,7 @@ def test_bootstrapping_with_verbosity_3(self):
162155
self.run_pip.assert_called_once_with(
163156
[
164157
"install", "--no-cache-dir", "--no-index", "--find-links",
165-
unittest.mock.ANY, "-vvv", "setuptools", "pip",
158+
unittest.mock.ANY, "-vvv", "pip",
166159
],
167160
unittest.mock.ANY,
168161
)
@@ -239,7 +232,6 @@ def test_uninstall(self):
239232
self.run_pip.assert_called_once_with(
240233
[
241234
"uninstall", "-y", "--disable-pip-version-check", "pip",
242-
"setuptools",
243235
]
244236
)
245237

@@ -250,7 +242,6 @@ def test_uninstall_with_verbosity_1(self):
250242
self.run_pip.assert_called_once_with(
251243
[
252244
"uninstall", "-y", "--disable-pip-version-check", "-v", "pip",
253-
"setuptools",
254245
]
255246
)
256247

@@ -261,7 +252,6 @@ def test_uninstall_with_verbosity_2(self):
261252
self.run_pip.assert_called_once_with(
262253
[
263254
"uninstall", "-y", "--disable-pip-version-check", "-vv", "pip",
264-
"setuptools",
265255
]
266256
)
267257

@@ -272,7 +262,7 @@ def test_uninstall_with_verbosity_3(self):
272262
self.run_pip.assert_called_once_with(
273263
[
274264
"uninstall", "-y", "--disable-pip-version-check", "-vvv",
275-
"pip", "setuptools",
265+
"pip"
276266
]
277267
)
278268

@@ -312,13 +302,13 @@ def test_basic_bootstrapping(self):
312302
self.run_pip.assert_called_once_with(
313303
[
314304
"install", "--no-cache-dir", "--no-index", "--find-links",
315-
unittest.mock.ANY, "setuptools", "pip",
305+
unittest.mock.ANY, "pip",
316306
],
317307
unittest.mock.ANY,
318308
)
319309

320310
additional_paths = self.run_pip.call_args[0][1]
321-
self.assertEqual(len(additional_paths), 2)
311+
self.assertEqual(len(additional_paths), 1)
322312
self.assertEqual(exit_code, 0)
323313

324314
def test_bootstrapping_error_code(self):
@@ -344,7 +334,6 @@ def test_basic_uninstall(self):
344334
self.run_pip.assert_called_once_with(
345335
[
346336
"uninstall", "-y", "--disable-pip-version-check", "pip",
347-
"setuptools",
348337
]
349338
)
350339

Lib/test/test_venv.py

-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ def pip_cmd_checker(cmd, **kwargs):
227227
'install',
228228
'--upgrade',
229229
'pip',
230-
'setuptools'
231230
]
232231
)
233232

@@ -729,7 +728,6 @@ def do_test_with_pip(self, system_site_packages):
729728
# future pip versions, this test can likely be relaxed further.
730729
out = out.decode("latin-1") # Force to text, prevent decoding errors
731730
self.assertIn("Successfully uninstalled pip", out)
732-
self.assertIn("Successfully uninstalled setuptools", out)
733731
# Check pip is now gone from the virtual environment. This only
734732
# applies in the system_site_packages=False case, because in the
735733
# other case, pip may still be available in the system site-packages

Lib/venv/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import types
1414

1515

16-
CORE_VENV_DEPS = ('pip', 'setuptools')
16+
CORE_VENV_DEPS = ('pip',)
1717
logger = logging.getLogger(__name__)
1818

1919

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the bundled setuptools wheel from ``ensurepip``, and stop installing setuptools in environments created by ``venv``.

Tools/build/verify_ensurepip_wheels.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pathlib import Path
1515
from urllib.request import urlopen
1616

17-
PACKAGE_NAMES = ("pip", "setuptools")
17+
PACKAGE_NAMES = ("pip",)
1818
ENSURE_PIP_ROOT = Path(__file__).parent.parent.parent / "Lib/ensurepip"
1919
WHEEL_DIR = ENSURE_PIP_ROOT / "_bundled"
2020
ENSURE_PIP_INIT_PY_TEXT = (ENSURE_PIP_ROOT / "__init__.py").read_text(encoding="utf-8")

0 commit comments

Comments
 (0)