ensurepip uses importlib.resources traversable API
This commit is contained in:
parent
13ff396c01
commit
52df60a4a3
|
@ -1,13 +1,10 @@
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import runpy
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
from importlib import resources
|
from importlib import resources
|
||||||
|
|
||||||
from . import _bundled
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["version", "bootstrap"]
|
__all__ = ["version", "bootstrap"]
|
||||||
|
@ -24,8 +21,8 @@ _PROJECTS = [
|
||||||
|
|
||||||
|
|
||||||
def _run_pip(args, additional_paths=None):
|
def _run_pip(args, additional_paths=None):
|
||||||
# Run the bootstraping in a subprocess to avoid leaking any state that happens
|
# Run the bootstrapping in a subprocess to avoid leaking any state that happens
|
||||||
# after pip has executed. Particulary, this avoids the case when pip holds onto
|
# 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
|
# the files in *additional_paths*, preventing us to remove them at the end of the
|
||||||
# invocation.
|
# invocation.
|
||||||
code = f"""
|
code = f"""
|
||||||
|
@ -106,12 +103,9 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
|
||||||
additional_paths = []
|
additional_paths = []
|
||||||
for project, version, py_tag in _PROJECTS:
|
for project, version, py_tag in _PROJECTS:
|
||||||
wheel_name = "{}-{}-{}-none-any.whl".format(project, version, py_tag)
|
wheel_name = "{}-{}-{}-none-any.whl".format(project, version, py_tag)
|
||||||
whl = resources.read_binary(
|
whl = resources.files("ensurepip") / "_bundled" / wheel_name
|
||||||
_bundled,
|
|
||||||
wheel_name,
|
|
||||||
)
|
|
||||||
with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
|
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))
|
additional_paths.append(os.path.join(tmpdir, wheel_name))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
`ensurepip` now uses `importlib.resources.files()` traversable APIs
|
Loading…
Reference in New Issue