1 """Execute exactly this copy of pip, within a different environment.
3 This file is named as it is, to ensure that this module can't be imported via
7 # /!\ This version compatibility check section must be Python 2 compatible. /!\
11 # Copied from setup.py
12 PYTHON_REQUIRES
= (3, 7)
15 def version_str(version
): # type: ignore
16 return ".".join(str(v
) for v
in version
)
19 if sys
.version_info
[:2] < PYTHON_REQUIRES
:
21 "This version of pip does not support python {} (requires >={}).".format(
22 version_str(sys
.version_info
[:2]), version_str(PYTHON_REQUIRES
)
26 # From here on, we can use Python 3 features, but the syntax must remain
27 # Python 2 compatible.
29 import runpy
# noqa: E402
30 from importlib
.machinery
import PathFinder
# noqa: E402
31 from os
.path
import dirname
# noqa: E402
33 PIP_SOURCES_ROOT
= dirname(dirname(__file__
))
36 class PipImportRedirectingFinder
:
38 def find_spec(self
, fullname
, path
=None, target
=None): # type: ignore
42 spec
= PathFinder
.find_spec(fullname
, [PIP_SOURCES_ROOT
], target
)
43 assert spec
, (PIP_SOURCES_ROOT
, fullname
)
47 sys
.meta_path
.insert(0, PipImportRedirectingFinder())
49 assert __name__
== "__main__", "Cannot run __pip-runner__.py as a non-main module"
50 runpy
.run_module("pip", run_name
="__main__", alter_sys
=True)