|
| 1 | +import distutils.version |
| 2 | +import glob |
1 | 3 | import os
|
2 | 4 | import os.path
|
3 | 5 | import sys
|
|
6 | 8 | import subprocess
|
7 | 9 | from importlib import resources
|
8 | 10 |
|
9 |
| -from . import _bundled |
10 |
| - |
11 | 11 |
|
12 | 12 |
|
13 | 13 | __all__ = ["version", "bootstrap"]
|
14 |
| -_SETUPTOOLS_VERSION = "58.1.0" |
15 |
| -_PIP_VERSION = "21.2.4" |
| 14 | + |
| 15 | +_WHEEL_DIR = "/usr/share/python-wheels/" |
| 16 | + |
| 17 | +_wheels = {} |
| 18 | + |
| 19 | +def _get_most_recent_wheel_version(pkg): |
| 20 | + prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg)) |
| 21 | + _wheels[pkg] = {} |
| 22 | + for suffix in "-py2.py3-none-any.whl", "-py3-none-any.whl": |
| 23 | + pattern = "{}*{}".format(prefix, suffix) |
| 24 | + for path in glob.glob(pattern): |
| 25 | + version_str = path[len(prefix):-len(suffix)] |
| 26 | + _wheels[pkg][version_str] = os.path.basename(path) |
| 27 | + return str(max(_wheels[pkg], key=distutils.version.LooseVersion)) |
| 28 | + |
| 29 | + |
| 30 | +_SETUPTOOLS_VERSION = _get_most_recent_wheel_version("setuptools") |
| 31 | + |
| 32 | +_PIP_VERSION = _get_most_recent_wheel_version("pip") |
| 33 | + |
16 | 34 | _PROJECTS = [
|
17 | 35 | ("setuptools", _SETUPTOOLS_VERSION, "py3"),
|
18 | 36 | ("pip", _PIP_VERSION, "py3"),
|
@@ -101,13 +119,10 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
|
101 | 119 | # additional paths that need added to sys.path
|
102 | 120 | additional_paths = []
|
103 | 121 | for project, version, py_tag in _PROJECTS:
|
104 |
| - wheel_name = "{}-{}-{}-none-any.whl".format(project, version, py_tag) |
105 |
| - whl = resources.read_binary( |
106 |
| - _bundled, |
107 |
| - wheel_name, |
108 |
| - ) |
109 |
| - with open(os.path.join(tmpdir, wheel_name), "wb") as fp: |
110 |
| - fp.write(whl) |
| 122 | + wheel_name = _wheels[project][version] |
| 123 | + with open(os.path.join(_WHEEL_DIR, wheel_name), "rb") as sfp: |
| 124 | + with open(os.path.join(tmpdir, wheel_name), "wb") as fp: |
| 125 | + fp.write(sfp.read()) |
111 | 126 |
|
112 | 127 | additional_paths.append(os.path.join(tmpdir, wheel_name))
|
113 | 128 |
|
|
0 commit comments