forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷Implement build-time pip bundling @
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 python#80789. Ref: https://bugs.python.org/issue36608.
- Loading branch information
Showing
14 changed files
with
647 additions
and
240 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* | ||
!.gitignore | ||
!README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.