Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't exclude setuptools, distribute & wheel from freeze output on Python 3.12+ #12032

Merged
merged 3 commits into from
Jul 7, 2023

Conversation

SpecLad
Copy link
Contributor

@SpecLad SpecLad commented May 15, 2023

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 (python/cpython#95299) and virtualenv (pypa/virtualenv#2558) 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.

Closes #4256.

noxfile.py Outdated Show resolved Hide resolved
"""Test pip shows itself"""
"""Test that pip shows itself only when --all is used"""
result = script.pip("freeze")
assert "pip==" not in result.stdout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also doesn't seem directly related to this PR. It's a sensible addition, but why is it included here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making sure that pip is still hidden by default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment mentioning pip should hide itself from freeze would be useful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the test docstring say exactly that?

"""

result = script.pip("freeze")
if sys.version_info >= (3, 12):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this test by mocking the value of sys.version_info, rather than having the test do different things depending on what Python version it's run under? That may be overkill, and may be difficult to achieve because the test runs pip in a subprocess, so I'm not suggesting that this is essential, but it's worth thinking about (especially as CI currently won't check this change at all).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like overkill, frankly. 3.12 will be added to CI sooner or later anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to mocking, doing conditional here makes running tests locally unnecessarily difficult.

Copy link
Contributor Author

@SpecLad SpecLad May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it more thought, and mocking sys.version_info really does not seem like a good idea. Imagine that pip (or one of its dependencies) does something like this in the code:

if sys.version_info >= (3, 12):
    # use feature that is only available in 3.12+

Then if you set sys.version_info to 3.12.x while running on, say, 3.8.x, then this code will break.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or two tests with different skip_if decorators?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of mocking sys.version_info directly, I’d add a function that toggles freeze output, and mock that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of mocking sys.version_info directly, I’d add a function that toggles freeze output, and mock that.

Okay, I did it.

@SpecLad SpecLad force-pushed the freeze-setuptools branch from 6e263eb to 28217cc Compare May 15, 2023 22:12
@SpecLad SpecLad force-pushed the freeze-setuptools branch from 28217cc to 7b6a81b Compare May 28, 2023 22:30
news/4256.removal.rst Outdated Show resolved Hide resolved
SpecLad added 2 commits July 7, 2023 01:46
…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
This makes it possible to test both branches on any Python version.
@SpecLad SpecLad force-pushed the freeze-setuptools branch from 9610d5b to 393ccfb Compare July 6, 2023 22:46
Comment on lines -64 to +75
" {}".format(", ".join(DEV_PKGS))
" {}".format(", ".join(_dev_pkgs()))
Copy link
Member

@uranusjr uranusjr Jul 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor note, it’d be a good idea to add some sorting here so the order package appear is more stable. But honestly nobody cares that much about these help messages anyway so it’s fine to keep things as-is.

@pradyunsg pradyunsg merged commit 177cf88 into pypa:main Jul 7, 2023
@SpecLad SpecLad deleted the freeze-setuptools branch July 8, 2023 12:49
@atugushev
Copy link
Contributor

@pradyunsg will this be released in 23.2 or sooner?

@pfmoore
Copy link
Member

pfmoore commented Jul 9, 2023

It's been merged, so it will be in 23.2.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revisit displaying setuptools in pip freeze?
6 participants