churchyard / rpms / python3

Forked from rpms/python3 6 years ago
Clone

Blame 00189-use-rpm-wheels.patch

c57c1e3
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
285f554
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
285f554
Date: Wed, 15 Aug 2018 15:36:29 +0200
29530ba
Subject: [PATCH] 00189: Instead of bundled wheels, use our RPM packaged wheels
285f554
285f554
We keep them in /usr/share/python-wheels
c57c1e3
c57c1e3
Downstream only: upstream bundles
c57c1e3
We might eventually pursuit upstream support, but it's low prio
285f554
---
66b21b9
 Lib/ensurepip/__init__.py | 32 ++++++++++++++++++++++----------
66b21b9
 1 file changed, 22 insertions(+), 10 deletions(-)
285f554
0b241ab
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
b74f7bb
index f3152a55d4..f58dab1800 100644
0b241ab
--- a/Lib/ensurepip/__init__.py
0b241ab
+++ b/Lib/ensurepip/__init__.py
43b44f1
@@ -1,6 +1,7 @@
0b241ab
+import distutils.version
0b241ab
+import glob
0b241ab
 import os
0b241ab
 import os.path
0b241ab
-import pkgutil
0b241ab
 import sys
43b44f1
 import runpy
0b241ab
 import tempfile
43b44f1
@@ -8,10 +9,24 @@ import tempfile
0b241ab
 
0b241ab
 __all__ = ["version", "bootstrap"]
0b241ab
 
0b241ab
+_WHEEL_DIR = "/usr/share/python-wheels/"
0b241ab
 
b74f7bb
-_SETUPTOOLS_VERSION = "47.1.0"
471a304
+_wheels = {}
0b241ab
 
b74f7bb
-_PIP_VERSION = "20.1.1"
0b241ab
+def _get_most_recent_wheel_version(pkg):
0b241ab
+    prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg))
471a304
+    _wheels[pkg] = {}
471a304
+    for suffix in "-py2.py3-none-any.whl", "-py3-none-any.whl":
471a304
+        pattern = "{}*{}".format(prefix, suffix)
471a304
+        for path in glob.glob(pattern):
471a304
+            version_str = path[len(prefix):-len(suffix)]
471a304
+            _wheels[pkg][version_str] = os.path.basename(path)
471a304
+    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 = [
b74f7bb
     ("setuptools", _SETUPTOOLS_VERSION, "py3"),
43b44f1
@@ -105,13 +120,10 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
471a304
         # additional paths that need added to sys.path
0b241ab
         additional_paths = []
b74f7bb
         for project, version, py_tag in _PROJECTS:
b74f7bb
-            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)
471a304
+            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