|
4 | 4 | an import statement.
|
5 | 5 | """
|
6 | 6 |
|
7 |
| -import runpy |
| 7 | +# /!\ This version compatibility check section must be Python 2 compatible. /!\ |
| 8 | + |
8 | 9 | import sys
|
9 |
| -import types |
10 |
| -from importlib.machinery import ModuleSpec, PathFinder |
11 |
| -from os.path import dirname |
12 |
| -from typing import Optional, Sequence, Union |
| 10 | + |
| 11 | +# Copied from setup.py |
| 12 | +PYTHON_REQUIRES = (3, 7) |
| 13 | + |
| 14 | + |
| 15 | +def version_str(version): # type: ignore |
| 16 | + return ".".join(str(v) for v in version) |
| 17 | + |
| 18 | + |
| 19 | +if sys.version_info[:2] < PYTHON_REQUIRES: |
| 20 | + raise SystemExit( |
| 21 | + "This version of pip does not support python {} (requires >={}).".format( |
| 22 | + version_str(sys.version_info[:2]), version_str(PYTHON_REQUIRES) |
| 23 | + ) |
| 24 | + ) |
| 25 | + |
| 26 | +# From here on, we can use Python 3 features, but the syntax must remain |
| 27 | +# Python 2 compatible. |
| 28 | + |
| 29 | +import runpy # noqa: E402 |
| 30 | +from importlib.machinery import PathFinder # noqa: E402 |
| 31 | +from os.path import dirname # noqa: E402 |
13 | 32 |
|
14 | 33 | PIP_SOURCES_ROOT = dirname(dirname(__file__))
|
15 | 34 |
|
16 | 35 |
|
17 | 36 | class PipImportRedirectingFinder:
|
18 | 37 | @classmethod
|
19 |
| - def find_spec( |
20 |
| - self, |
21 |
| - fullname: str, |
22 |
| - path: Optional[Sequence[Union[bytes, str]]] = None, |
23 |
| - target: Optional[types.ModuleType] = None, |
24 |
| - ) -> Optional[ModuleSpec]: |
| 38 | + def find_spec(self, fullname, path=None, target=None): # type: ignore |
25 | 39 | if fullname != "pip":
|
26 | 40 | return None
|
27 | 41 |
|
|
0 commit comments