Skip to content

Commit def4aec

Browse files
committed
Stop installing setuptools and wheel on Python 3.12+
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: [1]) 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: [2]), or if wheel is not installed (as of pip 23.1: [3]). In addition, as of Python 3.12, the stdlib's `ensurepip` and `venv` modules no longer install setuptools, and only install pip ([4]). 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: - Act as another small step towards `pyproject.toml` / PEP 517 based builds eventually becoming the pip default. - Improve parity with the behaviour of `ensurepip` / `venv` on Python 3.12+. - Allow `get-pip.py` to focus on its primary responsibility: bootstrapping Pip. Closes pypa#200. [1]: https://peps.python.org/pep-0517/ [2]: pypa/pip#10717 [3]: pypa/pip#11871 [4]: python/cpython#101039
1 parent ac92537 commit def4aec

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

README.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# get-pip.py
22

3-
`get-pip.py` is a bootstrapping script that enables users to install pip,
4-
setuptools, and wheel in Python environments that don't already have them. You
3+
`get-pip.py` is a bootstrapping script that enables users to install pip
4+
in Python environments that don't already have it installed. You
55
should not directly reference the files located in this repository and instead
66
use the versions located at <https://bootstrap.pypa.io/>.
77

@@ -12,26 +12,34 @@ $ curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
1212
$ python get-pip.py
1313
```
1414

15-
Upon execution, `get-pip.py` will install `pip`, `setuptools` and `wheel` in
16-
the current Python environment.
15+
Upon execution, `get-pip.py` will install the latest version of `pip` into the
16+
current Python environment. When using Python 3.11 or older, by default the
17+
packages `setuptools` and `wheel` will also be installed if an existing version
18+
of them was not found.
1719

1820
It is possible to provide additional arguments to the underlying script. These
1921
are passed through to the underlying `pip install` command, and can thus be
20-
used to constraint the versions of the packages, or to pass other pip options
21-
such as `--no-index`.
22+
used to constrain the versions of the packages, install additional packages,
23+
or to pass other pip options such as `--no-index`.
2224

2325
```console
24-
$ python get-pip.py "pip < 21.0" "setuptools < 50.0" "wheel < 1.0"
26+
# Constrain the pip version
27+
$ python get-pip.py "pip < 21.0"
28+
29+
# Force the installation of `setuptools` and `wheel` on newer Python versions.
30+
$ python get-pip.py setuptools wheel
31+
32+
# Install packages from a local directory instead of PyPI.
2533
$ python get-pip.py --no-index --find-links=/local/copies
2634
```
2735

2836
### get-pip.py options
2937

30-
This script also has it's own options, which control which packages it will
38+
This script also has its own options, which control which packages it will
3139
install.
3240

33-
- `--no-setuptools`: do not attempt to install `setuptools`.
34-
- `--no-wheel`: do not attempt to install `wheel`.
41+
- `--no-setuptools`: Do not attempt to install `setuptools`. This is a no-op on Python 3.12+.
42+
- `--no-wheel`: Do not attempt to install `wheel`. This is a no-op on Python 3.12+.
3543

3644
## Development
3745

public/3.6/get-pip.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,24 @@
4545

4646
def include_setuptools(args):
4747
"""
48-
Install setuptools only if absent and not excluded.
48+
Install setuptools only if absent, not excluded and when using Python <3.12.
4949
"""
5050
cli = not args.no_setuptools
5151
env = not os.environ.get("PIP_NO_SETUPTOOLS")
5252
absent = not importlib.util.find_spec("setuptools")
53-
return cli and env and absent
53+
python_lt_3_12 = this_python < (3, 12)
54+
return cli and env and absent and python_lt_3_12
5455

5556

5657
def include_wheel(args):
5758
"""
58-
Install wheel only if absent and not excluded.
59+
Install wheel only if absent, not excluded and when using Python <3.12.
5960
"""
6061
cli = not args.no_wheel
6162
env = not os.environ.get("PIP_NO_WHEEL")
6263
absent = not importlib.util.find_spec("wheel")
63-
return cli and env and absent
64+
python_lt_3_12 = this_python < (3, 12)
65+
return cli and env and absent and python_lt_3_12
6466

6567

6668
def determine_pip_install_arguments():
@@ -111,7 +113,7 @@ def bootstrap(tmpdir):
111113
monkeypatch_for_cert(tmpdir)
112114

113115
# Execute the included pip and use it to install the latest pip and
114-
# setuptools from PyPI
116+
# any user-requested packages from PyPI.
115117
from pip._internal.cli.main import main as pip_entry_point
116118
args = determine_pip_install_arguments()
117119
sys.exit(pip_entry_point(args))

public/3.7/get-pip.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,24 @@
4545

4646
def include_setuptools(args):
4747
"""
48-
Install setuptools only if absent and not excluded.
48+
Install setuptools only if absent, not excluded and when using Python <3.12.
4949
"""
5050
cli = not args.no_setuptools
5151
env = not os.environ.get("PIP_NO_SETUPTOOLS")
5252
absent = not importlib.util.find_spec("setuptools")
53-
return cli and env and absent
53+
python_lt_3_12 = this_python < (3, 12)
54+
return cli and env and absent and python_lt_3_12
5455

5556

5657
def include_wheel(args):
5758
"""
58-
Install wheel only if absent and not excluded.
59+
Install wheel only if absent, not excluded and when using Python <3.12.
5960
"""
6061
cli = not args.no_wheel
6162
env = not os.environ.get("PIP_NO_WHEEL")
6263
absent = not importlib.util.find_spec("wheel")
63-
return cli and env and absent
64+
python_lt_3_12 = this_python < (3, 12)
65+
return cli and env and absent and python_lt_3_12
6466

6567

6668
def determine_pip_install_arguments():
@@ -111,7 +113,7 @@ def bootstrap(tmpdir):
111113
monkeypatch_for_cert(tmpdir)
112114

113115
# Execute the included pip and use it to install the latest pip and
114-
# setuptools from PyPI
116+
# any user-requested packages from PyPI.
115117
from pip._internal.cli.main import main as pip_entry_point
116118
args = determine_pip_install_arguments()
117119
sys.exit(pip_entry_point(args))

public/get-pip.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,24 @@
4545

4646
def include_setuptools(args):
4747
"""
48-
Install setuptools only if absent and not excluded.
48+
Install setuptools only if absent, not excluded and when using Python <3.12.
4949
"""
5050
cli = not args.no_setuptools
5151
env = not os.environ.get("PIP_NO_SETUPTOOLS")
5252
absent = not importlib.util.find_spec("setuptools")
53-
return cli and env and absent
53+
python_lt_3_12 = this_python < (3, 12)
54+
return cli and env and absent and python_lt_3_12
5455

5556

5657
def include_wheel(args):
5758
"""
58-
Install wheel only if absent and not excluded.
59+
Install wheel only if absent, not excluded and when using Python <3.12.
5960
"""
6061
cli = not args.no_wheel
6162
env = not os.environ.get("PIP_NO_WHEEL")
6263
absent = not importlib.util.find_spec("wheel")
63-
return cli and env and absent
64+
python_lt_3_12 = this_python < (3, 12)
65+
return cli and env and absent and python_lt_3_12
6466

6567

6668
def determine_pip_install_arguments():
@@ -111,7 +113,7 @@ def bootstrap(tmpdir):
111113
monkeypatch_for_cert(tmpdir)
112114

113115
# Execute the included pip and use it to install the latest pip and
114-
# setuptools from PyPI
116+
# any user-requested packages from PyPI.
115117
from pip._internal.cli.main import main as pip_entry_point
116118
args = determine_pip_install_arguments()
117119
sys.exit(pip_entry_point(args))

templates/default.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,24 @@
4545

4646
def include_setuptools(args):
4747
"""
48-
Install setuptools only if absent and not excluded.
48+
Install setuptools only if absent, not excluded and when using Python <3.12.
4949
"""
5050
cli = not args.no_setuptools
5151
env = not os.environ.get("PIP_NO_SETUPTOOLS")
5252
absent = not importlib.util.find_spec("setuptools")
53-
return cli and env and absent
53+
python_lt_3_12 = this_python < (3, 12)
54+
return cli and env and absent and python_lt_3_12
5455

5556

5657
def include_wheel(args):
5758
"""
58-
Install wheel only if absent and not excluded.
59+
Install wheel only if absent, not excluded and when using Python <3.12.
5960
"""
6061
cli = not args.no_wheel
6162
env = not os.environ.get("PIP_NO_WHEEL")
6263
absent = not importlib.util.find_spec("wheel")
63-
return cli and env and absent
64+
python_lt_3_12 = this_python < (3, 12)
65+
return cli and env and absent and python_lt_3_12
6466

6567

6668
def determine_pip_install_arguments():
@@ -111,7 +113,7 @@ def bootstrap(tmpdir):
111113
monkeypatch_for_cert(tmpdir)
112114

113115
# Execute the included pip and use it to install the latest pip and
114-
# setuptools from PyPI
116+
# any user-requested packages from PyPI.
115117
from pip._internal.cli.main import main as pip_entry_point
116118
args = determine_pip_install_arguments()
117119
sys.exit(pip_entry_point(args))

0 commit comments

Comments
 (0)