churchyard / rpms / python3

Forked from rpms/python3 2 years ago
Clone
a26287
From 710cd909297d8e0291d37a4753b8e5a7965dc59f Mon Sep 17 00:00:00 2001
285f55
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
285f55
Date: Wed, 15 Aug 2018 15:36:29 +0200
29530b
Subject: [PATCH] 00189: Instead of bundled wheels, use our RPM packaged wheels
285f55
285f55
We keep them in /usr/share/python-wheels
285f55
---
285f55
 Lib/ensurepip/__init__.py | 26 +++++++++++++++++---------
285f55
 1 file changed, 17 insertions(+), 9 deletions(-)
285f55
0b241a
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
e702ad
index fc0edec6e3..4d17e413db 100644
0b241a
--- a/Lib/ensurepip/__init__.py
0b241a
+++ b/Lib/ensurepip/__init__.py
0b241a
@@ -1,16 +1,27 @@
0b241a
+import distutils.version
0b241a
+import glob
0b241a
 import os
0b241a
 import os.path
0b241a
-import pkgutil
0b241a
 import sys
0b241a
 import tempfile
0b241a
 
0b241a
 
0b241a
 __all__ = ["version", "bootstrap"]
0b241a
 
0b241a
+_WHEEL_DIR = "/usr/share/python-wheels/"
0b241a
 
e702ad
-_SETUPTOOLS_VERSION = "41.2.0"
0b241a
 
e702ad
-_PIP_VERSION = "19.2.3"
0b241a
+def _get_most_recent_wheel_version(pkg):
0b241a
+    prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg))
0b241a
+    suffix = "-py2.py3-none-any.whl"
0b241a
+    pattern = "{}*{}".format(prefix, suffix)
0b241a
+    versions = (p[len(prefix):-len(suffix)] for p in glob.glob(pattern))
0b241a
+    return str(max(versions, key=distutils.version.LooseVersion))
0b241a
+
0b241a
+
0b241a
+_SETUPTOOLS_VERSION = _get_most_recent_wheel_version("setuptools")
0b241a
+
0b241a
+_PIP_VERSION = _get_most_recent_wheel_version("pip")
0b241a
 
0b241a
 _PROJECTS = [
0b241a
     ("setuptools", _SETUPTOOLS_VERSION),
13257b
@@ -96,12 +107,9 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
0b241a
         additional_paths = []
0b241a
         for project, version in _PROJECTS:
0b241a
             wheel_name = "{}-{}-py2.py3-none-any.whl".format(project, version)
0b241a
-            whl = pkgutil.get_data(
0b241a
-                "ensurepip",
0b241a
-                "_bundled/{}".format(wheel_name),
0b241a
-            )
0b241a
-            with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
0b241a
-                fp.write(whl)
0b241a
+            with open(os.path.join(_WHEEL_DIR, wheel_name), "rb") as sfp:
0b241a
+                with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
0b241a
+                    fp.write(sfp.read())
0b241a
 
0b241a
             additional_paths.append(os.path.join(tmpdir, wheel_name))
0b241a
 
285f55
-- 
a26287
2.24.1
285f55