churchyard / rpms / python3

Forked from rpms/python3 4 years ago
Clone

Blame 00189-use-rpm-wheels.patch

0b241ab
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
0b241ab
index 4748ba4..fc02255 100644
0b241ab
--- a/Lib/ensurepip/__init__.py
0b241ab
+++ b/Lib/ensurepip/__init__.py
0b241ab
@@ -1,16 +1,27 @@
0b241ab
+import distutils.version
0b241ab
+import glob
0b241ab
 import os
0b241ab
 import os.path
0b241ab
-import pkgutil
0b241ab
 import sys
0b241ab
 import tempfile
0b241ab
 
0b241ab
 
0b241ab
 __all__ = ["version", "bootstrap"]
0b241ab
 
0b241ab
+_WHEEL_DIR = "/usr/share/python-wheels/"
0b241ab
 
804ec7c
-_SETUPTOOLS_VERSION = "40.8.0"
0b241ab
 
804ec7c
-_PIP_VERSION = "19.0.3"
0b241ab
+def _get_most_recent_wheel_version(pkg):
0b241ab
+    prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg))
0b241ab
+    suffix = "-py2.py3-none-any.whl"
0b241ab
+    pattern = "{}*{}".format(prefix, suffix)
0b241ab
+    versions = (p[len(prefix):-len(suffix)] for p in glob.glob(pattern))
0b241ab
+    return str(max(versions, key=distutils.version.LooseVersion))
0b241ab
+
0b241ab
+
0b241ab
+_SETUPTOOLS_VERSION = _get_most_recent_wheel_version("setuptools")
0b241ab
+
0b241ab
+_PIP_VERSION = _get_most_recent_wheel_version("pip")
0b241ab
 
0b241ab
 _PROJECTS = [
0b241ab
     ("setuptools", _SETUPTOOLS_VERSION),
0b241ab
@@ -94,12 +105,9 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
0b241ab
         additional_paths = []
0b241ab
         for project, version in _PROJECTS:
0b241ab
             wheel_name = "{}-{}-py2.py3-none-any.whl".format(project, version)
0b241ab
-            whl = pkgutil.get_data(
0b241ab
-                "ensurepip",
0b241ab
-                "_bundled/{}".format(wheel_name),
0b241ab
-            )
0b241ab
-            with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
0b241ab
-                fp.write(whl)
0b241ab
+            with open(os.path.join(_WHEEL_DIR, wheel_name), "rb") as sfp:
0b241ab
+                with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
0b241ab
+                    fp.write(sfp.read())
0b241ab
 
0b241ab
             additional_paths.append(os.path.join(tmpdir, wheel_name))
0b241ab