ensurepip uses importlib.resources traversable API

This commit is contained in:
wim glenn 2020-10-11 20:10:35 -05:00
parent 13ff396c01
commit 52df60a4a3
No known key found for this signature in database
GPG Key ID: C127F552CFFFC6DE
3 changed files with 5 additions and 10 deletions

View File

@ -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))

View File

@ -0,0 +1 @@
`ensurepip` now uses `importlib.resources.files()` traversable APIs