churchyard / rpms / python38

Forked from rpms/python38 2 years ago
Clone
ec69e79
From 2edaa31dec042fb8720add80814ca4a3cc4f788f Mon Sep 17 00:00:00 2001
7fd9466
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
7fd9466
Date: Wed, 15 Aug 2018 15:36:29 +0200
74db11e
Subject: [PATCH 4/7] 00189: Instead of bundled wheels, use our RPM packaged
7fd9466
 wheels
7fd9466
7fd9466
We keep them in /usr/share/python-wheels
7fd9466
---
7fd9466
 Lib/ensurepip/__init__.py | 26 +++++++++++++++++---------
7fd9466
 1 file changed, 17 insertions(+), 9 deletions(-)
7fd9466
0b241ab
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
ec69e79
index 6f2569da81..4d17e413db 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
 
6f3b5ba
-_SETUPTOOLS_VERSION = "40.8.0"
0b241ab
 
6f3b5ba
-_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),
ec69e79
@@ -96,12 +107,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
 
7fd9466
-- 
7fd9466
2.21.0
7fd9466