churchyard / rpms / python3

Forked from rpms/python3 6 years ago
Clone

Blame 00189-use-rpm-wheels.patch

bae5e50
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
256657e
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
256657e
Date: Wed, 15 Aug 2018 15:36:29 +0200
256657e
Subject: [PATCH] 00189: Instead of bundled wheels, use our RPM packaged wheels
256657e
256657e
We keep them in /usr/share/python-wheels
256657e
---
256657e
 Lib/ensurepip/__init__.py | 31 ++++++++++++++++++++++---------
256657e
 1 file changed, 22 insertions(+), 9 deletions(-)
256657e
0b241ab
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
256657e
index 94d40b0c8d..87d262814e 100644
0b241ab
--- a/Lib/ensurepip/__init__.py
0b241ab
+++ b/Lib/ensurepip/__init__.py
256657e
@@ -1,3 +1,5 @@
0b241ab
+import distutils.version
0b241ab
+import glob
0b241ab
 import os
0b241ab
 import os.path
256657e
 import pkgutil
256657e
@@ -8,10 +10,24 @@ import tempfile
0b241ab
 
0b241ab
 __all__ = ["version", "bootstrap"]
0b241ab
 
0b241ab
+_WHEEL_DIR = "/usr/share/python-wheels/"
0b241ab
 
256657e
-_SETUPTOOLS_VERSION = "47.1.0"
0540736
+_wheels = {}
0b241ab
 
256657e
-_PIP_VERSION = "20.1.1"
0b241ab
+def _get_most_recent_wheel_version(pkg):
0b241ab
+    prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg))
0540736
+    _wheels[pkg] = {}
0540736
+    for suffix in "-py2.py3-none-any.whl", "-py3-none-any.whl":
0540736
+        pattern = "{}*{}".format(prefix, suffix)
0540736
+        for path in glob.glob(pattern):
0540736
+            version_str = path[len(prefix):-len(suffix)]
0540736
+            _wheels[pkg][version_str] = os.path.basename(path)
0540736
+    return str(max(_wheels[pkg], 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 = [
256657e
     ("setuptools", _SETUPTOOLS_VERSION, "py3"),
256657e
@@ -103,13 +119,10 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
256657e
         # additional paths that need added to sys.path
0b241ab
         additional_paths = []
256657e
         for project, version, py_tag in _PROJECTS:
256657e
-            wheel_name = "{}-{}-{}-none-any.whl".format(project, version, py_tag)
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)
0540736
+            wheel_name = _wheels[project][version]
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