Skip to content

Commit 28217cc

Browse files
committed
Don't exclude setuptools, distribute & wheel from freeze output on Python 3.12+
Due to the advent of build isolation, it is no longer necessary to install setuptools and wheel in an environment just to install other packages. Moreover, on Python 3.12 both ensurepip [1] and virtualenv [2] are to stop installing setuptools & wheel by default. This means that when those packages are present in a Python 3.12+ environment, it is reasonable to assume that they are runtime dependencies of the user's project, and therefore should be included in freeze output. distribute is just obsolete. [1] python/cpython#95299 [2] pypa/virtualenv#2558
1 parent f25f8ff commit 28217cc

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

news/4256.removal.rst

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``freeze`` no longer excludes the ``setuptools``, ``distribute`` and ``wheel``
2+
packages from the output by default when running on Python 3.12 or later.
3+
Use ``--exclude`` if you wish to exclude any of these packages.

src/pip/_internal/commands/freeze.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
from pip._internal.operations.freeze import freeze
99
from pip._internal.utils.compat import stdlib_pkgs
1010

11-
DEV_PKGS = {"pip", "setuptools", "distribute", "wheel"}
11+
DEV_PKGS = {"pip"}
12+
13+
if sys.version_info < (3, 12):
14+
DEV_PKGS |= {"setuptools", "distribute", "wheel"}
1215

1316

1417
class FreezeCommand(Command):

tests/functional/test_freeze.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,29 @@ def test_basic_freeze(script: PipTestEnvironment) -> None:
8888

8989

9090
def test_freeze_with_pip(script: PipTestEnvironment) -> None:
91-
"""Test pip shows itself"""
91+
"""Test that pip shows itself only when --all is used"""
92+
result = script.pip("freeze")
93+
assert "pip==" not in result.stdout
9294
result = script.pip("freeze", "--all")
9395
assert "pip==" in result.stdout
9496

9597

98+
def test_freeze_with_setuptools(script: PipTestEnvironment) -> None:
99+
"""
100+
Test that pip shows setuptools only when --all is used
101+
or Python version is >=3.12
102+
"""
103+
104+
result = script.pip("freeze")
105+
if sys.version_info >= (3, 12):
106+
assert "setuptools==" in result.stdout
107+
else:
108+
assert "setuptools==" not in result.stdout
109+
110+
result = script.pip("freeze", "--all")
111+
assert "setuptools==" in result.stdout
112+
113+
96114
def test_exclude_and_normalization(script: PipTestEnvironment, tmpdir: Path) -> None:
97115
req_path = wheel.make_wheel(name="Normalizable_Name", version="1.0").save_to_dir(
98116
tmpdir

0 commit comments

Comments
 (0)