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