From 84b20b319277809579614cbee88dedbd7b230d0f Mon Sep 17 00:00:00 2001 From: wim glenn Date: Sat, 15 May 2021 23:32:31 -0500 Subject: [PATCH 1/3] `ensurepip` now uses `importlib.resources.files()` traversable APIs --- Lib/ensurepip/__init__.py | 10 +++++----- Lib/ensurepip/_bundled/__init__.py | 0 .../Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) delete mode 100644 Lib/ensurepip/_bundled/__init__.py create mode 100644 Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index 4c606b9f2a89b8..b31877ea50fbef 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -8,7 +8,6 @@ from importlib import resources - __all__ = ["version", "bootstrap"] _PACKAGE_NAMES = ('setuptools', 'pip') _SETUPTOOLS_VERSION = "56.0.0" @@ -79,8 +78,8 @@ def _get_packages(): def _run_pip(args, additional_paths=None): - # Run the bootstraping in a subprocess to avoid leaking any state that happens - # after pip has executed. Particulary, this avoids the case when pip holds onto + # Run the bootstrapping in a subprocess to avoid leaking any state that happens + # after pip has executed. Particularly, this avoids the case when pip holds onto # the files in *additional_paths*, preventing us to remove them at the end of the # invocation. code = f""" @@ -164,9 +163,10 @@ def _bootstrap(*, root=None, upgrade=False, user=False, for name, package in _get_packages().items(): if package.wheel_name: # Use bundled wheel package - from ensurepip import _bundled wheel_name = package.wheel_name - whl = resources.read_binary(_bundled, wheel_name) + wheel_path = resources.files("ensurepip") / "_bundled" / wheel_name + with wheel_path.open("rb") as fp: + whl = fp.read() else: # Use the wheel package directory with open(package.wheel_path, "rb") as fp: diff --git a/Lib/ensurepip/_bundled/__init__.py b/Lib/ensurepip/_bundled/__init__.py deleted file mode 100644 index e69de29bb2d1d6..00000000000000 diff --git a/Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst b/Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst new file mode 100644 index 00000000000000..360d301c6c9c33 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst @@ -0,0 +1 @@ +`ensurepip` now uses `importlib.resources.files()` traversable APIs From 039e3152ffb07b10558a54be55bd4237f9b8d59f Mon Sep 17 00:00:00 2001 From: wim glenn Date: Sun, 6 Jun 2021 20:31:49 -0500 Subject: [PATCH 2/3] Update Lib/ensurepip/__init__.py Co-authored-by: Jason R. Coombs --- Lib/ensurepip/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py index b31877ea50fbef..834fc6bdc64b35 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -165,8 +165,7 @@ def _bootstrap(*, root=None, upgrade=False, user=False, # Use bundled wheel package wheel_name = package.wheel_name wheel_path = resources.files("ensurepip") / "_bundled" / wheel_name - with wheel_path.open("rb") as fp: - whl = fp.read() + whl = wheel_path.read_bytes() else: # Use the wheel package directory with open(package.wheel_path, "rb") as fp: From f9f91b92d12cc8c14d03c79e4e55bb7e9c09cb6b Mon Sep 17 00:00:00 2001 From: wim glenn Date: Sun, 6 Jun 2021 20:31:55 -0500 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst Co-authored-by: Jason R. Coombs --- .../next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst b/Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst index 360d301c6c9c33..2202ae0a9ac969 100644 --- a/Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst +++ b/Misc/NEWS.d/next/Library/2020-10-11-20-23-48.bpo-37449.f-t3V6.rst @@ -1 +1 @@ -`ensurepip` now uses `importlib.resources.files()` traversable APIs +``ensurepip`` now uses ``importlib.resources.files()`` traversable APIs