pypa / get-pip

Helper scripts to install pip, in a Python installation that doesn't have it.
https://bootstrap.pypa.io/pip/
MIT License
738 stars 293 forks source link

Stop installing setuptools and wheel on Python 3.12+ #218

Closed edmorley closed 3 weeks ago

edmorley commented 2 months ago

Currently get-pip.py installs not only pip, but also setuptools and wheel by default, unless the --no-setuptools / --no-wheel (or PIP_NO_SETUPTOOLS / PIP_NO_WHEEL env vars) are used.

This has historically been necessary, however, modern versions of pip will now fallback to pyproject.toml (PEP 517) based builds (which will default to a setuptools backend, and thus automatically install setuptools and wheel in the isolated build environment) if either setuptools is not installed (as of pip 22.1), or if wheel is not installed (as of pip 23.1).

In addition, as of Python 3.12, the stdlib's ensurepip and venv modules no longer install setuptools, and only install pip.

As such, it is now time for get-pip.py to stop installing setuptools and wheel by default on Python 3.12+, in order to:

Users can still request that setuptools and/or wheel are installed on Python 3.12+, by adding them to the get-pip.py invocation like so:

$ python get-pip.py setuptools wheel

Closes #200.

edmorley commented 1 month ago

Please could I have review? :-)

pradyunsg commented 1 month ago

Please could I have review? :-)

Yes, now that I have some bandwidth.

edmorley commented 1 month ago

@pradyunsg Thank you for the review! I've made those changes. I wouldn't normally force push, but since this repo appears to exclusively use standard merges rather than squash and merge, I wanted to avoid a "Apply review feedback" type commit from ending up in the log on main. To see the diff between the last version and this, use: https://github.com/pypa/get-pip/compare/2f463eb7e795d395a72f690eafca41b1b1fa8ea4..def4aec84b261b939137dd1c69eff0aabb4a7bf4

edmorley commented 1 month ago

Testing with Python 3.12:

$ docker run --rm -it python:3.12 bash
...
root@e4b186d6ffd7:/# cd tmp/
root@e4b186d6ffd7:/tmp# python -m venv .venv --without-pip
root@e4b186d6ffd7:/tmp# source .venv/bin/activate
(.venv) root@e4b186d6ffd7:/tmp# curl -fLO https://github.com/edmorley/get-pip/raw/no-setuptools-wheel/public/get-pip.py
(.venv) root@e4b186d6ffd7:/tmp# python get-pip.py
Collecting pip
  Downloading pip-24.2-py3-none-any.whl.metadata (3.6 kB)
Downloading pip-24.2-py3-none-any.whl (1.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 17.0 MB/s eta 0:00:00
Installing collected packages: pip
Successfully installed pip-24.2

And with Python 3.11:

$ docker run --rm -it python:3.11 bash
...
root@6f0dbd95ed50:/# cd tmp/
root@6f0dbd95ed50:/tmp# python -m venv .venv --without-pip
root@6f0dbd95ed50:/tmp# source .venv/bin/activate
(.venv) root@6f0dbd95ed50:/tmp# curl -fLO https://github.com/edmorley/get-pip/raw/no-setuptools-wheel/public/get-pip.py
(.venv) root@6f0dbd95ed50:/tmp# python get-pip.py
Collecting pip
  Downloading pip-24.2-py3-none-any.whl.metadata (3.6 kB)
Collecting setuptools
  Downloading setuptools-72.1.0-py3-none-any.whl.metadata (6.6 kB)
Collecting wheel
  Downloading wheel-0.43.0-py3-none-any.whl.metadata (2.2 kB)
Downloading pip-24.2-py3-none-any.whl (1.8 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 57.8 MB/s eta 0:00:00
Downloading setuptools-72.1.0-py3-none-any.whl (2.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 70.9 MB/s eta 0:00:00
Downloading wheel-0.43.0-py3-none-any.whl (65 kB)
Installing collected packages: wheel, setuptools, pip
Successfully installed pip-24.2 setuptools-72.1.0 wheel-0.43.0
edmorley commented 1 month ago

Please could I have a re-review? :-)

edmorley commented 4 weeks ago

Please may someone merge this, now that it's had review (and time for anyone else to comment/review/object)? :-)

pradyunsg commented 3 weeks ago

Thanks for the poke @edmorley! I've merged this but we can revert this if someone raises concerns around this.

edmorley commented 3 weeks ago

Thank you :-)

As a reminder to anyone coming across this PR who wants to return to the old behaviour, you can update your get-pip.py usage to this to continue to install setuptools and wheel on Python 3.12+:

$ python get-pip.py setuptools wheel