Skip to content

Commit ece20db

Browse files
pradyunsghugovkCAM-Gerlacharhadthedev
authored
gh-95299: Stop installing setuptools as a part of ensurepip and venv (#101039)
Remove the bundled setuptools wheel from ensurepip, and stop installing setuptools in environments created by venv. Co-Authored-by: Hugo van Kemenade <[email protected]> Co-authored-by: C.A.M. Gerlach <[email protected]> Co-authored-by: Oleg Iarygin <[email protected]>
1 parent f39e00f commit ece20db

File tree

13 files changed

+57
-48
lines changed

13 files changed

+57
-48
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 wheels
22

33
on:
44
workflow_dispatch:
@@ -29,5 +29,5 @@ jobs:
2929
- uses: actions/setup-python@v4
3030
with:
3131
python-version: '3'
32-
- name: Compare checksums of bundled pip and setuptools to ones published on PyPI
32+
- name: Compare checksum of bundled wheels to the ones published on PyPI
3333
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

Doc/using/venv-create.inc

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ The command, if run with ``-h``, will show the available options::
6161
environment (pip is bootstrapped by default)
6262
--prompt PROMPT Provides an alternative prompt prefix for this
6363
environment.
64-
--upgrade-deps Upgrade core dependencies: pip setuptools to the
64+
--upgrade-deps Upgrade core dependencies (pip) to the
6565
latest version in PyPI
6666
6767
Once an environment has been created, you may wish to activate it, e.g. by
6868
sourcing an activate script in its bin directory.
6969
70+
.. versionchanged:: 3.12
71+
72+
``setuptools`` is no longer a core venv dependency.
73+
7074
.. versionchanged:: 3.9
7175
Add ``--upgrade-deps`` option to upgrade pip + setuptools to the latest on PyPI
7276
@@ -104,4 +108,3 @@ invoked to bootstrap ``pip`` into the virtual environment.
104108
Multiple paths can be given to ``venv``, in which case an identical virtual
105109
environment will be created, according to the given options, at each provided
106110
path.
107-

Doc/whatsnew/3.12.rst

+18
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,24 @@ Removed
731731
project can be installed: it still provides ``distutils``.
732732
(Contributed by Victor Stinner in :gh:`92584`.)
733733

734+
* Remove the bundled setuptools wheel from :mod:`ensurepip`,
735+
and stop installing setuptools in environments created by :mod:`venv`.
736+
737+
``pip (>= 22.1)`` does not require setuptools to be installed in the
738+
environment. ``setuptools``-based (and ``distutils``-based) packages
739+
can still be used with ``pip install``, since pip will provide
740+
``setuptools`` in the build environment it uses for building a
741+
package.
742+
743+
``easy_install``, ``pkg_resources``, ``setuptools`` and ``distutils``
744+
are no longer provided by default in environments created with
745+
``venv`` or bootstrapped with ``ensurepip``, since they are part of
746+
the ``setuptools`` package. For projects relying on these at runtime,
747+
the ``setuptools`` project should be declared as a dependency and
748+
installed separately (typically, using pip).
749+
750+
(Contributed by Pradyun Gedam in :gh:`95299`.)
751+
734752
* Removed many old deprecated :mod:`unittest` features:
735753

736754
- A number of :class:`~unittest.TestCase` method aliases:

Lib/ensurepip/__init__.py

+7-9
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 = "23.0.1"
1514
_PROJECTS = [
16-
("setuptools", _SETUPTOOLS_VERSION, "py3"),
1715
("pip", _PIP_VERSION, "py3"),
1816
]
1917

@@ -153,17 +151,17 @@ 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:
163-
# omit pip, pipX and easy_install
161+
# omit pip, pipX
164162
os.environ["ENSUREPIP_OPTIONS"] = "altinstall"
165163
elif not default_pip:
166-
# omit pip and easy_install
164+
# omit pip
167165
os.environ["ENSUREPIP_OPTIONS"] = "install"
168166

169167
with tempfile.TemporaryDirectory() as tmpdir:
@@ -271,14 +269,14 @@ def _main(argv=None):
271269
action="store_true",
272270
default=False,
273271
help=("Make an alternate install, installing only the X.Y versioned "
274-
"scripts (Default: pipX, pipX.Y, easy_install-X.Y)."),
272+
"scripts (Default: pipX, pipX.Y)."),
275273
)
276274
parser.add_argument(
277275
"--default-pip",
278276
action="store_true",
279277
default=False,
280278
help=("Make a default pip install, installing the unqualified pip "
281-
"and easy_install in addition to the versioned scripts."),
279+
"in addition to the versioned scripts."),
282280
)
283281

284282
args = parser.parse_args(argv)
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

@@ -745,7 +744,6 @@ def do_test_with_pip(self, system_site_packages):
745744
# future pip versions, this test can likely be relaxed further.
746745
out = out.decode("latin-1") # Force to text, prevent decoding errors
747746
self.assertIn("Successfully uninstalled pip", out)
748-
self.assertIn("Successfully uninstalled setuptools", out)
749747
# Check pip is now gone from the virtual environment. This only
750748
# applies in the system_site_packages=False case, because in the
751749
# other case, pip may still be available in the system site-packages

Lib/venv/__init__.py

+2-2
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

@@ -523,7 +523,7 @@ def main(args=None):
523523
'this environment.')
524524
parser.add_argument('--upgrade-deps', default=False, action='store_true',
525525
dest='upgrade_deps',
526-
help=f'Upgrade core dependencies: {", ".join(CORE_VENV_DEPS)} '
526+
help=f'Upgrade core dependencies ({", ".join(CORE_VENV_DEPS)}) '
527527
'to the latest version in PyPI')
528528
options = parser.parse_args(args)
529529
if options.upgrade and options.clear:

Mac/BuildScript/scripts/postflight.ensurepip

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ if [ -d /usr/local/bin ] ; then
5656

5757
cd /usr/local/bin
5858

59-
# Create pipx.y and easy_install-x.y links if /usr/local/bin/pythonx.y
59+
# Create pipx.y links if /usr/local/bin/pythonx.y
6060
# is linked to this framework version
6161
install_links_if_our_fw "python${PYVER}" \
62-
"pip${PYVER}" "easy_install-${PYVER}"
62+
"pip${PYVER}"
6363

6464
# Create pipx link if /usr/local/bin/pythonx is linked to this version
6565
install_links_if_our_fw "python${PYMAJOR}" \
6666
"pip${PYMAJOR}"
6767

68-
# Create pip and easy_install link if /usr/local/bin/python
68+
# Create pip link if /usr/local/bin/python
6969
# is linked to this version
7070
install_links_if_our_fw "python" \
71-
"pip" "easy_install"
71+
"pip"
7272
)
7373
fi
7474
exit 0

Mac/Makefile.in

-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ altinstallunixtools:
166166
-if test "x$(ENSUREPIP)" != "xno" ; then \
167167
cd "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" && \
168168
for fn in \
169-
easy_install-$(VERSION) \
170169
pip$(VERSION) \
171170
; \
172171
do \
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)