Blame SOURCES/00189-use-rpm-wheels.patch

b7e076
diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py
b7e076
index 09c572d..167d27b 100644
b7e076
--- a/Lib/ensurepip/__init__.py
b7e076
+++ b/Lib/ensurepip/__init__.py
b7e076
@@ -1,16 +1,27 @@
b7e076
+import distutils.version
b7e076
+import glob
b7e076
 import os
b7e076
 import os.path
b7e076
-import pkgutil
b7e076
 import sys
b7e076
 import tempfile
b7e076
 
b7e076
 
b7e076
 __all__ = ["version", "bootstrap"]
b7e076
 
b7e076
+_WHEEL_DIR = "/usr/share/python{}-wheels/".format(sys.version_info[0])
b7e076
 
b7e076
-_SETUPTOOLS_VERSION = "40.6.2"
b7e076
+def _get_most_recent_wheel_version(pkg):
b7e076
+    prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg))
b7e076
+    suffix = "-py2.py3-none-any.whl"
b7e076
+    pattern = "{}*{}".format(prefix, suffix)
b7e076
+    versions = (p[len(prefix):-len(suffix)] for p in glob.glob(pattern))
b7e076
+    return str(max(versions, key=distutils.version.LooseVersion))
b7e076
+
b7e076
+
b7e076
+_SETUPTOOLS_VERSION = _get_most_recent_wheel_version("setuptools")
b7e076
+
b7e076
+_PIP_VERSION = _get_most_recent_wheel_version("pip")
b7e076
 
b7e076
-_PIP_VERSION = "18.1"
b7e076
 
b7e076
 _PROJECTS = [
b7e076
     ("setuptools", _SETUPTOOLS_VERSION),
b7e076
@@ -23,9 +34,15 @@ def _run_pip(args, additional_paths=None):
b7e076
     if additional_paths is not None:
b7e076
         sys.path = additional_paths + sys.path
b7e076
 
b7e076
-    # Install the bundled software
b7e076
-    import pip._internal
b7e076
-    return pip._internal.main(args)
b7e076
+    try:
b7e076
+        # pip 10
b7e076
+        from pip._internal import main
b7e076
+    except ImportError:
b7e076
+        # pip 9
b7e076
+        from pip import main
b7e076
+    if args[0] in ["install", "list", "wheel"]:
b7e076
+        args.append('--pre')
b7e076
+    return main(args)
b7e076
 
b7e076
 
b7e076
 def version():
b7e076
@@ -94,12 +111,9 @@ def _bootstrap(*, root=None, upgrade=False, user=False,
b7e076
         additional_paths = []
b7e076
         for project, version in _PROJECTS:
b7e076
             wheel_name = "{}-{}-py2.py3-none-any.whl".format(project, version)
b7e076
-            whl = pkgutil.get_data(
b7e076
-                "ensurepip",
b7e076
-                "_bundled/{}".format(wheel_name),
b7e076
-            )
b7e076
-            with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
b7e076
-                fp.write(whl)
b7e076
+            with open(os.path.join(_WHEEL_DIR, wheel_name), "rb") as sfp:
b7e076
+                with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
b7e076
+                    fp.write(sfp.read())
b7e076
 
b7e076
             additional_paths.append(os.path.join(tmpdir, wheel_name))
b7e076