From 52df60a4a33fc27da39d51e31281e85d4e1d0f7d Mon Sep 17 00:00:00 2001 From: wim glenn Date: Sun, 11 Oct 2020 20:10:35 -0500 Subject: [PATCH] ensurepip uses importlib.resources traversable API --- Lib/ensurepip/__init__.py | 14 ++++---------- Lib/ensurepip/_bundled/__init__.py | 0 .../2020-10-11-20-23-48.bpo-37449.f-t3V6.rst | 1 + 3 files changed, 5 insertions(+), 10 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 cb2882e3360..f70e3a17a91 100644 --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -1,13 +1,10 @@ import os import os.path import sys -import runpy import tempfile import subprocess from importlib import resources -from . import _bundled - __all__ = ["version", "bootstrap"] @@ -24,8 +21,8 @@ _PROJECTS = [ 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""" @@ -106,12 +103,9 @@ def _bootstrap(*, root=None, upgrade=False, user=False, additional_paths = [] for project, version, py_tag in _PROJECTS: wheel_name = "{}-{}-{}-none-any.whl".format(project, version, py_tag) - whl = resources.read_binary( - _bundled, - wheel_name, - ) + whl = resources.files("ensurepip") / "_bundled" / wheel_name with open(os.path.join(tmpdir, wheel_name), "wb") as fp: - fp.write(whl) + fp.write(whl.read_bytes()) additional_paths.append(os.path.join(tmpdir, wheel_name)) diff --git a/Lib/ensurepip/_bundled/__init__.py b/Lib/ensurepip/_bundled/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 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 00000000000..360d301c6c9 --- /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