Skip to content

Commit

Permalink
Don't exclude setuptools, distribute & wheel from freeze output on Py…
Browse files Browse the repository at this point in the history
…thon 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
  • Loading branch information
SpecLad committed May 15, 2023
1 parent f617fdc commit fe72585
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions news/4256.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
``freeze`` no longer excludes the ``setuptools``, ``distribute`` and ``wheel``
packages from the output by default when running on Python 3.12 or later.
Use ``--exclude`` if you wish to exclude any of these packages.
5 changes: 4 additions & 1 deletion src/pip/_internal/commands/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from pip._internal.operations.freeze import freeze
from pip._internal.utils.compat import stdlib_pkgs

DEV_PKGS = {"pip", "setuptools", "distribute", "wheel"}
DEV_PKGS = {"pip"}

if sys.version_info < (3, 12):
DEV_PKGS |= {"setuptools", "distribute", "wheel"}


class FreezeCommand(Command):
Expand Down
19 changes: 18 additions & 1 deletion tests/functional/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,27 @@ def test_basic_freeze(script: PipTestEnvironment) -> None:


def test_freeze_with_pip(script: PipTestEnvironment) -> None:
"""Test pip shows itself"""
"""Test that pip shows itself only when --all is used"""
result = script.pip("freeze")
assert "pip==" not in result.stdout
result = script.pip("freeze", "--all")
assert "pip==" in result.stdout

def test_freeze_with_setuptools(script: PipTestEnvironment) -> None:
"""
Test that pip shows setuptools only when --all is used
or Python version is >=3.12
"""

result = script.pip("freeze")
if sys.version_info >= (3, 12):
assert "setuptools==" in result.stdout
else:
assert "setuptools==" not in result.stdout

result = script.pip("freeze", "--all")
assert "setuptools==" in result.stdout


def test_exclude_and_normalization(script: PipTestEnvironment, tmpdir: Path) -> None:
req_path = wheel.make_wheel(name="Normalizable_Name", version="1.0").save_to_dir(
Expand Down

0 comments on commit fe72585

Please sign in to comment.