|
|
5b97503 |
diff --git a/lib-python/2.7/ensurepip/__init__.py b/lib-python/2.7/ensurepip/__init__.py
|
|
|
0fdc213 |
index 78ffd23..225c90a 100644
|
|
|
5b97503 |
--- a/lib-python/2.7/ensurepip/__init__.py
|
|
|
5b97503 |
+++ b/lib-python/2.7/ensurepip/__init__.py
|
|
|
0fdc213 |
@@ -1,11 +1,14 @@
|
|
|
5b97503 |
#!/usr/bin/env python2
|
|
|
5b97503 |
from __future__ import print_function
|
|
|
5b97503 |
|
|
|
5b97503 |
+import distutils.version
|
|
|
5b97503 |
+import glob
|
|
|
5b97503 |
import os
|
|
|
5b97503 |
import os.path
|
|
|
0fdc213 |
import pkgutil
|
|
|
5b97503 |
import shutil
|
|
|
5b97503 |
import sys
|
|
|
0fdc213 |
+import runpy
|
|
|
5b97503 |
import tempfile
|
|
|
0fdc213 |
import warnings
|
|
|
5b97503 |
|
|
|
0fdc213 |
@@ -13,9 +16,24 @@ import warnings
|
|
|
5b97503 |
__all__ = ["version", "bootstrap"]
|
|
|
5b97503 |
|
|
|
5b97503 |
|
|
|
0fdc213 |
-_SETUPTOOLS_VERSION = "44.0.0"
|
|
|
0fdc213 |
+_WHEEL_DIR = "/usr/share/python-wheels/"
|
|
|
5b97503 |
|
|
|
0fdc213 |
-_PIP_VERSION = "20.0.2"
|
|
|
0fdc213 |
+_wheels = {}
|
|
|
0fdc213 |
+
|
|
|
5b97503 |
+def _get_most_recent_wheel_version(pkg):
|
|
|
5b97503 |
+ prefix = os.path.join(_WHEEL_DIR, "{}-".format(pkg))
|
|
|
0fdc213 |
+ _wheels[pkg] = {}
|
|
|
0fdc213 |
+ for suffix in "-py2.py3-none-any.whl", "-py3-none-any.whl":
|
|
|
0fdc213 |
+ pattern = "{}*{}".format(prefix, suffix)
|
|
|
0fdc213 |
+ for path in glob.glob(pattern):
|
|
|
0fdc213 |
+ version_str = path[len(prefix):-len(suffix)]
|
|
|
0fdc213 |
+ _wheels[pkg][version_str] = os.path.basename(path)
|
|
|
0fdc213 |
+ return str(max(_wheels[pkg], key=distutils.version.LooseVersion))
|
|
|
5b97503 |
+
|
|
|
5b97503 |
+
|
|
|
5b97503 |
+_SETUPTOOLS_VERSION = _get_most_recent_wheel_version("setuptools")
|
|
|
5b97503 |
+
|
|
|
5b97503 |
+_PIP_VERSION = _get_most_recent_wheel_version("pip")
|
|
|
5b97503 |
|
|
|
5b97503 |
_PROJECTS = [
|
|
|
5b97503 |
("setuptools", _SETUPTOOLS_VERSION),
|
|
|
0fdc213 |
@@ -28,13 +46,18 @@ def _run_pip(args, additional_paths=None):
|
|
|
0fdc213 |
if additional_paths is not None:
|
|
|
0fdc213 |
sys.path = additional_paths + sys.path
|
|
|
0fdc213 |
|
|
|
0fdc213 |
- # Install the bundled pip, filtering the PipDeprecationWarning
|
|
|
0fdc213 |
- import pip._internal.cli.main
|
|
|
0fdc213 |
- from pip._internal.utils.deprecation import PipDeprecationWarning
|
|
|
0fdc213 |
- with warnings.catch_warnings():
|
|
|
0fdc213 |
- warnings.filterwarnings('ignore', category=PipDeprecationWarning)
|
|
|
0fdc213 |
- return pip._internal.cli.main.main(args)
|
|
|
0fdc213 |
+ # Invoke pip as if it's the main module, and catch the exit.
|
|
|
0fdc213 |
+ backup_argv = sys.argv[:]
|
|
|
0fdc213 |
+ sys.argv[1:] = args
|
|
|
0fdc213 |
+ try:
|
|
|
0fdc213 |
+ # run_module() alters sys.modules and sys.argv, but restores them at exit
|
|
|
0fdc213 |
+ runpy.run_module("pip", run_name="__main__", alter_sys=True)
|
|
|
0fdc213 |
+ except SystemExit as exc:
|
|
|
0fdc213 |
+ return exc.code
|
|
|
0fdc213 |
+ finally:
|
|
|
0fdc213 |
+ sys.argv[:] = backup_argv
|
|
|
0fdc213 |
|
|
|
0fdc213 |
+ raise SystemError("pip did not exit, this should never happen")
|
|
|
0fdc213 |
|
|
|
0fdc213 |
def version():
|
|
|
0fdc213 |
"""
|
|
|
0fdc213 |
@@ -88,13 +111,10 @@ def bootstrap(root=None, upgrade=False, user=False,
|
|
|
0fdc213 |
# additional paths that need added to sys.path
|
|
|
5b97503 |
additional_paths = []
|
|
|
5b97503 |
for project, version in _PROJECTS:
|
|
|
0fdc213 |
- wheel_name = "{}-{}-py2.py3-none-any.whl".format(project, version)
|
|
|
5b97503 |
- whl = pkgutil.get_data(
|
|
|
5b97503 |
- "ensurepip",
|
|
|
5b97503 |
- "_bundled/{}".format(wheel_name),
|
|
|
5b97503 |
- )
|
|
|
5b97503 |
- with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
|
|
|
5b97503 |
- fp.write(whl)
|
|
|
0fdc213 |
+ wheel_name = _wheels[project][version]
|
|
|
5b97503 |
+ with open(os.path.join(_WHEEL_DIR, wheel_name), "rb") as sfp:
|
|
|
5b97503 |
+ with open(os.path.join(tmpdir, wheel_name), "wb") as fp:
|
|
|
5b97503 |
+ fp.write(sfp.read())
|
|
|
5b97503 |
|
|
|
5b97503 |
additional_paths.append(os.path.join(tmpdir, wheel_name))
|
|
|
5b97503 |
|