Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.3k
GH-80789: Get rid of theensurepip
infra for many wheels#109245
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
c32777f
d6e51b2
5c3bd26
96b8b9e
7b04736
f3a49c2
3d7ee78
72b8ebe
0d94ec9
5c97cda
bce6e3a
50efc2a
865c41f
2472d87
da1ae79
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,64 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
import sysconfig | ||
import tempfile | ||
from contextlib import nullcontext | ||
from importlib import resources | ||
from pathlib import Path | ||
from shutil import copy2 | ||
__all__ = ["version", "bootstrap"] | ||
_PIP_VERSION = "23.3.2" | ||
# Directory of system wheel packages. Some Linux distribution packaging | ||
# policies recommend against bundling dependencies. For example, Fedora | ||
# installs wheel packages in the /usr/share/python-wheels/ directory and don't | ||
# install the ensurepip._bundled package. | ||
if (_pkg_dir := sysconfig.get_config_var('WHEEL_PKG_DIR')) is not None: | ||
_WHEEL_PKG_DIR = Path(_pkg_dir).resolve() | ||
else: | ||
_WHEEL_PKG_DIR = None | ||
pradyunsg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
def _find_wheel_pkg_dir_pip(): | ||
webknjaz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if _WHEEL_PKG_DIR is None: | ||
# NOTE: The compile-time `WHEEL_PKG_DIR` is unset so there is no place | ||
# NOTE: for looking up the wheels. | ||
return None | ||
dist_matching_wheels = _WHEEL_PKG_DIR.glob('pip-*.whl') | ||
try: | ||
last_matching_dist_wheel = sorted(dist_matching_wheels)[-1] | ||
except IndexError: | ||
# NOTE: `WHEEL_PKG_DIR` does not contain any wheel files for `pip`. | ||
return None | ||
webknjaz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return nullcontext(last_matching_dist_wheel) | ||
def _get_pip_whl_path_ctx(): | ||
# Prefer pip from the wheel package directory, if present. | ||
if (alternative_pip_wheel_path := _find_wheel_pkg_dir_pip()) is not None: | ||
return alternative_pip_wheel_path | ||
return resources.as_file( | ||
resources.files('ensurepip') | ||
/ '_bundled' | ||
/ f'pip-{_PIP_VERSION}-py3-none-any.whl' | ||
) | ||
def _get_pip_version(): | ||
pradyunsg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
with _get_pip_whl_path_ctx() as bundled_wheel_path: | ||
wheel_name = bundled_wheel_path.name | ||
return ( | ||
# Extract '21.2.4' from 'pip-21.2.4-py3-none-any.whl' | ||
wheel_name. | ||
removeprefix('pip-'). | ||
partition('-')[0] | ||
) | ||
def _run_pip(args, additional_paths=None): | ||
@@ -105,7 +91,7 @@ def version(): | ||
""" | ||
Returns a string specifying the bundled version of pip. | ||
""" | ||
return_get_pip_version() | ||
pradyunsg marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
def _disable_pip_configuration_settings(): | ||
@@ -167,24 +153,10 @@ def _bootstrap(*, root=None, upgrade=False, user=False, | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
# Put our bundled wheels into a temporary directory and construct the | ||
# additional paths that need added to sys.path | ||
tmpdir_path = Path(tmpdir) | ||
with _get_pip_whl_path_ctx() as bundled_wheel_path: | ||
tmp_wheel_path = tmpdir_path / bundled_wheel_path.name | ||
copy2(bundled_wheel_path, tmp_wheel_path) | ||
# Construct the arguments to be passed to the pip command | ||
args = ["install", "--no-cache-dir", "--no-index", "--find-links", tmpdir] | ||
@@ -197,7 +169,8 @@ def _bootstrap(*, root=None, upgrade=False, user=False, | ||
if verbosity: | ||
args += ["-" + "v" * verbosity] | ||
return _run_pip([*args, "pip"], [os.fsdecode(tmp_wheel_path)]) | ||
def _uninstall_helper(*, verbosity=0): | ||
"""Helper to support a clean default uninstall process on Windows | ||
@@ -227,7 +200,7 @@ def _uninstall_helper(*, verbosity=0): | ||
if verbosity: | ||
args += ["-" + "v" * verbosity] | ||
return _run_pip([*args,"pip"]) | ||
def _main(argv=None): | ||