-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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 all commits
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -231,7 +231,7 @@ jobs: | |
--prefix=/opt/python-dev \ | ||
--with-openssl="$(brew --prefix [email protected])" | ||
- name: Build CPython | ||
run: make -j4 | ||
run: make all-with-ensurepip-dists-bundled -j4 | ||
- name: Display build info | ||
run: make pythoninfo | ||
- name: Tests | ||
|
@@ -300,6 +300,11 @@ jobs: | |
- name: Remount sources writable for tests | ||
# some tests write to srcdir, lack of pyc files slows down testing | ||
run: sudo mount $CPYTHON_RO_SRCDIR -oremount,rw | ||
- name: Bundle ensurepip dists | ||
env: | ||
SSL_CERT_DIR: /etc/ssl/certs | ||
run: make download-ensurepip-blobs | ||
working-directory: ${{ env.CPYTHON_BUILDDIR }} | ||
- name: Tests | ||
working-directory: ${{ env.CPYTHON_BUILDDIR }} | ||
run: xvfb-run make buildbottest TESTOPTS="-j4 -uall,-cpu" | ||
|
@@ -352,7 +357,9 @@ jobs: | |
- name: Configure CPython | ||
run: ./configure --config-cache --with-pydebug --with-openssl=$OPENSSL_DIR | ||
- name: Build CPython | ||
run: make -j4 | ||
env: | ||
SSL_CERT_DIR: /etc/ssl/certs | ||
run: make all-with-ensurepip-dists-bundled -j4 | ||
- name: Display build info | ||
run: make pythoninfo | ||
- name: SSL tests | ||
|
@@ -421,6 +428,11 @@ jobs: | |
- name: Remount sources writable for tests | ||
# some tests write to srcdir, lack of pyc files slows down testing | ||
run: sudo mount $CPYTHON_RO_SRCDIR -oremount,rw | ||
- name: Bundle ensurepip dists | ||
env: | ||
SSL_CERT_DIR: /etc/ssl/certs | ||
run: make download-ensurepip-blobs | ||
working-directory: ${{ env.CPYTHON_BUILDDIR }} | ||
- name: Setup directory envs for out-of-tree builds | ||
run: | | ||
echo "CPYTHON_BUILDDIR=$(realpath -m ${GITHUB_WORKSPACE}/../cpython-builddir)" >> $GITHUB_ENV | ||
|
@@ -514,7 +526,9 @@ jobs: | |
- name: Configure CPython | ||
run: ./configure --config-cache --with-address-sanitizer --without-pymalloc | ||
- name: Build CPython | ||
run: make -j4 | ||
env: | ||
SSL_CERT_DIR: /etc/ssl/certs | ||
run: make all-with-ensurepip-dists-bundled -j4 | ||
- name: Display build info | ||
run: make pythoninfo | ||
- name: Tests | ||
|
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.