|
| 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 = "23.0.1" |
| 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"),
|
@@ -106,13 +124,10 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
|
106 | 124 | # additional paths that need added to sys.path
|
107 | 125 | additional_paths = []
|
108 | 126 | for project, version, py_tag in _PROJECTS:
|
109 |
| - wheel_name = "{}-{}-{}-none-any.whl".format(project, version, py_tag) |
110 |
| - whl = resources.read_binary( |
111 |
| - _bundled, |
112 |
| - wheel_name, |
113 |
| - ) |
114 |
| - with open(os.path.join(tmpdir, wheel_name), "wb") as fp: |
115 |
| - fp.write(whl) |
| 127 | + wheel_name = _wheels[project][version] |
| 128 | + with open(os.path.join(_WHEEL_DIR, wheel_name), "rb") as sfp: |
| 129 | + with open(os.path.join(tmpdir, wheel_name), "wb") as fp: |
| 130 | + fp.write(sfp.read()) |
116 | 131 |
|
117 | 132 | additional_paths.append(os.path.join(tmpdir, wheel_name))
|
118 | 133 |
|
|
0 commit comments