-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-80789: Implement build-time pip bundling in ensurepip
#12791
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
Changes from 1 commit
c31bdca
abe7339
d2ae980
5bf0cda
388113b
6edef14
7be49ec
ae92ab9
0178658
00c761f
f4bf361
2615fe8
2ed185f
8d1ddcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
ensurepip
Prior to this patch, Pip wheels were stored in the Git repository of CPython. Git is optimized for text but these artifacts are binary. So the unpleasant side effect of doing this is that the bare Git repository size is being increased by the zip archive side every time it is added, removed or modified. It's time to put a stop to this. The patch implements an `ensurepip.bundle` module that is meant to be called through `runpy` to download the Pip wheel and place it into the same location as before. It removes the wheel file from the Git repository and prevents re-adding it by defining a new `.gitignore` configuration file. The idea is that the builders of CPython are supposed to invoke the following command during the build time: ```console $ python -m ensurepip.bundle ``` This command will verify the existing wheel's SHA-256 hash and, if it does not match, or doesn't exist, it will proceed to download the artifact from PyPI. It will confirm its SHA-256 hash before placing it into the `Lib/ensurepip/_bundled/` directory. Every single line added or modified as a part of this change is also covered with tests. Every new module has 100% coverage. The only uncovered lines under `Lib/ensurepip/` are the ones that are absolutely unrelated to this effort. Resolves #80789. Ref: https://bugs.python.org/issue36608.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ jobs: | |
- name: 'Configure CPython' | ||
run: ./configure --with-pydebug | ||
- name: 'Build CPython' | ||
run: make -j4 | ||
run: make all-with-ensurepip-dists-bundled -j4 | ||
- name: 'Install build dependencies' | ||
run: make -C Doc/ PYTHON=../python venv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AA-Turner so I looked into whether bundling pip into ensurepip is needed in doctests and the answer is “yes”. This line calls |
||
# Use "xvfb-run" since some doctest tests open GUI windows | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* | ||
!.gitignore | ||
!README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Upstream packaging | ||
|
||
To populate this directory, the initial build packagers are supposed | ||
to invoke the following command: | ||
|
||
```console | ||
$ python -m ensurepip.bundle | ||
``` | ||
|
||
It will download a pre-defined version of the Pip wheel. Its SHA-256 | ||
hash is guaranteed to match the one on PyPI. | ||
|
||
# Downstream packaging | ||
|
||
Packagers of the downstream distributions are welcome to put an | ||
alternative wheel version in the directory defined by the | ||
`WHEEL_PKG_DIR` configuration setting. If this is done, | ||
|
||
```console | ||
$ python -m ensurepip | ||
``` | ||
|
||
will prefer the replacement distribution package over the bundled one. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Build time dist downloading and bundling logic.""" | ||
|
||
from __future__ import annotations | ||
|
||
import sys | ||
from contextlib import suppress | ||
from importlib.resources import as_file as _traversable_to_pathlib_ctx | ||
|
||
from ._structs import BUNDLED_WHEELS_PATH, REMOTE_DIST_PKGS | ||
|
||
|
||
def ensure_wheels_are_downloaded(*, verbosity: bool = False) -> None: | ||
"""Download wheels into bundle if they are not there yet.""" | ||
for pkg in REMOTE_DIST_PKGS: | ||
existing_whl_file_path = BUNDLED_WHEELS_PATH / pkg.wheel_file_name | ||
with suppress(FileNotFoundError): | ||
if pkg.matches(existing_whl_file_path.read_bytes()): | ||
if verbosity: | ||
print( | ||
f'A valid `{pkg.wheel_file_name}` is already ' | ||
'present in cache. Skipping download.', | ||
file=sys.stderr, | ||
) | ||
continue | ||
|
||
if verbosity: | ||
print( | ||
f'Downloading `{pkg.wheel_file_name}`...', | ||
file=sys.stderr, | ||
) | ||
downloaded_whl_contents = pkg.download_verified_wheel_contents() | ||
|
||
if verbosity: | ||
print( | ||
f'Saving `{pkg.wheel_file_name}` to disk...', | ||
file=sys.stderr, | ||
) | ||
with _traversable_to_pathlib_ctx(BUNDLED_WHEELS_PATH) as bundled_dir: | ||
whl_file_path = bundled_dir / pkg.wheel_file_name | ||
whl_file_path.write_bytes(downloaded_whl_contents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need ensurepip for the doctests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. I thought something was failing, but that was at the time when I was trying to figure out the Makefile integration, and it didn't work. So maybe not, this needs some experimentation.