Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- scripts/myenv/lib/python3.10/site-packages/pip/__init__.py +13 -0
- scripts/myenv/lib/python3.10/site-packages/pip/__main__.py +31 -0
- scripts/myenv/lib/python3.10/site-packages/pip/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/__pycache__/__main__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__init__.py +19 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/build_env.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/cache.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/configuration.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/exceptions.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/main.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/pyproject.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/self_outdated_check.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/wheel_builder.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/build_env.py +296 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/cache.py +264 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/__init__.py +4 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/main.py +70 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/progress_bars.py +321 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py +506 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/spinners.py +157 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/status_codes.py +6 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/configuration.py +366 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/exceptions.py +658 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__init__.py +520 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_distutils.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_sysconfig.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/base.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/_distutils.py +169 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/_sysconfig.py +219 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/base.py +52 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/main.py +12 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/pyproject.py +168 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/__pycache__/base.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/base.py +20 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/legacy/__init__.py +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/legacy/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/legacy/resolver.py +467 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__init__.py +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/__init__.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/base.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/candidates.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/found_candidates.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/provider.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/reporter.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/requirements.cpython-310.pyc +0 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/reporter.py +68 -0
- scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/requirements.py +166 -0
scripts/myenv/lib/python3.10/site-packages/pip/__init__.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Optional
|
2 |
+
|
3 |
+
__version__ = "22.0.2"
|
4 |
+
|
5 |
+
|
6 |
+
def main(args: Optional[List[str]] = None) -> int:
|
7 |
+
"""This is an internal API only meant for use by pip's own console scripts.
|
8 |
+
|
9 |
+
For additional details, see https://github.com/pypa/pip/issues/7498.
|
10 |
+
"""
|
11 |
+
from pip._internal.utils.entrypoints import _wrapper
|
12 |
+
|
13 |
+
return _wrapper(args)
|
scripts/myenv/lib/python3.10/site-packages/pip/__main__.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import warnings
|
4 |
+
|
5 |
+
# Remove '' and current working directory from the first entry
|
6 |
+
# of sys.path, if present to avoid using current directory
|
7 |
+
# in pip commands check, freeze, install, list and show,
|
8 |
+
# when invoked as python -m pip <command>
|
9 |
+
if sys.path[0] in ("", os.getcwd()):
|
10 |
+
sys.path.pop(0)
|
11 |
+
|
12 |
+
# If we are running from a wheel, add the wheel to sys.path
|
13 |
+
# This allows the usage python pip-*.whl/pip install pip-*.whl
|
14 |
+
if __package__ == "":
|
15 |
+
# __file__ is pip-*.whl/pip/__main__.py
|
16 |
+
# first dirname call strips of '/__main__.py', second strips off '/pip'
|
17 |
+
# Resulting path is the name of the wheel itself
|
18 |
+
# Add that to sys.path so we can import pip
|
19 |
+
path = os.path.dirname(os.path.dirname(__file__))
|
20 |
+
sys.path.insert(0, path)
|
21 |
+
|
22 |
+
if __name__ == "__main__":
|
23 |
+
# Work around the error reported in #9540, pending a proper fix.
|
24 |
+
# Note: It is essential the warning filter is set *before* importing
|
25 |
+
# pip, as the deprecation happens at import time, not runtime.
|
26 |
+
warnings.filterwarnings(
|
27 |
+
"ignore", category=DeprecationWarning, module=".*packaging\\.version"
|
28 |
+
)
|
29 |
+
from pip._internal.cli.main import main as _main
|
30 |
+
|
31 |
+
sys.exit(_main())
|
scripts/myenv/lib/python3.10/site-packages/pip/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (634 Bytes). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/__pycache__/__main__.cpython-310.pyc
ADDED
Binary file (596 Bytes). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__init__.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Optional
|
2 |
+
|
3 |
+
import pip._internal.utils.inject_securetransport # noqa
|
4 |
+
from pip._internal.utils import _log
|
5 |
+
|
6 |
+
# init_logging() must be called before any call to logging.getLogger()
|
7 |
+
# which happens at import of most modules.
|
8 |
+
_log.init_logging()
|
9 |
+
|
10 |
+
|
11 |
+
def main(args: (Optional[List[str]]) = None) -> int:
|
12 |
+
"""This is preserved for old console scripts that may still be referencing
|
13 |
+
it.
|
14 |
+
|
15 |
+
For additional details, see https://github.com/pypa/pip/issues/7498.
|
16 |
+
"""
|
17 |
+
from pip._internal.utils.entrypoints import _wrapper
|
18 |
+
|
19 |
+
return _wrapper(args)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (755 Bytes). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/build_env.cpython-310.pyc
ADDED
Binary file (9.6 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/cache.cpython-310.pyc
ADDED
Binary file (8.38 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/configuration.cpython-310.pyc
ADDED
Binary file (11.1 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/exceptions.cpython-310.pyc
ADDED
Binary file (23.1 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/main.cpython-310.pyc
ADDED
Binary file (620 Bytes). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/pyproject.cpython-310.pyc
ADDED
Binary file (3.54 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/self_outdated_check.cpython-310.pyc
ADDED
Binary file (4.58 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/__pycache__/wheel_builder.cpython-310.pyc
ADDED
Binary file (9.14 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/build_env.py
ADDED
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Build Environment used for isolation during sdist building
|
2 |
+
"""
|
3 |
+
|
4 |
+
import contextlib
|
5 |
+
import logging
|
6 |
+
import os
|
7 |
+
import pathlib
|
8 |
+
import sys
|
9 |
+
import textwrap
|
10 |
+
import zipfile
|
11 |
+
from collections import OrderedDict
|
12 |
+
from sysconfig import get_paths
|
13 |
+
from types import TracebackType
|
14 |
+
from typing import TYPE_CHECKING, Iterable, Iterator, List, Optional, Set, Tuple, Type
|
15 |
+
|
16 |
+
from pip._vendor.certifi import where
|
17 |
+
from pip._vendor.packaging.requirements import Requirement
|
18 |
+
from pip._vendor.packaging.version import Version
|
19 |
+
|
20 |
+
from pip import __file__ as pip_location
|
21 |
+
from pip._internal.cli.spinners import open_spinner
|
22 |
+
from pip._internal.locations import get_platlib, get_prefixed_libs, get_purelib
|
23 |
+
from pip._internal.metadata import get_environment
|
24 |
+
from pip._internal.utils.subprocess import call_subprocess
|
25 |
+
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
26 |
+
|
27 |
+
if TYPE_CHECKING:
|
28 |
+
from pip._internal.index.package_finder import PackageFinder
|
29 |
+
|
30 |
+
logger = logging.getLogger(__name__)
|
31 |
+
|
32 |
+
|
33 |
+
class _Prefix:
|
34 |
+
def __init__(self, path: str) -> None:
|
35 |
+
self.path = path
|
36 |
+
self.setup = False
|
37 |
+
self.bin_dir = get_paths(
|
38 |
+
"nt" if os.name == "nt" else "posix_prefix",
|
39 |
+
vars={"base": path, "platbase": path},
|
40 |
+
)["scripts"]
|
41 |
+
self.lib_dirs = get_prefixed_libs(path)
|
42 |
+
|
43 |
+
|
44 |
+
@contextlib.contextmanager
|
45 |
+
def _create_standalone_pip() -> Iterator[str]:
|
46 |
+
"""Create a "standalone pip" zip file.
|
47 |
+
|
48 |
+
The zip file's content is identical to the currently-running pip.
|
49 |
+
It will be used to install requirements into the build environment.
|
50 |
+
"""
|
51 |
+
source = pathlib.Path(pip_location).resolve().parent
|
52 |
+
|
53 |
+
# Return the current instance if `source` is not a directory. We can't build
|
54 |
+
# a zip from this, and it likely means the instance is already standalone.
|
55 |
+
if not source.is_dir():
|
56 |
+
yield str(source)
|
57 |
+
return
|
58 |
+
|
59 |
+
with TempDirectory(kind="standalone-pip") as tmp_dir:
|
60 |
+
pip_zip = os.path.join(tmp_dir.path, "__env_pip__.zip")
|
61 |
+
kwargs = {}
|
62 |
+
if sys.version_info >= (3, 8):
|
63 |
+
kwargs["strict_timestamps"] = False
|
64 |
+
with zipfile.ZipFile(pip_zip, "w", **kwargs) as zf:
|
65 |
+
for child in source.rglob("*"):
|
66 |
+
zf.write(child, child.relative_to(source.parent).as_posix())
|
67 |
+
yield os.path.join(pip_zip, "pip")
|
68 |
+
|
69 |
+
|
70 |
+
class BuildEnvironment:
|
71 |
+
"""Creates and manages an isolated environment to install build deps"""
|
72 |
+
|
73 |
+
def __init__(self) -> None:
|
74 |
+
temp_dir = TempDirectory(kind=tempdir_kinds.BUILD_ENV, globally_managed=True)
|
75 |
+
|
76 |
+
self._prefixes = OrderedDict(
|
77 |
+
(name, _Prefix(os.path.join(temp_dir.path, name)))
|
78 |
+
for name in ("normal", "overlay")
|
79 |
+
)
|
80 |
+
|
81 |
+
self._bin_dirs: List[str] = []
|
82 |
+
self._lib_dirs: List[str] = []
|
83 |
+
for prefix in reversed(list(self._prefixes.values())):
|
84 |
+
self._bin_dirs.append(prefix.bin_dir)
|
85 |
+
self._lib_dirs.extend(prefix.lib_dirs)
|
86 |
+
|
87 |
+
# Customize site to:
|
88 |
+
# - ensure .pth files are honored
|
89 |
+
# - prevent access to system site packages
|
90 |
+
system_sites = {
|
91 |
+
os.path.normcase(site) for site in (get_purelib(), get_platlib())
|
92 |
+
}
|
93 |
+
self._site_dir = os.path.join(temp_dir.path, "site")
|
94 |
+
if not os.path.exists(self._site_dir):
|
95 |
+
os.mkdir(self._site_dir)
|
96 |
+
with open(
|
97 |
+
os.path.join(self._site_dir, "sitecustomize.py"), "w", encoding="utf-8"
|
98 |
+
) as fp:
|
99 |
+
fp.write(
|
100 |
+
textwrap.dedent(
|
101 |
+
"""
|
102 |
+
import os, site, sys
|
103 |
+
|
104 |
+
# First, drop system-sites related paths.
|
105 |
+
original_sys_path = sys.path[:]
|
106 |
+
known_paths = set()
|
107 |
+
for path in {system_sites!r}:
|
108 |
+
site.addsitedir(path, known_paths=known_paths)
|
109 |
+
system_paths = set(
|
110 |
+
os.path.normcase(path)
|
111 |
+
for path in sys.path[len(original_sys_path):]
|
112 |
+
)
|
113 |
+
original_sys_path = [
|
114 |
+
path for path in original_sys_path
|
115 |
+
if os.path.normcase(path) not in system_paths
|
116 |
+
]
|
117 |
+
sys.path = original_sys_path
|
118 |
+
|
119 |
+
# Second, add lib directories.
|
120 |
+
# ensuring .pth file are processed.
|
121 |
+
for path in {lib_dirs!r}:
|
122 |
+
assert not path in sys.path
|
123 |
+
site.addsitedir(path)
|
124 |
+
"""
|
125 |
+
).format(system_sites=system_sites, lib_dirs=self._lib_dirs)
|
126 |
+
)
|
127 |
+
|
128 |
+
def __enter__(self) -> None:
|
129 |
+
self._save_env = {
|
130 |
+
name: os.environ.get(name, None)
|
131 |
+
for name in ("PATH", "PYTHONNOUSERSITE", "PYTHONPATH")
|
132 |
+
}
|
133 |
+
|
134 |
+
path = self._bin_dirs[:]
|
135 |
+
old_path = self._save_env["PATH"]
|
136 |
+
if old_path:
|
137 |
+
path.extend(old_path.split(os.pathsep))
|
138 |
+
|
139 |
+
pythonpath = [self._site_dir]
|
140 |
+
|
141 |
+
os.environ.update(
|
142 |
+
{
|
143 |
+
"PATH": os.pathsep.join(path),
|
144 |
+
"PYTHONNOUSERSITE": "1",
|
145 |
+
"PYTHONPATH": os.pathsep.join(pythonpath),
|
146 |
+
}
|
147 |
+
)
|
148 |
+
|
149 |
+
def __exit__(
|
150 |
+
self,
|
151 |
+
exc_type: Optional[Type[BaseException]],
|
152 |
+
exc_val: Optional[BaseException],
|
153 |
+
exc_tb: Optional[TracebackType],
|
154 |
+
) -> None:
|
155 |
+
for varname, old_value in self._save_env.items():
|
156 |
+
if old_value is None:
|
157 |
+
os.environ.pop(varname, None)
|
158 |
+
else:
|
159 |
+
os.environ[varname] = old_value
|
160 |
+
|
161 |
+
def check_requirements(
|
162 |
+
self, reqs: Iterable[str]
|
163 |
+
) -> Tuple[Set[Tuple[str, str]], Set[str]]:
|
164 |
+
"""Return 2 sets:
|
165 |
+
- conflicting requirements: set of (installed, wanted) reqs tuples
|
166 |
+
- missing requirements: set of reqs
|
167 |
+
"""
|
168 |
+
missing = set()
|
169 |
+
conflicting = set()
|
170 |
+
if reqs:
|
171 |
+
env = get_environment(self._lib_dirs)
|
172 |
+
for req_str in reqs:
|
173 |
+
req = Requirement(req_str)
|
174 |
+
dist = env.get_distribution(req.name)
|
175 |
+
if not dist:
|
176 |
+
missing.add(req_str)
|
177 |
+
continue
|
178 |
+
if isinstance(dist.version, Version):
|
179 |
+
installed_req_str = f"{req.name}=={dist.version}"
|
180 |
+
else:
|
181 |
+
installed_req_str = f"{req.name}==={dist.version}"
|
182 |
+
if dist.version not in req.specifier:
|
183 |
+
conflicting.add((installed_req_str, req_str))
|
184 |
+
# FIXME: Consider direct URL?
|
185 |
+
return conflicting, missing
|
186 |
+
|
187 |
+
def install_requirements(
|
188 |
+
self,
|
189 |
+
finder: "PackageFinder",
|
190 |
+
requirements: Iterable[str],
|
191 |
+
prefix_as_string: str,
|
192 |
+
*,
|
193 |
+
kind: str,
|
194 |
+
) -> None:
|
195 |
+
prefix = self._prefixes[prefix_as_string]
|
196 |
+
assert not prefix.setup
|
197 |
+
prefix.setup = True
|
198 |
+
if not requirements:
|
199 |
+
return
|
200 |
+
with contextlib.ExitStack() as ctx:
|
201 |
+
pip_runnable = ctx.enter_context(_create_standalone_pip())
|
202 |
+
self._install_requirements(
|
203 |
+
pip_runnable,
|
204 |
+
finder,
|
205 |
+
requirements,
|
206 |
+
prefix,
|
207 |
+
kind=kind,
|
208 |
+
)
|
209 |
+
|
210 |
+
@staticmethod
|
211 |
+
def _install_requirements(
|
212 |
+
pip_runnable: str,
|
213 |
+
finder: "PackageFinder",
|
214 |
+
requirements: Iterable[str],
|
215 |
+
prefix: _Prefix,
|
216 |
+
*,
|
217 |
+
kind: str,
|
218 |
+
) -> None:
|
219 |
+
args: List[str] = [
|
220 |
+
sys.executable,
|
221 |
+
pip_runnable,
|
222 |
+
"install",
|
223 |
+
"--ignore-installed",
|
224 |
+
"--no-user",
|
225 |
+
"--prefix",
|
226 |
+
prefix.path,
|
227 |
+
"--no-warn-script-location",
|
228 |
+
]
|
229 |
+
if logger.getEffectiveLevel() <= logging.DEBUG:
|
230 |
+
args.append("-v")
|
231 |
+
for format_control in ("no_binary", "only_binary"):
|
232 |
+
formats = getattr(finder.format_control, format_control)
|
233 |
+
args.extend(
|
234 |
+
(
|
235 |
+
"--" + format_control.replace("_", "-"),
|
236 |
+
",".join(sorted(formats or {":none:"})),
|
237 |
+
)
|
238 |
+
)
|
239 |
+
|
240 |
+
index_urls = finder.index_urls
|
241 |
+
if index_urls:
|
242 |
+
args.extend(["-i", index_urls[0]])
|
243 |
+
for extra_index in index_urls[1:]:
|
244 |
+
args.extend(["--extra-index-url", extra_index])
|
245 |
+
else:
|
246 |
+
args.append("--no-index")
|
247 |
+
for link in finder.find_links:
|
248 |
+
args.extend(["--find-links", link])
|
249 |
+
|
250 |
+
for host in finder.trusted_hosts:
|
251 |
+
args.extend(["--trusted-host", host])
|
252 |
+
if finder.allow_all_prereleases:
|
253 |
+
args.append("--pre")
|
254 |
+
if finder.prefer_binary:
|
255 |
+
args.append("--prefer-binary")
|
256 |
+
args.append("--")
|
257 |
+
args.extend(requirements)
|
258 |
+
extra_environ = {"_PIP_STANDALONE_CERT": where()}
|
259 |
+
with open_spinner(f"Installing {kind}") as spinner:
|
260 |
+
call_subprocess(
|
261 |
+
args,
|
262 |
+
command_desc=f"pip subprocess to install {kind}",
|
263 |
+
spinner=spinner,
|
264 |
+
extra_environ=extra_environ,
|
265 |
+
)
|
266 |
+
|
267 |
+
|
268 |
+
class NoOpBuildEnvironment(BuildEnvironment):
|
269 |
+
"""A no-op drop-in replacement for BuildEnvironment"""
|
270 |
+
|
271 |
+
def __init__(self) -> None:
|
272 |
+
pass
|
273 |
+
|
274 |
+
def __enter__(self) -> None:
|
275 |
+
pass
|
276 |
+
|
277 |
+
def __exit__(
|
278 |
+
self,
|
279 |
+
exc_type: Optional[Type[BaseException]],
|
280 |
+
exc_val: Optional[BaseException],
|
281 |
+
exc_tb: Optional[TracebackType],
|
282 |
+
) -> None:
|
283 |
+
pass
|
284 |
+
|
285 |
+
def cleanup(self) -> None:
|
286 |
+
pass
|
287 |
+
|
288 |
+
def install_requirements(
|
289 |
+
self,
|
290 |
+
finder: "PackageFinder",
|
291 |
+
requirements: Iterable[str],
|
292 |
+
prefix_as_string: str,
|
293 |
+
*,
|
294 |
+
kind: str,
|
295 |
+
) -> None:
|
296 |
+
raise NotImplementedError()
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/cache.py
ADDED
@@ -0,0 +1,264 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Cache Management
|
2 |
+
"""
|
3 |
+
|
4 |
+
import hashlib
|
5 |
+
import json
|
6 |
+
import logging
|
7 |
+
import os
|
8 |
+
from typing import Any, Dict, List, Optional, Set
|
9 |
+
|
10 |
+
from pip._vendor.packaging.tags import Tag, interpreter_name, interpreter_version
|
11 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
12 |
+
|
13 |
+
from pip._internal.exceptions import InvalidWheelFilename
|
14 |
+
from pip._internal.models.format_control import FormatControl
|
15 |
+
from pip._internal.models.link import Link
|
16 |
+
from pip._internal.models.wheel import Wheel
|
17 |
+
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
|
18 |
+
from pip._internal.utils.urls import path_to_url
|
19 |
+
|
20 |
+
logger = logging.getLogger(__name__)
|
21 |
+
|
22 |
+
|
23 |
+
def _hash_dict(d: Dict[str, str]) -> str:
|
24 |
+
"""Return a stable sha224 of a dictionary."""
|
25 |
+
s = json.dumps(d, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
|
26 |
+
return hashlib.sha224(s.encode("ascii")).hexdigest()
|
27 |
+
|
28 |
+
|
29 |
+
class Cache:
|
30 |
+
"""An abstract class - provides cache directories for data from links
|
31 |
+
|
32 |
+
|
33 |
+
:param cache_dir: The root of the cache.
|
34 |
+
:param format_control: An object of FormatControl class to limit
|
35 |
+
binaries being read from the cache.
|
36 |
+
:param allowed_formats: which formats of files the cache should store.
|
37 |
+
('binary' and 'source' are the only allowed values)
|
38 |
+
"""
|
39 |
+
|
40 |
+
def __init__(
|
41 |
+
self, cache_dir: str, format_control: FormatControl, allowed_formats: Set[str]
|
42 |
+
) -> None:
|
43 |
+
super().__init__()
|
44 |
+
assert not cache_dir or os.path.isabs(cache_dir)
|
45 |
+
self.cache_dir = cache_dir or None
|
46 |
+
self.format_control = format_control
|
47 |
+
self.allowed_formats = allowed_formats
|
48 |
+
|
49 |
+
_valid_formats = {"source", "binary"}
|
50 |
+
assert self.allowed_formats.union(_valid_formats) == _valid_formats
|
51 |
+
|
52 |
+
def _get_cache_path_parts(self, link: Link) -> List[str]:
|
53 |
+
"""Get parts of part that must be os.path.joined with cache_dir"""
|
54 |
+
|
55 |
+
# We want to generate an url to use as our cache key, we don't want to
|
56 |
+
# just re-use the URL because it might have other items in the fragment
|
57 |
+
# and we don't care about those.
|
58 |
+
key_parts = {"url": link.url_without_fragment}
|
59 |
+
if link.hash_name is not None and link.hash is not None:
|
60 |
+
key_parts[link.hash_name] = link.hash
|
61 |
+
if link.subdirectory_fragment:
|
62 |
+
key_parts["subdirectory"] = link.subdirectory_fragment
|
63 |
+
|
64 |
+
# Include interpreter name, major and minor version in cache key
|
65 |
+
# to cope with ill-behaved sdists that build a different wheel
|
66 |
+
# depending on the python version their setup.py is being run on,
|
67 |
+
# and don't encode the difference in compatibility tags.
|
68 |
+
# https://github.com/pypa/pip/issues/7296
|
69 |
+
key_parts["interpreter_name"] = interpreter_name()
|
70 |
+
key_parts["interpreter_version"] = interpreter_version()
|
71 |
+
|
72 |
+
# Encode our key url with sha224, we'll use this because it has similar
|
73 |
+
# security properties to sha256, but with a shorter total output (and
|
74 |
+
# thus less secure). However the differences don't make a lot of
|
75 |
+
# difference for our use case here.
|
76 |
+
hashed = _hash_dict(key_parts)
|
77 |
+
|
78 |
+
# We want to nest the directories some to prevent having a ton of top
|
79 |
+
# level directories where we might run out of sub directories on some
|
80 |
+
# FS.
|
81 |
+
parts = [hashed[:2], hashed[2:4], hashed[4:6], hashed[6:]]
|
82 |
+
|
83 |
+
return parts
|
84 |
+
|
85 |
+
def _get_candidates(self, link: Link, canonical_package_name: str) -> List[Any]:
|
86 |
+
can_not_cache = not self.cache_dir or not canonical_package_name or not link
|
87 |
+
if can_not_cache:
|
88 |
+
return []
|
89 |
+
|
90 |
+
formats = self.format_control.get_allowed_formats(canonical_package_name)
|
91 |
+
if not self.allowed_formats.intersection(formats):
|
92 |
+
return []
|
93 |
+
|
94 |
+
candidates = []
|
95 |
+
path = self.get_path_for_link(link)
|
96 |
+
if os.path.isdir(path):
|
97 |
+
for candidate in os.listdir(path):
|
98 |
+
candidates.append((candidate, path))
|
99 |
+
return candidates
|
100 |
+
|
101 |
+
def get_path_for_link(self, link: Link) -> str:
|
102 |
+
"""Return a directory to store cached items in for link."""
|
103 |
+
raise NotImplementedError()
|
104 |
+
|
105 |
+
def get(
|
106 |
+
self,
|
107 |
+
link: Link,
|
108 |
+
package_name: Optional[str],
|
109 |
+
supported_tags: List[Tag],
|
110 |
+
) -> Link:
|
111 |
+
"""Returns a link to a cached item if it exists, otherwise returns the
|
112 |
+
passed link.
|
113 |
+
"""
|
114 |
+
raise NotImplementedError()
|
115 |
+
|
116 |
+
|
117 |
+
class SimpleWheelCache(Cache):
|
118 |
+
"""A cache of wheels for future installs."""
|
119 |
+
|
120 |
+
def __init__(self, cache_dir: str, format_control: FormatControl) -> None:
|
121 |
+
super().__init__(cache_dir, format_control, {"binary"})
|
122 |
+
|
123 |
+
def get_path_for_link(self, link: Link) -> str:
|
124 |
+
"""Return a directory to store cached wheels for link
|
125 |
+
|
126 |
+
Because there are M wheels for any one sdist, we provide a directory
|
127 |
+
to cache them in, and then consult that directory when looking up
|
128 |
+
cache hits.
|
129 |
+
|
130 |
+
We only insert things into the cache if they have plausible version
|
131 |
+
numbers, so that we don't contaminate the cache with things that were
|
132 |
+
not unique. E.g. ./package might have dozens of installs done for it
|
133 |
+
and build a version of 0.0...and if we built and cached a wheel, we'd
|
134 |
+
end up using the same wheel even if the source has been edited.
|
135 |
+
|
136 |
+
:param link: The link of the sdist for which this will cache wheels.
|
137 |
+
"""
|
138 |
+
parts = self._get_cache_path_parts(link)
|
139 |
+
assert self.cache_dir
|
140 |
+
# Store wheels within the root cache_dir
|
141 |
+
return os.path.join(self.cache_dir, "wheels", *parts)
|
142 |
+
|
143 |
+
def get(
|
144 |
+
self,
|
145 |
+
link: Link,
|
146 |
+
package_name: Optional[str],
|
147 |
+
supported_tags: List[Tag],
|
148 |
+
) -> Link:
|
149 |
+
candidates = []
|
150 |
+
|
151 |
+
if not package_name:
|
152 |
+
return link
|
153 |
+
|
154 |
+
canonical_package_name = canonicalize_name(package_name)
|
155 |
+
for wheel_name, wheel_dir in self._get_candidates(link, canonical_package_name):
|
156 |
+
try:
|
157 |
+
wheel = Wheel(wheel_name)
|
158 |
+
except InvalidWheelFilename:
|
159 |
+
continue
|
160 |
+
if canonicalize_name(wheel.name) != canonical_package_name:
|
161 |
+
logger.debug(
|
162 |
+
"Ignoring cached wheel %s for %s as it "
|
163 |
+
"does not match the expected distribution name %s.",
|
164 |
+
wheel_name,
|
165 |
+
link,
|
166 |
+
package_name,
|
167 |
+
)
|
168 |
+
continue
|
169 |
+
if not wheel.supported(supported_tags):
|
170 |
+
# Built for a different python/arch/etc
|
171 |
+
continue
|
172 |
+
candidates.append(
|
173 |
+
(
|
174 |
+
wheel.support_index_min(supported_tags),
|
175 |
+
wheel_name,
|
176 |
+
wheel_dir,
|
177 |
+
)
|
178 |
+
)
|
179 |
+
|
180 |
+
if not candidates:
|
181 |
+
return link
|
182 |
+
|
183 |
+
_, wheel_name, wheel_dir = min(candidates)
|
184 |
+
return Link(path_to_url(os.path.join(wheel_dir, wheel_name)))
|
185 |
+
|
186 |
+
|
187 |
+
class EphemWheelCache(SimpleWheelCache):
|
188 |
+
"""A SimpleWheelCache that creates it's own temporary cache directory"""
|
189 |
+
|
190 |
+
def __init__(self, format_control: FormatControl) -> None:
|
191 |
+
self._temp_dir = TempDirectory(
|
192 |
+
kind=tempdir_kinds.EPHEM_WHEEL_CACHE,
|
193 |
+
globally_managed=True,
|
194 |
+
)
|
195 |
+
|
196 |
+
super().__init__(self._temp_dir.path, format_control)
|
197 |
+
|
198 |
+
|
199 |
+
class CacheEntry:
|
200 |
+
def __init__(
|
201 |
+
self,
|
202 |
+
link: Link,
|
203 |
+
persistent: bool,
|
204 |
+
):
|
205 |
+
self.link = link
|
206 |
+
self.persistent = persistent
|
207 |
+
|
208 |
+
|
209 |
+
class WheelCache(Cache):
|
210 |
+
"""Wraps EphemWheelCache and SimpleWheelCache into a single Cache
|
211 |
+
|
212 |
+
This Cache allows for gracefully degradation, using the ephem wheel cache
|
213 |
+
when a certain link is not found in the simple wheel cache first.
|
214 |
+
"""
|
215 |
+
|
216 |
+
def __init__(self, cache_dir: str, format_control: FormatControl) -> None:
|
217 |
+
super().__init__(cache_dir, format_control, {"binary"})
|
218 |
+
self._wheel_cache = SimpleWheelCache(cache_dir, format_control)
|
219 |
+
self._ephem_cache = EphemWheelCache(format_control)
|
220 |
+
|
221 |
+
def get_path_for_link(self, link: Link) -> str:
|
222 |
+
return self._wheel_cache.get_path_for_link(link)
|
223 |
+
|
224 |
+
def get_ephem_path_for_link(self, link: Link) -> str:
|
225 |
+
return self._ephem_cache.get_path_for_link(link)
|
226 |
+
|
227 |
+
def get(
|
228 |
+
self,
|
229 |
+
link: Link,
|
230 |
+
package_name: Optional[str],
|
231 |
+
supported_tags: List[Tag],
|
232 |
+
) -> Link:
|
233 |
+
cache_entry = self.get_cache_entry(link, package_name, supported_tags)
|
234 |
+
if cache_entry is None:
|
235 |
+
return link
|
236 |
+
return cache_entry.link
|
237 |
+
|
238 |
+
def get_cache_entry(
|
239 |
+
self,
|
240 |
+
link: Link,
|
241 |
+
package_name: Optional[str],
|
242 |
+
supported_tags: List[Tag],
|
243 |
+
) -> Optional[CacheEntry]:
|
244 |
+
"""Returns a CacheEntry with a link to a cached item if it exists or
|
245 |
+
None. The cache entry indicates if the item was found in the persistent
|
246 |
+
or ephemeral cache.
|
247 |
+
"""
|
248 |
+
retval = self._wheel_cache.get(
|
249 |
+
link=link,
|
250 |
+
package_name=package_name,
|
251 |
+
supported_tags=supported_tags,
|
252 |
+
)
|
253 |
+
if retval is not link:
|
254 |
+
return CacheEntry(retval, persistent=True)
|
255 |
+
|
256 |
+
retval = self._ephem_cache.get(
|
257 |
+
link=link,
|
258 |
+
package_name=package_name,
|
259 |
+
supported_tags=supported_tags,
|
260 |
+
)
|
261 |
+
if retval is not link:
|
262 |
+
return CacheEntry(retval, persistent=False)
|
263 |
+
|
264 |
+
return None
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/__init__.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Subpackage containing all of pip's command line interface related code
|
2 |
+
"""
|
3 |
+
|
4 |
+
# This file intentionally does not import submodules
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/main.py
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Primary application entrypoint.
|
2 |
+
"""
|
3 |
+
import locale
|
4 |
+
import logging
|
5 |
+
import os
|
6 |
+
import sys
|
7 |
+
from typing import List, Optional
|
8 |
+
|
9 |
+
from pip._internal.cli.autocompletion import autocomplete
|
10 |
+
from pip._internal.cli.main_parser import parse_command
|
11 |
+
from pip._internal.commands import create_command
|
12 |
+
from pip._internal.exceptions import PipError
|
13 |
+
from pip._internal.utils import deprecation
|
14 |
+
|
15 |
+
logger = logging.getLogger(__name__)
|
16 |
+
|
17 |
+
|
18 |
+
# Do not import and use main() directly! Using it directly is actively
|
19 |
+
# discouraged by pip's maintainers. The name, location and behavior of
|
20 |
+
# this function is subject to change, so calling it directly is not
|
21 |
+
# portable across different pip versions.
|
22 |
+
|
23 |
+
# In addition, running pip in-process is unsupported and unsafe. This is
|
24 |
+
# elaborated in detail at
|
25 |
+
# https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program.
|
26 |
+
# That document also provides suggestions that should work for nearly
|
27 |
+
# all users that are considering importing and using main() directly.
|
28 |
+
|
29 |
+
# However, we know that certain users will still want to invoke pip
|
30 |
+
# in-process. If you understand and accept the implications of using pip
|
31 |
+
# in an unsupported manner, the best approach is to use runpy to avoid
|
32 |
+
# depending on the exact location of this entry point.
|
33 |
+
|
34 |
+
# The following example shows how to use runpy to invoke pip in that
|
35 |
+
# case:
|
36 |
+
#
|
37 |
+
# sys.argv = ["pip", your, args, here]
|
38 |
+
# runpy.run_module("pip", run_name="__main__")
|
39 |
+
#
|
40 |
+
# Note that this will exit the process after running, unlike a direct
|
41 |
+
# call to main. As it is not safe to do any processing after calling
|
42 |
+
# main, this should not be an issue in practice.
|
43 |
+
|
44 |
+
|
45 |
+
def main(args: Optional[List[str]] = None) -> int:
|
46 |
+
if args is None:
|
47 |
+
args = sys.argv[1:]
|
48 |
+
|
49 |
+
# Configure our deprecation warnings to be sent through loggers
|
50 |
+
deprecation.install_warning_logger()
|
51 |
+
|
52 |
+
autocomplete()
|
53 |
+
|
54 |
+
try:
|
55 |
+
cmd_name, cmd_args = parse_command(args)
|
56 |
+
except PipError as exc:
|
57 |
+
sys.stderr.write(f"ERROR: {exc}")
|
58 |
+
sys.stderr.write(os.linesep)
|
59 |
+
sys.exit(1)
|
60 |
+
|
61 |
+
# Needed for locale.getpreferredencoding(False) to work
|
62 |
+
# in pip._internal.utils.encoding.auto_decode
|
63 |
+
try:
|
64 |
+
locale.setlocale(locale.LC_ALL, "")
|
65 |
+
except locale.Error as e:
|
66 |
+
# setlocale can apparently crash if locale are uninitialized
|
67 |
+
logger.debug("Ignoring error %s when setting locale", e)
|
68 |
+
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
|
69 |
+
|
70 |
+
return command.main(cmd_args)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/progress_bars.py
ADDED
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import functools
|
2 |
+
import itertools
|
3 |
+
import sys
|
4 |
+
from signal import SIGINT, default_int_handler, signal
|
5 |
+
from typing import Any, Callable, Iterator, Optional, Tuple
|
6 |
+
|
7 |
+
from pip._vendor.progress.bar import Bar, FillingCirclesBar, IncrementalBar
|
8 |
+
from pip._vendor.progress.spinner import Spinner
|
9 |
+
from pip._vendor.rich.progress import (
|
10 |
+
BarColumn,
|
11 |
+
DownloadColumn,
|
12 |
+
FileSizeColumn,
|
13 |
+
Progress,
|
14 |
+
ProgressColumn,
|
15 |
+
SpinnerColumn,
|
16 |
+
TextColumn,
|
17 |
+
TimeElapsedColumn,
|
18 |
+
TimeRemainingColumn,
|
19 |
+
TransferSpeedColumn,
|
20 |
+
)
|
21 |
+
|
22 |
+
from pip._internal.utils.compat import WINDOWS
|
23 |
+
from pip._internal.utils.logging import get_indentation
|
24 |
+
from pip._internal.utils.misc import format_size
|
25 |
+
|
26 |
+
try:
|
27 |
+
from pip._vendor import colorama
|
28 |
+
# Lots of different errors can come from this, including SystemError and
|
29 |
+
# ImportError.
|
30 |
+
except Exception:
|
31 |
+
colorama = None
|
32 |
+
|
33 |
+
DownloadProgressRenderer = Callable[[Iterator[bytes]], Iterator[bytes]]
|
34 |
+
|
35 |
+
|
36 |
+
def _select_progress_class(preferred: Bar, fallback: Bar) -> Bar:
|
37 |
+
encoding = getattr(preferred.file, "encoding", None)
|
38 |
+
|
39 |
+
# If we don't know what encoding this file is in, then we'll just assume
|
40 |
+
# that it doesn't support unicode and use the ASCII bar.
|
41 |
+
if not encoding:
|
42 |
+
return fallback
|
43 |
+
|
44 |
+
# Collect all of the possible characters we want to use with the preferred
|
45 |
+
# bar.
|
46 |
+
characters = [
|
47 |
+
getattr(preferred, "empty_fill", ""),
|
48 |
+
getattr(preferred, "fill", ""),
|
49 |
+
]
|
50 |
+
characters += list(getattr(preferred, "phases", []))
|
51 |
+
|
52 |
+
# Try to decode the characters we're using for the bar using the encoding
|
53 |
+
# of the given file, if this works then we'll assume that we can use the
|
54 |
+
# fancier bar and if not we'll fall back to the plaintext bar.
|
55 |
+
try:
|
56 |
+
"".join(characters).encode(encoding)
|
57 |
+
except UnicodeEncodeError:
|
58 |
+
return fallback
|
59 |
+
else:
|
60 |
+
return preferred
|
61 |
+
|
62 |
+
|
63 |
+
_BaseBar: Any = _select_progress_class(IncrementalBar, Bar)
|
64 |
+
|
65 |
+
|
66 |
+
class InterruptibleMixin:
|
67 |
+
"""
|
68 |
+
Helper to ensure that self.finish() gets called on keyboard interrupt.
|
69 |
+
|
70 |
+
This allows downloads to be interrupted without leaving temporary state
|
71 |
+
(like hidden cursors) behind.
|
72 |
+
|
73 |
+
This class is similar to the progress library's existing SigIntMixin
|
74 |
+
helper, but as of version 1.2, that helper has the following problems:
|
75 |
+
|
76 |
+
1. It calls sys.exit().
|
77 |
+
2. It discards the existing SIGINT handler completely.
|
78 |
+
3. It leaves its own handler in place even after an uninterrupted finish,
|
79 |
+
which will have unexpected delayed effects if the user triggers an
|
80 |
+
unrelated keyboard interrupt some time after a progress-displaying
|
81 |
+
download has already completed, for example.
|
82 |
+
"""
|
83 |
+
|
84 |
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
85 |
+
"""
|
86 |
+
Save the original SIGINT handler for later.
|
87 |
+
"""
|
88 |
+
# https://github.com/python/mypy/issues/5887
|
89 |
+
super().__init__(*args, **kwargs) # type: ignore
|
90 |
+
|
91 |
+
self.original_handler = signal(SIGINT, self.handle_sigint)
|
92 |
+
|
93 |
+
# If signal() returns None, the previous handler was not installed from
|
94 |
+
# Python, and we cannot restore it. This probably should not happen,
|
95 |
+
# but if it does, we must restore something sensible instead, at least.
|
96 |
+
# The least bad option should be Python's default SIGINT handler, which
|
97 |
+
# just raises KeyboardInterrupt.
|
98 |
+
if self.original_handler is None:
|
99 |
+
self.original_handler = default_int_handler
|
100 |
+
|
101 |
+
def finish(self) -> None:
|
102 |
+
"""
|
103 |
+
Restore the original SIGINT handler after finishing.
|
104 |
+
|
105 |
+
This should happen regardless of whether the progress display finishes
|
106 |
+
normally, or gets interrupted.
|
107 |
+
"""
|
108 |
+
super().finish() # type: ignore
|
109 |
+
signal(SIGINT, self.original_handler)
|
110 |
+
|
111 |
+
def handle_sigint(self, signum, frame): # type: ignore
|
112 |
+
"""
|
113 |
+
Call self.finish() before delegating to the original SIGINT handler.
|
114 |
+
|
115 |
+
This handler should only be in place while the progress display is
|
116 |
+
active.
|
117 |
+
"""
|
118 |
+
self.finish()
|
119 |
+
self.original_handler(signum, frame)
|
120 |
+
|
121 |
+
|
122 |
+
class SilentBar(Bar):
|
123 |
+
def update(self) -> None:
|
124 |
+
pass
|
125 |
+
|
126 |
+
|
127 |
+
class BlueEmojiBar(IncrementalBar):
|
128 |
+
|
129 |
+
suffix = "%(percent)d%%"
|
130 |
+
bar_prefix = " "
|
131 |
+
bar_suffix = " "
|
132 |
+
phases = ("\U0001F539", "\U0001F537", "\U0001F535")
|
133 |
+
|
134 |
+
|
135 |
+
class DownloadProgressMixin:
|
136 |
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
137 |
+
# https://github.com/python/mypy/issues/5887
|
138 |
+
super().__init__(*args, **kwargs) # type: ignore
|
139 |
+
self.message: str = (" " * (get_indentation() + 2)) + self.message
|
140 |
+
|
141 |
+
@property
|
142 |
+
def downloaded(self) -> str:
|
143 |
+
return format_size(self.index) # type: ignore
|
144 |
+
|
145 |
+
@property
|
146 |
+
def download_speed(self) -> str:
|
147 |
+
# Avoid zero division errors...
|
148 |
+
if self.avg == 0.0: # type: ignore
|
149 |
+
return "..."
|
150 |
+
return format_size(1 / self.avg) + "/s" # type: ignore
|
151 |
+
|
152 |
+
@property
|
153 |
+
def pretty_eta(self) -> str:
|
154 |
+
if self.eta: # type: ignore
|
155 |
+
return f"eta {self.eta_td}" # type: ignore
|
156 |
+
return ""
|
157 |
+
|
158 |
+
def iter(self, it): # type: ignore
|
159 |
+
for x in it:
|
160 |
+
yield x
|
161 |
+
# B305 is incorrectly raised here
|
162 |
+
# https://github.com/PyCQA/flake8-bugbear/issues/59
|
163 |
+
self.next(len(x)) # noqa: B305
|
164 |
+
self.finish()
|
165 |
+
|
166 |
+
|
167 |
+
class WindowsMixin:
|
168 |
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
169 |
+
# The Windows terminal does not support the hide/show cursor ANSI codes
|
170 |
+
# even with colorama. So we'll ensure that hide_cursor is False on
|
171 |
+
# Windows.
|
172 |
+
# This call needs to go before the super() call, so that hide_cursor
|
173 |
+
# is set in time. The base progress bar class writes the "hide cursor"
|
174 |
+
# code to the terminal in its init, so if we don't set this soon
|
175 |
+
# enough, we get a "hide" with no corresponding "show"...
|
176 |
+
if WINDOWS and self.hide_cursor: # type: ignore
|
177 |
+
self.hide_cursor = False
|
178 |
+
|
179 |
+
# https://github.com/python/mypy/issues/5887
|
180 |
+
super().__init__(*args, **kwargs) # type: ignore
|
181 |
+
|
182 |
+
# Check if we are running on Windows and we have the colorama module,
|
183 |
+
# if we do then wrap our file with it.
|
184 |
+
if WINDOWS and colorama:
|
185 |
+
self.file = colorama.AnsiToWin32(self.file) # type: ignore
|
186 |
+
# The progress code expects to be able to call self.file.isatty()
|
187 |
+
# but the colorama.AnsiToWin32() object doesn't have that, so we'll
|
188 |
+
# add it.
|
189 |
+
self.file.isatty = lambda: self.file.wrapped.isatty()
|
190 |
+
# The progress code expects to be able to call self.file.flush()
|
191 |
+
# but the colorama.AnsiToWin32() object doesn't have that, so we'll
|
192 |
+
# add it.
|
193 |
+
self.file.flush = lambda: self.file.wrapped.flush()
|
194 |
+
|
195 |
+
|
196 |
+
class BaseDownloadProgressBar(WindowsMixin, InterruptibleMixin, DownloadProgressMixin):
|
197 |
+
|
198 |
+
file = sys.stdout
|
199 |
+
message = "%(percent)d%%"
|
200 |
+
suffix = "%(downloaded)s %(download_speed)s %(pretty_eta)s"
|
201 |
+
|
202 |
+
|
203 |
+
class DefaultDownloadProgressBar(BaseDownloadProgressBar, _BaseBar):
|
204 |
+
pass
|
205 |
+
|
206 |
+
|
207 |
+
class DownloadSilentBar(BaseDownloadProgressBar, SilentBar):
|
208 |
+
pass
|
209 |
+
|
210 |
+
|
211 |
+
class DownloadBar(BaseDownloadProgressBar, Bar):
|
212 |
+
pass
|
213 |
+
|
214 |
+
|
215 |
+
class DownloadFillingCirclesBar(BaseDownloadProgressBar, FillingCirclesBar):
|
216 |
+
pass
|
217 |
+
|
218 |
+
|
219 |
+
class DownloadBlueEmojiProgressBar(BaseDownloadProgressBar, BlueEmojiBar):
|
220 |
+
pass
|
221 |
+
|
222 |
+
|
223 |
+
class DownloadProgressSpinner(
|
224 |
+
WindowsMixin, InterruptibleMixin, DownloadProgressMixin, Spinner
|
225 |
+
):
|
226 |
+
|
227 |
+
file = sys.stdout
|
228 |
+
suffix = "%(downloaded)s %(download_speed)s"
|
229 |
+
|
230 |
+
def next_phase(self) -> str:
|
231 |
+
if not hasattr(self, "_phaser"):
|
232 |
+
self._phaser = itertools.cycle(self.phases)
|
233 |
+
return next(self._phaser)
|
234 |
+
|
235 |
+
def update(self) -> None:
|
236 |
+
message = self.message % self
|
237 |
+
phase = self.next_phase()
|
238 |
+
suffix = self.suffix % self
|
239 |
+
line = "".join(
|
240 |
+
[
|
241 |
+
message,
|
242 |
+
" " if message else "",
|
243 |
+
phase,
|
244 |
+
" " if suffix else "",
|
245 |
+
suffix,
|
246 |
+
]
|
247 |
+
)
|
248 |
+
|
249 |
+
self.writeln(line)
|
250 |
+
|
251 |
+
|
252 |
+
BAR_TYPES = {
|
253 |
+
"off": (DownloadSilentBar, DownloadSilentBar),
|
254 |
+
"on": (DefaultDownloadProgressBar, DownloadProgressSpinner),
|
255 |
+
"ascii": (DownloadBar, DownloadProgressSpinner),
|
256 |
+
"pretty": (DownloadFillingCirclesBar, DownloadProgressSpinner),
|
257 |
+
"emoji": (DownloadBlueEmojiProgressBar, DownloadProgressSpinner),
|
258 |
+
}
|
259 |
+
|
260 |
+
|
261 |
+
def _legacy_progress_bar(
|
262 |
+
progress_bar: str, max: Optional[int]
|
263 |
+
) -> DownloadProgressRenderer:
|
264 |
+
if max is None or max == 0:
|
265 |
+
return BAR_TYPES[progress_bar][1]().iter # type: ignore
|
266 |
+
else:
|
267 |
+
return BAR_TYPES[progress_bar][0](max=max).iter
|
268 |
+
|
269 |
+
|
270 |
+
#
|
271 |
+
# Modern replacement, for our legacy progress bars.
|
272 |
+
#
|
273 |
+
def _rich_progress_bar(
|
274 |
+
iterable: Iterator[bytes],
|
275 |
+
*,
|
276 |
+
bar_type: str,
|
277 |
+
size: int,
|
278 |
+
) -> Iterator[bytes]:
|
279 |
+
assert bar_type == "on", "This should only be used in the default mode."
|
280 |
+
|
281 |
+
if not size:
|
282 |
+
total = float("inf")
|
283 |
+
columns: Tuple[ProgressColumn, ...] = (
|
284 |
+
TextColumn("[progress.description]{task.description}"),
|
285 |
+
SpinnerColumn("line", speed=1.5),
|
286 |
+
FileSizeColumn(),
|
287 |
+
TransferSpeedColumn(),
|
288 |
+
TimeElapsedColumn(),
|
289 |
+
)
|
290 |
+
else:
|
291 |
+
total = size
|
292 |
+
columns = (
|
293 |
+
TextColumn("[progress.description]{task.description}"),
|
294 |
+
BarColumn(),
|
295 |
+
DownloadColumn(),
|
296 |
+
TransferSpeedColumn(),
|
297 |
+
TextColumn("eta"),
|
298 |
+
TimeRemainingColumn(),
|
299 |
+
)
|
300 |
+
|
301 |
+
progress = Progress(*columns, refresh_per_second=30)
|
302 |
+
task_id = progress.add_task(" " * (get_indentation() + 2), total=total)
|
303 |
+
with progress:
|
304 |
+
for chunk in iterable:
|
305 |
+
yield chunk
|
306 |
+
progress.update(task_id, advance=len(chunk))
|
307 |
+
|
308 |
+
|
309 |
+
def get_download_progress_renderer(
|
310 |
+
*, bar_type: str, size: Optional[int] = None
|
311 |
+
) -> DownloadProgressRenderer:
|
312 |
+
"""Get an object that can be used to render the download progress.
|
313 |
+
|
314 |
+
Returns a callable, that takes an iterable to "wrap".
|
315 |
+
"""
|
316 |
+
if bar_type == "on":
|
317 |
+
return functools.partial(_rich_progress_bar, bar_type=bar_type, size=size)
|
318 |
+
elif bar_type == "off":
|
319 |
+
return iter # no-op, when passed an iterator
|
320 |
+
else:
|
321 |
+
return _legacy_progress_bar(bar_type, size)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py
ADDED
@@ -0,0 +1,506 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Contains the Command base classes that depend on PipSession.
|
2 |
+
|
3 |
+
The classes in this module are in a separate module so the commands not
|
4 |
+
needing download / PackageFinder capability don't unnecessarily import the
|
5 |
+
PackageFinder machinery and all its vendored dependencies, etc.
|
6 |
+
"""
|
7 |
+
|
8 |
+
import logging
|
9 |
+
import os
|
10 |
+
import sys
|
11 |
+
from functools import partial
|
12 |
+
from optparse import Values
|
13 |
+
from typing import Any, List, Optional, Tuple
|
14 |
+
|
15 |
+
from pip._internal.cache import WheelCache
|
16 |
+
from pip._internal.cli import cmdoptions
|
17 |
+
from pip._internal.cli.base_command import Command
|
18 |
+
from pip._internal.cli.command_context import CommandContextMixIn
|
19 |
+
from pip._internal.exceptions import CommandError, PreviousBuildDirError
|
20 |
+
from pip._internal.index.collector import LinkCollector
|
21 |
+
from pip._internal.index.package_finder import PackageFinder
|
22 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
23 |
+
from pip._internal.models.target_python import TargetPython
|
24 |
+
from pip._internal.network.session import PipSession
|
25 |
+
from pip._internal.operations.prepare import RequirementPreparer
|
26 |
+
from pip._internal.req.constructors import (
|
27 |
+
install_req_from_editable,
|
28 |
+
install_req_from_line,
|
29 |
+
install_req_from_parsed_requirement,
|
30 |
+
install_req_from_req_string,
|
31 |
+
)
|
32 |
+
from pip._internal.req.req_file import parse_requirements
|
33 |
+
from pip._internal.req.req_install import InstallRequirement
|
34 |
+
from pip._internal.req.req_tracker import RequirementTracker
|
35 |
+
from pip._internal.resolution.base import BaseResolver
|
36 |
+
from pip._internal.self_outdated_check import pip_self_version_check
|
37 |
+
from pip._internal.utils.deprecation import deprecated
|
38 |
+
from pip._internal.utils.temp_dir import (
|
39 |
+
TempDirectory,
|
40 |
+
TempDirectoryTypeRegistry,
|
41 |
+
tempdir_kinds,
|
42 |
+
)
|
43 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
44 |
+
|
45 |
+
logger = logging.getLogger(__name__)
|
46 |
+
|
47 |
+
|
48 |
+
class SessionCommandMixin(CommandContextMixIn):
|
49 |
+
|
50 |
+
"""
|
51 |
+
A class mixin for command classes needing _build_session().
|
52 |
+
"""
|
53 |
+
|
54 |
+
def __init__(self) -> None:
|
55 |
+
super().__init__()
|
56 |
+
self._session: Optional[PipSession] = None
|
57 |
+
|
58 |
+
@classmethod
|
59 |
+
def _get_index_urls(cls, options: Values) -> Optional[List[str]]:
|
60 |
+
"""Return a list of index urls from user-provided options."""
|
61 |
+
index_urls = []
|
62 |
+
if not getattr(options, "no_index", False):
|
63 |
+
url = getattr(options, "index_url", None)
|
64 |
+
if url:
|
65 |
+
index_urls.append(url)
|
66 |
+
urls = getattr(options, "extra_index_urls", None)
|
67 |
+
if urls:
|
68 |
+
index_urls.extend(urls)
|
69 |
+
# Return None rather than an empty list
|
70 |
+
return index_urls or None
|
71 |
+
|
72 |
+
def get_default_session(self, options: Values) -> PipSession:
|
73 |
+
"""Get a default-managed session."""
|
74 |
+
if self._session is None:
|
75 |
+
self._session = self.enter_context(self._build_session(options))
|
76 |
+
# there's no type annotation on requests.Session, so it's
|
77 |
+
# automatically ContextManager[Any] and self._session becomes Any,
|
78 |
+
# then https://github.com/python/mypy/issues/7696 kicks in
|
79 |
+
assert self._session is not None
|
80 |
+
return self._session
|
81 |
+
|
82 |
+
def _build_session(
|
83 |
+
self,
|
84 |
+
options: Values,
|
85 |
+
retries: Optional[int] = None,
|
86 |
+
timeout: Optional[int] = None,
|
87 |
+
) -> PipSession:
|
88 |
+
assert not options.cache_dir or os.path.isabs(options.cache_dir)
|
89 |
+
session = PipSession(
|
90 |
+
cache=(
|
91 |
+
os.path.join(options.cache_dir, "http") if options.cache_dir else None
|
92 |
+
),
|
93 |
+
retries=retries if retries is not None else options.retries,
|
94 |
+
trusted_hosts=options.trusted_hosts,
|
95 |
+
index_urls=self._get_index_urls(options),
|
96 |
+
)
|
97 |
+
|
98 |
+
# Handle custom ca-bundles from the user
|
99 |
+
if options.cert:
|
100 |
+
session.verify = options.cert
|
101 |
+
|
102 |
+
# Handle SSL client certificate
|
103 |
+
if options.client_cert:
|
104 |
+
session.cert = options.client_cert
|
105 |
+
|
106 |
+
# Handle timeouts
|
107 |
+
if options.timeout or timeout:
|
108 |
+
session.timeout = timeout if timeout is not None else options.timeout
|
109 |
+
|
110 |
+
# Handle configured proxies
|
111 |
+
if options.proxy:
|
112 |
+
session.proxies = {
|
113 |
+
"http": options.proxy,
|
114 |
+
"https": options.proxy,
|
115 |
+
}
|
116 |
+
|
117 |
+
# Determine if we can prompt the user for authentication or not
|
118 |
+
session.auth.prompting = not options.no_input
|
119 |
+
|
120 |
+
return session
|
121 |
+
|
122 |
+
|
123 |
+
class IndexGroupCommand(Command, SessionCommandMixin):
|
124 |
+
|
125 |
+
"""
|
126 |
+
Abstract base class for commands with the index_group options.
|
127 |
+
|
128 |
+
This also corresponds to the commands that permit the pip version check.
|
129 |
+
"""
|
130 |
+
|
131 |
+
def handle_pip_version_check(self, options: Values) -> None:
|
132 |
+
"""
|
133 |
+
Do the pip version check if not disabled.
|
134 |
+
|
135 |
+
This overrides the default behavior of not doing the check.
|
136 |
+
"""
|
137 |
+
# Make sure the index_group options are present.
|
138 |
+
assert hasattr(options, "no_index")
|
139 |
+
|
140 |
+
if options.disable_pip_version_check or options.no_index:
|
141 |
+
return
|
142 |
+
|
143 |
+
# Otherwise, check if we're using the latest version of pip available.
|
144 |
+
session = self._build_session(
|
145 |
+
options, retries=0, timeout=min(5, options.timeout)
|
146 |
+
)
|
147 |
+
with session:
|
148 |
+
pip_self_version_check(session, options)
|
149 |
+
|
150 |
+
|
151 |
+
KEEPABLE_TEMPDIR_TYPES = [
|
152 |
+
tempdir_kinds.BUILD_ENV,
|
153 |
+
tempdir_kinds.EPHEM_WHEEL_CACHE,
|
154 |
+
tempdir_kinds.REQ_BUILD,
|
155 |
+
]
|
156 |
+
|
157 |
+
|
158 |
+
def warn_if_run_as_root() -> None:
|
159 |
+
"""Output a warning for sudo users on Unix.
|
160 |
+
|
161 |
+
In a virtual environment, sudo pip still writes to virtualenv.
|
162 |
+
On Windows, users may run pip as Administrator without issues.
|
163 |
+
This warning only applies to Unix root users outside of virtualenv.
|
164 |
+
"""
|
165 |
+
if running_under_virtualenv():
|
166 |
+
return
|
167 |
+
if not hasattr(os, "getuid"):
|
168 |
+
return
|
169 |
+
# On Windows, there are no "system managed" Python packages. Installing as
|
170 |
+
# Administrator via pip is the correct way of updating system environments.
|
171 |
+
#
|
172 |
+
# We choose sys.platform over utils.compat.WINDOWS here to enable Mypy platform
|
173 |
+
# checks: https://mypy.readthedocs.io/en/stable/common_issues.html
|
174 |
+
if sys.platform == "win32" or sys.platform == "cygwin":
|
175 |
+
return
|
176 |
+
|
177 |
+
if os.getuid() != 0:
|
178 |
+
return
|
179 |
+
|
180 |
+
logger.warning(
|
181 |
+
"Running pip as the 'root' user can result in broken permissions and "
|
182 |
+
"conflicting behaviour with the system package manager. "
|
183 |
+
"It is recommended to use a virtual environment instead: "
|
184 |
+
"https://pip.pypa.io/warnings/venv"
|
185 |
+
)
|
186 |
+
|
187 |
+
|
188 |
+
def with_cleanup(func: Any) -> Any:
|
189 |
+
"""Decorator for common logic related to managing temporary
|
190 |
+
directories.
|
191 |
+
"""
|
192 |
+
|
193 |
+
def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None:
|
194 |
+
for t in KEEPABLE_TEMPDIR_TYPES:
|
195 |
+
registry.set_delete(t, False)
|
196 |
+
|
197 |
+
def wrapper(
|
198 |
+
self: RequirementCommand, options: Values, args: List[Any]
|
199 |
+
) -> Optional[int]:
|
200 |
+
assert self.tempdir_registry is not None
|
201 |
+
if options.no_clean:
|
202 |
+
configure_tempdir_registry(self.tempdir_registry)
|
203 |
+
|
204 |
+
try:
|
205 |
+
return func(self, options, args)
|
206 |
+
except PreviousBuildDirError:
|
207 |
+
# This kind of conflict can occur when the user passes an explicit
|
208 |
+
# build directory with a pre-existing folder. In that case we do
|
209 |
+
# not want to accidentally remove it.
|
210 |
+
configure_tempdir_registry(self.tempdir_registry)
|
211 |
+
raise
|
212 |
+
|
213 |
+
return wrapper
|
214 |
+
|
215 |
+
|
216 |
+
class RequirementCommand(IndexGroupCommand):
|
217 |
+
def __init__(self, *args: Any, **kw: Any) -> None:
|
218 |
+
super().__init__(*args, **kw)
|
219 |
+
|
220 |
+
self.cmd_opts.add_option(cmdoptions.no_clean())
|
221 |
+
|
222 |
+
@staticmethod
|
223 |
+
def determine_resolver_variant(options: Values) -> str:
|
224 |
+
"""Determines which resolver should be used, based on the given options."""
|
225 |
+
if "legacy-resolver" in options.deprecated_features_enabled:
|
226 |
+
return "legacy"
|
227 |
+
|
228 |
+
return "2020-resolver"
|
229 |
+
|
230 |
+
@staticmethod
|
231 |
+
def determine_build_failure_suppression(options: Values) -> bool:
|
232 |
+
"""Determines whether build failures should be suppressed and backtracked on."""
|
233 |
+
if "backtrack-on-build-failures" not in options.deprecated_features_enabled:
|
234 |
+
return False
|
235 |
+
|
236 |
+
if "legacy-resolver" in options.deprecated_features_enabled:
|
237 |
+
raise CommandError("Cannot backtrack with legacy resolver.")
|
238 |
+
|
239 |
+
deprecated(
|
240 |
+
reason=(
|
241 |
+
"Backtracking on build failures can mask issues related to how "
|
242 |
+
"a package generates metadata or builds a wheel. This flag will "
|
243 |
+
"be removed in pip 22.2."
|
244 |
+
),
|
245 |
+
gone_in=None,
|
246 |
+
replacement=(
|
247 |
+
"avoiding known-bad versions by explicitly telling pip to ignore them "
|
248 |
+
"(either directly as requirements, or via a constraints file)"
|
249 |
+
),
|
250 |
+
feature_flag=None,
|
251 |
+
issue=10655,
|
252 |
+
)
|
253 |
+
return True
|
254 |
+
|
255 |
+
@classmethod
|
256 |
+
def make_requirement_preparer(
|
257 |
+
cls,
|
258 |
+
temp_build_dir: TempDirectory,
|
259 |
+
options: Values,
|
260 |
+
req_tracker: RequirementTracker,
|
261 |
+
session: PipSession,
|
262 |
+
finder: PackageFinder,
|
263 |
+
use_user_site: bool,
|
264 |
+
download_dir: Optional[str] = None,
|
265 |
+
verbosity: int = 0,
|
266 |
+
) -> RequirementPreparer:
|
267 |
+
"""
|
268 |
+
Create a RequirementPreparer instance for the given parameters.
|
269 |
+
"""
|
270 |
+
temp_build_dir_path = temp_build_dir.path
|
271 |
+
assert temp_build_dir_path is not None
|
272 |
+
|
273 |
+
resolver_variant = cls.determine_resolver_variant(options)
|
274 |
+
if resolver_variant == "2020-resolver":
|
275 |
+
lazy_wheel = "fast-deps" in options.features_enabled
|
276 |
+
if lazy_wheel:
|
277 |
+
logger.warning(
|
278 |
+
"pip is using lazily downloaded wheels using HTTP "
|
279 |
+
"range requests to obtain dependency information. "
|
280 |
+
"This experimental feature is enabled through "
|
281 |
+
"--use-feature=fast-deps and it is not ready for "
|
282 |
+
"production."
|
283 |
+
)
|
284 |
+
else:
|
285 |
+
lazy_wheel = False
|
286 |
+
if "fast-deps" in options.features_enabled:
|
287 |
+
logger.warning(
|
288 |
+
"fast-deps has no effect when used with the legacy resolver."
|
289 |
+
)
|
290 |
+
|
291 |
+
in_tree_build = "out-of-tree-build" not in options.deprecated_features_enabled
|
292 |
+
if "in-tree-build" in options.features_enabled:
|
293 |
+
deprecated(
|
294 |
+
reason="In-tree builds are now the default.",
|
295 |
+
replacement="to remove the --use-feature=in-tree-build flag",
|
296 |
+
gone_in="22.1",
|
297 |
+
)
|
298 |
+
if "out-of-tree-build" in options.deprecated_features_enabled:
|
299 |
+
deprecated(
|
300 |
+
reason="Out-of-tree builds are deprecated.",
|
301 |
+
replacement=None,
|
302 |
+
gone_in="22.1",
|
303 |
+
)
|
304 |
+
|
305 |
+
if options.progress_bar not in {"on", "off"}:
|
306 |
+
deprecated(
|
307 |
+
reason="Custom progress bar styles are deprecated",
|
308 |
+
replacement="to use the default progress bar style.",
|
309 |
+
gone_in="22.1",
|
310 |
+
)
|
311 |
+
|
312 |
+
return RequirementPreparer(
|
313 |
+
build_dir=temp_build_dir_path,
|
314 |
+
src_dir=options.src_dir,
|
315 |
+
download_dir=download_dir,
|
316 |
+
build_isolation=options.build_isolation,
|
317 |
+
req_tracker=req_tracker,
|
318 |
+
session=session,
|
319 |
+
progress_bar=options.progress_bar,
|
320 |
+
finder=finder,
|
321 |
+
require_hashes=options.require_hashes,
|
322 |
+
use_user_site=use_user_site,
|
323 |
+
lazy_wheel=lazy_wheel,
|
324 |
+
verbosity=verbosity,
|
325 |
+
in_tree_build=in_tree_build,
|
326 |
+
)
|
327 |
+
|
328 |
+
@classmethod
|
329 |
+
def make_resolver(
|
330 |
+
cls,
|
331 |
+
preparer: RequirementPreparer,
|
332 |
+
finder: PackageFinder,
|
333 |
+
options: Values,
|
334 |
+
wheel_cache: Optional[WheelCache] = None,
|
335 |
+
use_user_site: bool = False,
|
336 |
+
ignore_installed: bool = True,
|
337 |
+
ignore_requires_python: bool = False,
|
338 |
+
force_reinstall: bool = False,
|
339 |
+
upgrade_strategy: str = "to-satisfy-only",
|
340 |
+
use_pep517: Optional[bool] = None,
|
341 |
+
py_version_info: Optional[Tuple[int, ...]] = None,
|
342 |
+
) -> BaseResolver:
|
343 |
+
"""
|
344 |
+
Create a Resolver instance for the given parameters.
|
345 |
+
"""
|
346 |
+
make_install_req = partial(
|
347 |
+
install_req_from_req_string,
|
348 |
+
isolated=options.isolated_mode,
|
349 |
+
use_pep517=use_pep517,
|
350 |
+
)
|
351 |
+
suppress_build_failures = cls.determine_build_failure_suppression(options)
|
352 |
+
resolver_variant = cls.determine_resolver_variant(options)
|
353 |
+
# The long import name and duplicated invocation is needed to convince
|
354 |
+
# Mypy into correctly typechecking. Otherwise it would complain the
|
355 |
+
# "Resolver" class being redefined.
|
356 |
+
if resolver_variant == "2020-resolver":
|
357 |
+
import pip._internal.resolution.resolvelib.resolver
|
358 |
+
|
359 |
+
return pip._internal.resolution.resolvelib.resolver.Resolver(
|
360 |
+
preparer=preparer,
|
361 |
+
finder=finder,
|
362 |
+
wheel_cache=wheel_cache,
|
363 |
+
make_install_req=make_install_req,
|
364 |
+
use_user_site=use_user_site,
|
365 |
+
ignore_dependencies=options.ignore_dependencies,
|
366 |
+
ignore_installed=ignore_installed,
|
367 |
+
ignore_requires_python=ignore_requires_python,
|
368 |
+
force_reinstall=force_reinstall,
|
369 |
+
upgrade_strategy=upgrade_strategy,
|
370 |
+
py_version_info=py_version_info,
|
371 |
+
suppress_build_failures=suppress_build_failures,
|
372 |
+
)
|
373 |
+
import pip._internal.resolution.legacy.resolver
|
374 |
+
|
375 |
+
return pip._internal.resolution.legacy.resolver.Resolver(
|
376 |
+
preparer=preparer,
|
377 |
+
finder=finder,
|
378 |
+
wheel_cache=wheel_cache,
|
379 |
+
make_install_req=make_install_req,
|
380 |
+
use_user_site=use_user_site,
|
381 |
+
ignore_dependencies=options.ignore_dependencies,
|
382 |
+
ignore_installed=ignore_installed,
|
383 |
+
ignore_requires_python=ignore_requires_python,
|
384 |
+
force_reinstall=force_reinstall,
|
385 |
+
upgrade_strategy=upgrade_strategy,
|
386 |
+
py_version_info=py_version_info,
|
387 |
+
)
|
388 |
+
|
389 |
+
def get_requirements(
|
390 |
+
self,
|
391 |
+
args: List[str],
|
392 |
+
options: Values,
|
393 |
+
finder: PackageFinder,
|
394 |
+
session: PipSession,
|
395 |
+
) -> List[InstallRequirement]:
|
396 |
+
"""
|
397 |
+
Parse command-line arguments into the corresponding requirements.
|
398 |
+
"""
|
399 |
+
requirements: List[InstallRequirement] = []
|
400 |
+
for filename in options.constraints:
|
401 |
+
for parsed_req in parse_requirements(
|
402 |
+
filename,
|
403 |
+
constraint=True,
|
404 |
+
finder=finder,
|
405 |
+
options=options,
|
406 |
+
session=session,
|
407 |
+
):
|
408 |
+
req_to_add = install_req_from_parsed_requirement(
|
409 |
+
parsed_req,
|
410 |
+
isolated=options.isolated_mode,
|
411 |
+
user_supplied=False,
|
412 |
+
)
|
413 |
+
requirements.append(req_to_add)
|
414 |
+
|
415 |
+
for req in args:
|
416 |
+
req_to_add = install_req_from_line(
|
417 |
+
req,
|
418 |
+
None,
|
419 |
+
isolated=options.isolated_mode,
|
420 |
+
use_pep517=options.use_pep517,
|
421 |
+
user_supplied=True,
|
422 |
+
)
|
423 |
+
requirements.append(req_to_add)
|
424 |
+
|
425 |
+
for req in options.editables:
|
426 |
+
req_to_add = install_req_from_editable(
|
427 |
+
req,
|
428 |
+
user_supplied=True,
|
429 |
+
isolated=options.isolated_mode,
|
430 |
+
use_pep517=options.use_pep517,
|
431 |
+
)
|
432 |
+
requirements.append(req_to_add)
|
433 |
+
|
434 |
+
# NOTE: options.require_hashes may be set if --require-hashes is True
|
435 |
+
for filename in options.requirements:
|
436 |
+
for parsed_req in parse_requirements(
|
437 |
+
filename, finder=finder, options=options, session=session
|
438 |
+
):
|
439 |
+
req_to_add = install_req_from_parsed_requirement(
|
440 |
+
parsed_req,
|
441 |
+
isolated=options.isolated_mode,
|
442 |
+
use_pep517=options.use_pep517,
|
443 |
+
user_supplied=True,
|
444 |
+
)
|
445 |
+
requirements.append(req_to_add)
|
446 |
+
|
447 |
+
# If any requirement has hash options, enable hash checking.
|
448 |
+
if any(req.has_hash_options for req in requirements):
|
449 |
+
options.require_hashes = True
|
450 |
+
|
451 |
+
if not (args or options.editables or options.requirements):
|
452 |
+
opts = {"name": self.name}
|
453 |
+
if options.find_links:
|
454 |
+
raise CommandError(
|
455 |
+
"You must give at least one requirement to {name} "
|
456 |
+
'(maybe you meant "pip {name} {links}"?)'.format(
|
457 |
+
**dict(opts, links=" ".join(options.find_links))
|
458 |
+
)
|
459 |
+
)
|
460 |
+
else:
|
461 |
+
raise CommandError(
|
462 |
+
"You must give at least one requirement to {name} "
|
463 |
+
'(see "pip help {name}")'.format(**opts)
|
464 |
+
)
|
465 |
+
|
466 |
+
return requirements
|
467 |
+
|
468 |
+
@staticmethod
|
469 |
+
def trace_basic_info(finder: PackageFinder) -> None:
|
470 |
+
"""
|
471 |
+
Trace basic information about the provided objects.
|
472 |
+
"""
|
473 |
+
# Display where finder is looking for packages
|
474 |
+
search_scope = finder.search_scope
|
475 |
+
locations = search_scope.get_formatted_locations()
|
476 |
+
if locations:
|
477 |
+
logger.info(locations)
|
478 |
+
|
479 |
+
def _build_package_finder(
|
480 |
+
self,
|
481 |
+
options: Values,
|
482 |
+
session: PipSession,
|
483 |
+
target_python: Optional[TargetPython] = None,
|
484 |
+
ignore_requires_python: Optional[bool] = None,
|
485 |
+
) -> PackageFinder:
|
486 |
+
"""
|
487 |
+
Create a package finder appropriate to this requirement command.
|
488 |
+
|
489 |
+
:param ignore_requires_python: Whether to ignore incompatible
|
490 |
+
"Requires-Python" values in links. Defaults to False.
|
491 |
+
"""
|
492 |
+
link_collector = LinkCollector.create(session, options=options)
|
493 |
+
selection_prefs = SelectionPreferences(
|
494 |
+
allow_yanked=True,
|
495 |
+
format_control=options.format_control,
|
496 |
+
allow_all_prereleases=options.pre,
|
497 |
+
prefer_binary=options.prefer_binary,
|
498 |
+
ignore_requires_python=ignore_requires_python,
|
499 |
+
)
|
500 |
+
|
501 |
+
return PackageFinder.create(
|
502 |
+
link_collector=link_collector,
|
503 |
+
selection_prefs=selection_prefs,
|
504 |
+
target_python=target_python,
|
505 |
+
use_deprecated_html5lib="html5lib" in options.deprecated_features_enabled,
|
506 |
+
)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/spinners.py
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import contextlib
|
2 |
+
import itertools
|
3 |
+
import logging
|
4 |
+
import sys
|
5 |
+
import time
|
6 |
+
from typing import IO, Iterator
|
7 |
+
|
8 |
+
from pip._vendor.progress import HIDE_CURSOR, SHOW_CURSOR
|
9 |
+
|
10 |
+
from pip._internal.utils.compat import WINDOWS
|
11 |
+
from pip._internal.utils.logging import get_indentation
|
12 |
+
|
13 |
+
logger = logging.getLogger(__name__)
|
14 |
+
|
15 |
+
|
16 |
+
class SpinnerInterface:
|
17 |
+
def spin(self) -> None:
|
18 |
+
raise NotImplementedError()
|
19 |
+
|
20 |
+
def finish(self, final_status: str) -> None:
|
21 |
+
raise NotImplementedError()
|
22 |
+
|
23 |
+
|
24 |
+
class InteractiveSpinner(SpinnerInterface):
|
25 |
+
def __init__(
|
26 |
+
self,
|
27 |
+
message: str,
|
28 |
+
file: IO[str] = None,
|
29 |
+
spin_chars: str = "-\\|/",
|
30 |
+
# Empirically, 8 updates/second looks nice
|
31 |
+
min_update_interval_seconds: float = 0.125,
|
32 |
+
):
|
33 |
+
self._message = message
|
34 |
+
if file is None:
|
35 |
+
file = sys.stdout
|
36 |
+
self._file = file
|
37 |
+
self._rate_limiter = RateLimiter(min_update_interval_seconds)
|
38 |
+
self._finished = False
|
39 |
+
|
40 |
+
self._spin_cycle = itertools.cycle(spin_chars)
|
41 |
+
|
42 |
+
self._file.write(" " * get_indentation() + self._message + " ... ")
|
43 |
+
self._width = 0
|
44 |
+
|
45 |
+
def _write(self, status: str) -> None:
|
46 |
+
assert not self._finished
|
47 |
+
# Erase what we wrote before by backspacing to the beginning, writing
|
48 |
+
# spaces to overwrite the old text, and then backspacing again
|
49 |
+
backup = "\b" * self._width
|
50 |
+
self._file.write(backup + " " * self._width + backup)
|
51 |
+
# Now we have a blank slate to add our status
|
52 |
+
self._file.write(status)
|
53 |
+
self._width = len(status)
|
54 |
+
self._file.flush()
|
55 |
+
self._rate_limiter.reset()
|
56 |
+
|
57 |
+
def spin(self) -> None:
|
58 |
+
if self._finished:
|
59 |
+
return
|
60 |
+
if not self._rate_limiter.ready():
|
61 |
+
return
|
62 |
+
self._write(next(self._spin_cycle))
|
63 |
+
|
64 |
+
def finish(self, final_status: str) -> None:
|
65 |
+
if self._finished:
|
66 |
+
return
|
67 |
+
self._write(final_status)
|
68 |
+
self._file.write("\n")
|
69 |
+
self._file.flush()
|
70 |
+
self._finished = True
|
71 |
+
|
72 |
+
|
73 |
+
# Used for dumb terminals, non-interactive installs (no tty), etc.
|
74 |
+
# We still print updates occasionally (once every 60 seconds by default) to
|
75 |
+
# act as a keep-alive for systems like Travis-CI that take lack-of-output as
|
76 |
+
# an indication that a task has frozen.
|
77 |
+
class NonInteractiveSpinner(SpinnerInterface):
|
78 |
+
def __init__(self, message: str, min_update_interval_seconds: float = 60.0) -> None:
|
79 |
+
self._message = message
|
80 |
+
self._finished = False
|
81 |
+
self._rate_limiter = RateLimiter(min_update_interval_seconds)
|
82 |
+
self._update("started")
|
83 |
+
|
84 |
+
def _update(self, status: str) -> None:
|
85 |
+
assert not self._finished
|
86 |
+
self._rate_limiter.reset()
|
87 |
+
logger.info("%s: %s", self._message, status)
|
88 |
+
|
89 |
+
def spin(self) -> None:
|
90 |
+
if self._finished:
|
91 |
+
return
|
92 |
+
if not self._rate_limiter.ready():
|
93 |
+
return
|
94 |
+
self._update("still running...")
|
95 |
+
|
96 |
+
def finish(self, final_status: str) -> None:
|
97 |
+
if self._finished:
|
98 |
+
return
|
99 |
+
self._update(f"finished with status '{final_status}'")
|
100 |
+
self._finished = True
|
101 |
+
|
102 |
+
|
103 |
+
class RateLimiter:
|
104 |
+
def __init__(self, min_update_interval_seconds: float) -> None:
|
105 |
+
self._min_update_interval_seconds = min_update_interval_seconds
|
106 |
+
self._last_update: float = 0
|
107 |
+
|
108 |
+
def ready(self) -> bool:
|
109 |
+
now = time.time()
|
110 |
+
delta = now - self._last_update
|
111 |
+
return delta >= self._min_update_interval_seconds
|
112 |
+
|
113 |
+
def reset(self) -> None:
|
114 |
+
self._last_update = time.time()
|
115 |
+
|
116 |
+
|
117 |
+
@contextlib.contextmanager
|
118 |
+
def open_spinner(message: str) -> Iterator[SpinnerInterface]:
|
119 |
+
# Interactive spinner goes directly to sys.stdout rather than being routed
|
120 |
+
# through the logging system, but it acts like it has level INFO,
|
121 |
+
# i.e. it's only displayed if we're at level INFO or better.
|
122 |
+
# Non-interactive spinner goes through the logging system, so it is always
|
123 |
+
# in sync with logging configuration.
|
124 |
+
if sys.stdout.isatty() and logger.getEffectiveLevel() <= logging.INFO:
|
125 |
+
spinner: SpinnerInterface = InteractiveSpinner(message)
|
126 |
+
else:
|
127 |
+
spinner = NonInteractiveSpinner(message)
|
128 |
+
try:
|
129 |
+
with hidden_cursor(sys.stdout):
|
130 |
+
yield spinner
|
131 |
+
except KeyboardInterrupt:
|
132 |
+
spinner.finish("canceled")
|
133 |
+
raise
|
134 |
+
except Exception:
|
135 |
+
spinner.finish("error")
|
136 |
+
raise
|
137 |
+
else:
|
138 |
+
spinner.finish("done")
|
139 |
+
|
140 |
+
|
141 |
+
@contextlib.contextmanager
|
142 |
+
def hidden_cursor(file: IO[str]) -> Iterator[None]:
|
143 |
+
# The Windows terminal does not support the hide/show cursor ANSI codes,
|
144 |
+
# even via colorama. So don't even try.
|
145 |
+
if WINDOWS:
|
146 |
+
yield
|
147 |
+
# We don't want to clutter the output with control characters if we're
|
148 |
+
# writing to a file, or if the user is running with --quiet.
|
149 |
+
# See https://github.com/pypa/pip/issues/3418
|
150 |
+
elif not file.isatty() or logger.getEffectiveLevel() > logging.INFO:
|
151 |
+
yield
|
152 |
+
else:
|
153 |
+
file.write(HIDE_CURSOR)
|
154 |
+
try:
|
155 |
+
yield
|
156 |
+
finally:
|
157 |
+
file.write(SHOW_CURSOR)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/cli/status_codes.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
SUCCESS = 0
|
2 |
+
ERROR = 1
|
3 |
+
UNKNOWN_ERROR = 2
|
4 |
+
VIRTUALENV_NOT_FOUND = 3
|
5 |
+
PREVIOUS_BUILD_DIR_ERROR = 4
|
6 |
+
NO_MATCHES_FOUND = 23
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/configuration.py
ADDED
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Configuration management setup
|
2 |
+
|
3 |
+
Some terminology:
|
4 |
+
- name
|
5 |
+
As written in config files.
|
6 |
+
- value
|
7 |
+
Value associated with a name
|
8 |
+
- key
|
9 |
+
Name combined with it's section (section.name)
|
10 |
+
- variant
|
11 |
+
A single word describing where the configuration key-value pair came from
|
12 |
+
"""
|
13 |
+
|
14 |
+
import configparser
|
15 |
+
import locale
|
16 |
+
import os
|
17 |
+
import sys
|
18 |
+
from typing import Any, Dict, Iterable, List, NewType, Optional, Tuple
|
19 |
+
|
20 |
+
from pip._internal.exceptions import (
|
21 |
+
ConfigurationError,
|
22 |
+
ConfigurationFileCouldNotBeLoaded,
|
23 |
+
)
|
24 |
+
from pip._internal.utils import appdirs
|
25 |
+
from pip._internal.utils.compat import WINDOWS
|
26 |
+
from pip._internal.utils.logging import getLogger
|
27 |
+
from pip._internal.utils.misc import ensure_dir, enum
|
28 |
+
|
29 |
+
RawConfigParser = configparser.RawConfigParser # Shorthand
|
30 |
+
Kind = NewType("Kind", str)
|
31 |
+
|
32 |
+
CONFIG_BASENAME = "pip.ini" if WINDOWS else "pip.conf"
|
33 |
+
ENV_NAMES_IGNORED = "version", "help"
|
34 |
+
|
35 |
+
# The kinds of configurations there are.
|
36 |
+
kinds = enum(
|
37 |
+
USER="user", # User Specific
|
38 |
+
GLOBAL="global", # System Wide
|
39 |
+
SITE="site", # [Virtual] Environment Specific
|
40 |
+
ENV="env", # from PIP_CONFIG_FILE
|
41 |
+
ENV_VAR="env-var", # from Environment Variables
|
42 |
+
)
|
43 |
+
OVERRIDE_ORDER = kinds.GLOBAL, kinds.USER, kinds.SITE, kinds.ENV, kinds.ENV_VAR
|
44 |
+
VALID_LOAD_ONLY = kinds.USER, kinds.GLOBAL, kinds.SITE
|
45 |
+
|
46 |
+
logger = getLogger(__name__)
|
47 |
+
|
48 |
+
|
49 |
+
# NOTE: Maybe use the optionx attribute to normalize keynames.
|
50 |
+
def _normalize_name(name: str) -> str:
|
51 |
+
"""Make a name consistent regardless of source (environment or file)"""
|
52 |
+
name = name.lower().replace("_", "-")
|
53 |
+
if name.startswith("--"):
|
54 |
+
name = name[2:] # only prefer long opts
|
55 |
+
return name
|
56 |
+
|
57 |
+
|
58 |
+
def _disassemble_key(name: str) -> List[str]:
|
59 |
+
if "." not in name:
|
60 |
+
error_message = (
|
61 |
+
"Key does not contain dot separated section and key. "
|
62 |
+
"Perhaps you wanted to use 'global.{}' instead?"
|
63 |
+
).format(name)
|
64 |
+
raise ConfigurationError(error_message)
|
65 |
+
return name.split(".", 1)
|
66 |
+
|
67 |
+
|
68 |
+
def get_configuration_files() -> Dict[Kind, List[str]]:
|
69 |
+
global_config_files = [
|
70 |
+
os.path.join(path, CONFIG_BASENAME) for path in appdirs.site_config_dirs("pip")
|
71 |
+
]
|
72 |
+
|
73 |
+
site_config_file = os.path.join(sys.prefix, CONFIG_BASENAME)
|
74 |
+
legacy_config_file = os.path.join(
|
75 |
+
os.path.expanduser("~"),
|
76 |
+
"pip" if WINDOWS else ".pip",
|
77 |
+
CONFIG_BASENAME,
|
78 |
+
)
|
79 |
+
new_config_file = os.path.join(appdirs.user_config_dir("pip"), CONFIG_BASENAME)
|
80 |
+
return {
|
81 |
+
kinds.GLOBAL: global_config_files,
|
82 |
+
kinds.SITE: [site_config_file],
|
83 |
+
kinds.USER: [legacy_config_file, new_config_file],
|
84 |
+
}
|
85 |
+
|
86 |
+
|
87 |
+
class Configuration:
|
88 |
+
"""Handles management of configuration.
|
89 |
+
|
90 |
+
Provides an interface to accessing and managing configuration files.
|
91 |
+
|
92 |
+
This class converts provides an API that takes "section.key-name" style
|
93 |
+
keys and stores the value associated with it as "key-name" under the
|
94 |
+
section "section".
|
95 |
+
|
96 |
+
This allows for a clean interface wherein the both the section and the
|
97 |
+
key-name are preserved in an easy to manage form in the configuration files
|
98 |
+
and the data stored is also nice.
|
99 |
+
"""
|
100 |
+
|
101 |
+
def __init__(self, isolated: bool, load_only: Optional[Kind] = None) -> None:
|
102 |
+
super().__init__()
|
103 |
+
|
104 |
+
if load_only is not None and load_only not in VALID_LOAD_ONLY:
|
105 |
+
raise ConfigurationError(
|
106 |
+
"Got invalid value for load_only - should be one of {}".format(
|
107 |
+
", ".join(map(repr, VALID_LOAD_ONLY))
|
108 |
+
)
|
109 |
+
)
|
110 |
+
self.isolated = isolated
|
111 |
+
self.load_only = load_only
|
112 |
+
|
113 |
+
# Because we keep track of where we got the data from
|
114 |
+
self._parsers: Dict[Kind, List[Tuple[str, RawConfigParser]]] = {
|
115 |
+
variant: [] for variant in OVERRIDE_ORDER
|
116 |
+
}
|
117 |
+
self._config: Dict[Kind, Dict[str, Any]] = {
|
118 |
+
variant: {} for variant in OVERRIDE_ORDER
|
119 |
+
}
|
120 |
+
self._modified_parsers: List[Tuple[str, RawConfigParser]] = []
|
121 |
+
|
122 |
+
def load(self) -> None:
|
123 |
+
"""Loads configuration from configuration files and environment"""
|
124 |
+
self._load_config_files()
|
125 |
+
if not self.isolated:
|
126 |
+
self._load_environment_vars()
|
127 |
+
|
128 |
+
def get_file_to_edit(self) -> Optional[str]:
|
129 |
+
"""Returns the file with highest priority in configuration"""
|
130 |
+
assert self.load_only is not None, "Need to be specified a file to be editing"
|
131 |
+
|
132 |
+
try:
|
133 |
+
return self._get_parser_to_modify()[0]
|
134 |
+
except IndexError:
|
135 |
+
return None
|
136 |
+
|
137 |
+
def items(self) -> Iterable[Tuple[str, Any]]:
|
138 |
+
"""Returns key-value pairs like dict.items() representing the loaded
|
139 |
+
configuration
|
140 |
+
"""
|
141 |
+
return self._dictionary.items()
|
142 |
+
|
143 |
+
def get_value(self, key: str) -> Any:
|
144 |
+
"""Get a value from the configuration."""
|
145 |
+
try:
|
146 |
+
return self._dictionary[key]
|
147 |
+
except KeyError:
|
148 |
+
raise ConfigurationError(f"No such key - {key}")
|
149 |
+
|
150 |
+
def set_value(self, key: str, value: Any) -> None:
|
151 |
+
"""Modify a value in the configuration."""
|
152 |
+
self._ensure_have_load_only()
|
153 |
+
|
154 |
+
assert self.load_only
|
155 |
+
fname, parser = self._get_parser_to_modify()
|
156 |
+
|
157 |
+
if parser is not None:
|
158 |
+
section, name = _disassemble_key(key)
|
159 |
+
|
160 |
+
# Modify the parser and the configuration
|
161 |
+
if not parser.has_section(section):
|
162 |
+
parser.add_section(section)
|
163 |
+
parser.set(section, name, value)
|
164 |
+
|
165 |
+
self._config[self.load_only][key] = value
|
166 |
+
self._mark_as_modified(fname, parser)
|
167 |
+
|
168 |
+
def unset_value(self, key: str) -> None:
|
169 |
+
"""Unset a value in the configuration."""
|
170 |
+
self._ensure_have_load_only()
|
171 |
+
|
172 |
+
assert self.load_only
|
173 |
+
if key not in self._config[self.load_only]:
|
174 |
+
raise ConfigurationError(f"No such key - {key}")
|
175 |
+
|
176 |
+
fname, parser = self._get_parser_to_modify()
|
177 |
+
|
178 |
+
if parser is not None:
|
179 |
+
section, name = _disassemble_key(key)
|
180 |
+
if not (
|
181 |
+
parser.has_section(section) and parser.remove_option(section, name)
|
182 |
+
):
|
183 |
+
# The option was not removed.
|
184 |
+
raise ConfigurationError(
|
185 |
+
"Fatal Internal error [id=1]. Please report as a bug."
|
186 |
+
)
|
187 |
+
|
188 |
+
# The section may be empty after the option was removed.
|
189 |
+
if not parser.items(section):
|
190 |
+
parser.remove_section(section)
|
191 |
+
self._mark_as_modified(fname, parser)
|
192 |
+
|
193 |
+
del self._config[self.load_only][key]
|
194 |
+
|
195 |
+
def save(self) -> None:
|
196 |
+
"""Save the current in-memory state."""
|
197 |
+
self._ensure_have_load_only()
|
198 |
+
|
199 |
+
for fname, parser in self._modified_parsers:
|
200 |
+
logger.info("Writing to %s", fname)
|
201 |
+
|
202 |
+
# Ensure directory exists.
|
203 |
+
ensure_dir(os.path.dirname(fname))
|
204 |
+
|
205 |
+
with open(fname, "w") as f:
|
206 |
+
parser.write(f)
|
207 |
+
|
208 |
+
#
|
209 |
+
# Private routines
|
210 |
+
#
|
211 |
+
|
212 |
+
def _ensure_have_load_only(self) -> None:
|
213 |
+
if self.load_only is None:
|
214 |
+
raise ConfigurationError("Needed a specific file to be modifying.")
|
215 |
+
logger.debug("Will be working with %s variant only", self.load_only)
|
216 |
+
|
217 |
+
@property
|
218 |
+
def _dictionary(self) -> Dict[str, Any]:
|
219 |
+
"""A dictionary representing the loaded configuration."""
|
220 |
+
# NOTE: Dictionaries are not populated if not loaded. So, conditionals
|
221 |
+
# are not needed here.
|
222 |
+
retval = {}
|
223 |
+
|
224 |
+
for variant in OVERRIDE_ORDER:
|
225 |
+
retval.update(self._config[variant])
|
226 |
+
|
227 |
+
return retval
|
228 |
+
|
229 |
+
def _load_config_files(self) -> None:
|
230 |
+
"""Loads configuration from configuration files"""
|
231 |
+
config_files = dict(self.iter_config_files())
|
232 |
+
if config_files[kinds.ENV][0:1] == [os.devnull]:
|
233 |
+
logger.debug(
|
234 |
+
"Skipping loading configuration files due to "
|
235 |
+
"environment's PIP_CONFIG_FILE being os.devnull"
|
236 |
+
)
|
237 |
+
return
|
238 |
+
|
239 |
+
for variant, files in config_files.items():
|
240 |
+
for fname in files:
|
241 |
+
# If there's specific variant set in `load_only`, load only
|
242 |
+
# that variant, not the others.
|
243 |
+
if self.load_only is not None and variant != self.load_only:
|
244 |
+
logger.debug("Skipping file '%s' (variant: %s)", fname, variant)
|
245 |
+
continue
|
246 |
+
|
247 |
+
parser = self._load_file(variant, fname)
|
248 |
+
|
249 |
+
# Keeping track of the parsers used
|
250 |
+
self._parsers[variant].append((fname, parser))
|
251 |
+
|
252 |
+
def _load_file(self, variant: Kind, fname: str) -> RawConfigParser:
|
253 |
+
logger.verbose("For variant '%s', will try loading '%s'", variant, fname)
|
254 |
+
parser = self._construct_parser(fname)
|
255 |
+
|
256 |
+
for section in parser.sections():
|
257 |
+
items = parser.items(section)
|
258 |
+
self._config[variant].update(self._normalized_keys(section, items))
|
259 |
+
|
260 |
+
return parser
|
261 |
+
|
262 |
+
def _construct_parser(self, fname: str) -> RawConfigParser:
|
263 |
+
parser = configparser.RawConfigParser()
|
264 |
+
# If there is no such file, don't bother reading it but create the
|
265 |
+
# parser anyway, to hold the data.
|
266 |
+
# Doing this is useful when modifying and saving files, where we don't
|
267 |
+
# need to construct a parser.
|
268 |
+
if os.path.exists(fname):
|
269 |
+
locale_encoding = locale.getpreferredencoding(False)
|
270 |
+
try:
|
271 |
+
parser.read(fname, encoding=locale_encoding)
|
272 |
+
except UnicodeDecodeError:
|
273 |
+
# See https://github.com/pypa/pip/issues/4963
|
274 |
+
raise ConfigurationFileCouldNotBeLoaded(
|
275 |
+
reason=f"contains invalid {locale_encoding} characters",
|
276 |
+
fname=fname,
|
277 |
+
)
|
278 |
+
except configparser.Error as error:
|
279 |
+
# See https://github.com/pypa/pip/issues/4893
|
280 |
+
raise ConfigurationFileCouldNotBeLoaded(error=error)
|
281 |
+
return parser
|
282 |
+
|
283 |
+
def _load_environment_vars(self) -> None:
|
284 |
+
"""Loads configuration from environment variables"""
|
285 |
+
self._config[kinds.ENV_VAR].update(
|
286 |
+
self._normalized_keys(":env:", self.get_environ_vars())
|
287 |
+
)
|
288 |
+
|
289 |
+
def _normalized_keys(
|
290 |
+
self, section: str, items: Iterable[Tuple[str, Any]]
|
291 |
+
) -> Dict[str, Any]:
|
292 |
+
"""Normalizes items to construct a dictionary with normalized keys.
|
293 |
+
|
294 |
+
This routine is where the names become keys and are made the same
|
295 |
+
regardless of source - configuration files or environment.
|
296 |
+
"""
|
297 |
+
normalized = {}
|
298 |
+
for name, val in items:
|
299 |
+
key = section + "." + _normalize_name(name)
|
300 |
+
normalized[key] = val
|
301 |
+
return normalized
|
302 |
+
|
303 |
+
def get_environ_vars(self) -> Iterable[Tuple[str, str]]:
|
304 |
+
"""Returns a generator with all environmental vars with prefix PIP_"""
|
305 |
+
for key, val in os.environ.items():
|
306 |
+
if key.startswith("PIP_"):
|
307 |
+
name = key[4:].lower()
|
308 |
+
if name not in ENV_NAMES_IGNORED:
|
309 |
+
yield name, val
|
310 |
+
|
311 |
+
# XXX: This is patched in the tests.
|
312 |
+
def iter_config_files(self) -> Iterable[Tuple[Kind, List[str]]]:
|
313 |
+
"""Yields variant and configuration files associated with it.
|
314 |
+
|
315 |
+
This should be treated like items of a dictionary.
|
316 |
+
"""
|
317 |
+
# SMELL: Move the conditions out of this function
|
318 |
+
|
319 |
+
# environment variables have the lowest priority
|
320 |
+
config_file = os.environ.get("PIP_CONFIG_FILE", None)
|
321 |
+
if config_file is not None:
|
322 |
+
yield kinds.ENV, [config_file]
|
323 |
+
else:
|
324 |
+
yield kinds.ENV, []
|
325 |
+
|
326 |
+
config_files = get_configuration_files()
|
327 |
+
|
328 |
+
# at the base we have any global configuration
|
329 |
+
yield kinds.GLOBAL, config_files[kinds.GLOBAL]
|
330 |
+
|
331 |
+
# per-user configuration next
|
332 |
+
should_load_user_config = not self.isolated and not (
|
333 |
+
config_file and os.path.exists(config_file)
|
334 |
+
)
|
335 |
+
if should_load_user_config:
|
336 |
+
# The legacy config file is overridden by the new config file
|
337 |
+
yield kinds.USER, config_files[kinds.USER]
|
338 |
+
|
339 |
+
# finally virtualenv configuration first trumping others
|
340 |
+
yield kinds.SITE, config_files[kinds.SITE]
|
341 |
+
|
342 |
+
def get_values_in_config(self, variant: Kind) -> Dict[str, Any]:
|
343 |
+
"""Get values present in a config file"""
|
344 |
+
return self._config[variant]
|
345 |
+
|
346 |
+
def _get_parser_to_modify(self) -> Tuple[str, RawConfigParser]:
|
347 |
+
# Determine which parser to modify
|
348 |
+
assert self.load_only
|
349 |
+
parsers = self._parsers[self.load_only]
|
350 |
+
if not parsers:
|
351 |
+
# This should not happen if everything works correctly.
|
352 |
+
raise ConfigurationError(
|
353 |
+
"Fatal Internal error [id=2]. Please report as a bug."
|
354 |
+
)
|
355 |
+
|
356 |
+
# Use the highest priority parser.
|
357 |
+
return parsers[-1]
|
358 |
+
|
359 |
+
# XXX: This is patched in the tests.
|
360 |
+
def _mark_as_modified(self, fname: str, parser: RawConfigParser) -> None:
|
361 |
+
file_parser_tuple = (fname, parser)
|
362 |
+
if file_parser_tuple not in self._modified_parsers:
|
363 |
+
self._modified_parsers.append(file_parser_tuple)
|
364 |
+
|
365 |
+
def __repr__(self) -> str:
|
366 |
+
return f"{self.__class__.__name__}({self._dictionary!r})"
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/exceptions.py
ADDED
@@ -0,0 +1,658 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Exceptions used throughout package.
|
2 |
+
|
3 |
+
This module MUST NOT try to import from anything within `pip._internal` to
|
4 |
+
operate. This is expected to be importable from any/all files within the
|
5 |
+
subpackage and, thus, should not depend on them.
|
6 |
+
"""
|
7 |
+
|
8 |
+
import configparser
|
9 |
+
import re
|
10 |
+
from itertools import chain, groupby, repeat
|
11 |
+
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
12 |
+
|
13 |
+
from pip._vendor.requests.models import Request, Response
|
14 |
+
from pip._vendor.rich.console import Console, ConsoleOptions, RenderResult
|
15 |
+
from pip._vendor.rich.markup import escape
|
16 |
+
from pip._vendor.rich.text import Text
|
17 |
+
|
18 |
+
if TYPE_CHECKING:
|
19 |
+
from hashlib import _Hash
|
20 |
+
from typing import Literal
|
21 |
+
|
22 |
+
from pip._internal.metadata import BaseDistribution
|
23 |
+
from pip._internal.req.req_install import InstallRequirement
|
24 |
+
|
25 |
+
|
26 |
+
#
|
27 |
+
# Scaffolding
|
28 |
+
#
|
29 |
+
def _is_kebab_case(s: str) -> bool:
|
30 |
+
return re.match(r"^[a-z]+(-[a-z]+)*$", s) is not None
|
31 |
+
|
32 |
+
|
33 |
+
def _prefix_with_indent(
|
34 |
+
s: Union[Text, str],
|
35 |
+
console: Console,
|
36 |
+
*,
|
37 |
+
prefix: str,
|
38 |
+
indent: str,
|
39 |
+
) -> Text:
|
40 |
+
if isinstance(s, Text):
|
41 |
+
text = s
|
42 |
+
else:
|
43 |
+
text = console.render_str(s)
|
44 |
+
|
45 |
+
return console.render_str(prefix, overflow="ignore") + console.render_str(
|
46 |
+
f"\n{indent}", overflow="ignore"
|
47 |
+
).join(text.split(allow_blank=True))
|
48 |
+
|
49 |
+
|
50 |
+
class PipError(Exception):
|
51 |
+
"""The base pip error."""
|
52 |
+
|
53 |
+
|
54 |
+
class DiagnosticPipError(PipError):
|
55 |
+
"""An error, that presents diagnostic information to the user.
|
56 |
+
|
57 |
+
This contains a bunch of logic, to enable pretty presentation of our error
|
58 |
+
messages. Each error gets a unique reference. Each error can also include
|
59 |
+
additional context, a hint and/or a note -- which are presented with the
|
60 |
+
main error message in a consistent style.
|
61 |
+
|
62 |
+
This is adapted from the error output styling in `sphinx-theme-builder`.
|
63 |
+
"""
|
64 |
+
|
65 |
+
reference: str
|
66 |
+
|
67 |
+
def __init__(
|
68 |
+
self,
|
69 |
+
*,
|
70 |
+
kind: 'Literal["error", "warning"]' = "error",
|
71 |
+
reference: Optional[str] = None,
|
72 |
+
message: Union[str, Text],
|
73 |
+
context: Optional[Union[str, Text]],
|
74 |
+
hint_stmt: Optional[Union[str, Text]],
|
75 |
+
note_stmt: Optional[Union[str, Text]] = None,
|
76 |
+
link: Optional[str] = None,
|
77 |
+
) -> None:
|
78 |
+
# Ensure a proper reference is provided.
|
79 |
+
if reference is None:
|
80 |
+
assert hasattr(self, "reference"), "error reference not provided!"
|
81 |
+
reference = self.reference
|
82 |
+
assert _is_kebab_case(reference), "error reference must be kebab-case!"
|
83 |
+
|
84 |
+
self.kind = kind
|
85 |
+
self.reference = reference
|
86 |
+
|
87 |
+
self.message = message
|
88 |
+
self.context = context
|
89 |
+
|
90 |
+
self.note_stmt = note_stmt
|
91 |
+
self.hint_stmt = hint_stmt
|
92 |
+
|
93 |
+
self.link = link
|
94 |
+
|
95 |
+
super().__init__(f"<{self.__class__.__name__}: {self.reference}>")
|
96 |
+
|
97 |
+
def __repr__(self) -> str:
|
98 |
+
return (
|
99 |
+
f"<{self.__class__.__name__}("
|
100 |
+
f"reference={self.reference!r}, "
|
101 |
+
f"message={self.message!r}, "
|
102 |
+
f"context={self.context!r}, "
|
103 |
+
f"note_stmt={self.note_stmt!r}, "
|
104 |
+
f"hint_stmt={self.hint_stmt!r}"
|
105 |
+
")>"
|
106 |
+
)
|
107 |
+
|
108 |
+
def __rich_console__(
|
109 |
+
self,
|
110 |
+
console: Console,
|
111 |
+
options: ConsoleOptions,
|
112 |
+
) -> RenderResult:
|
113 |
+
colour = "red" if self.kind == "error" else "yellow"
|
114 |
+
|
115 |
+
yield f"[{colour} bold]{self.kind}[/]: [bold]{self.reference}[/]"
|
116 |
+
yield ""
|
117 |
+
|
118 |
+
if not options.ascii_only:
|
119 |
+
# Present the main message, with relevant context indented.
|
120 |
+
if self.context is not None:
|
121 |
+
yield _prefix_with_indent(
|
122 |
+
self.message,
|
123 |
+
console,
|
124 |
+
prefix=f"[{colour}]×[/] ",
|
125 |
+
indent=f"[{colour}]│[/] ",
|
126 |
+
)
|
127 |
+
yield _prefix_with_indent(
|
128 |
+
self.context,
|
129 |
+
console,
|
130 |
+
prefix=f"[{colour}]╰─>[/] ",
|
131 |
+
indent=f"[{colour}] [/] ",
|
132 |
+
)
|
133 |
+
else:
|
134 |
+
yield _prefix_with_indent(
|
135 |
+
self.message,
|
136 |
+
console,
|
137 |
+
prefix="[red]×[/] ",
|
138 |
+
indent=" ",
|
139 |
+
)
|
140 |
+
else:
|
141 |
+
yield self.message
|
142 |
+
if self.context is not None:
|
143 |
+
yield ""
|
144 |
+
yield self.context
|
145 |
+
|
146 |
+
if self.note_stmt is not None or self.hint_stmt is not None:
|
147 |
+
yield ""
|
148 |
+
|
149 |
+
if self.note_stmt is not None:
|
150 |
+
yield _prefix_with_indent(
|
151 |
+
self.note_stmt,
|
152 |
+
console,
|
153 |
+
prefix="[magenta bold]note[/]: ",
|
154 |
+
indent=" ",
|
155 |
+
)
|
156 |
+
if self.hint_stmt is not None:
|
157 |
+
yield _prefix_with_indent(
|
158 |
+
self.hint_stmt,
|
159 |
+
console,
|
160 |
+
prefix="[cyan bold]hint[/]: ",
|
161 |
+
indent=" ",
|
162 |
+
)
|
163 |
+
|
164 |
+
if self.link is not None:
|
165 |
+
yield ""
|
166 |
+
yield f"Link: {self.link}"
|
167 |
+
|
168 |
+
|
169 |
+
#
|
170 |
+
# Actual Errors
|
171 |
+
#
|
172 |
+
class ConfigurationError(PipError):
|
173 |
+
"""General exception in configuration"""
|
174 |
+
|
175 |
+
|
176 |
+
class InstallationError(PipError):
|
177 |
+
"""General exception during installation"""
|
178 |
+
|
179 |
+
|
180 |
+
class UninstallationError(PipError):
|
181 |
+
"""General exception during uninstallation"""
|
182 |
+
|
183 |
+
|
184 |
+
class MissingPyProjectBuildRequires(DiagnosticPipError):
|
185 |
+
"""Raised when pyproject.toml has `build-system`, but no `build-system.requires`."""
|
186 |
+
|
187 |
+
reference = "missing-pyproject-build-system-requires"
|
188 |
+
|
189 |
+
def __init__(self, *, package: str) -> None:
|
190 |
+
super().__init__(
|
191 |
+
message=f"Can not process {escape(package)}",
|
192 |
+
context=Text(
|
193 |
+
"This package has an invalid pyproject.toml file.\n"
|
194 |
+
"The [build-system] table is missing the mandatory `requires` key."
|
195 |
+
),
|
196 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
197 |
+
hint_stmt=Text("See PEP 518 for the detailed specification."),
|
198 |
+
)
|
199 |
+
|
200 |
+
|
201 |
+
class InvalidPyProjectBuildRequires(DiagnosticPipError):
|
202 |
+
"""Raised when pyproject.toml an invalid `build-system.requires`."""
|
203 |
+
|
204 |
+
reference = "invalid-pyproject-build-system-requires"
|
205 |
+
|
206 |
+
def __init__(self, *, package: str, reason: str) -> None:
|
207 |
+
super().__init__(
|
208 |
+
message=f"Can not process {escape(package)}",
|
209 |
+
context=Text(
|
210 |
+
"This package has an invalid `build-system.requires` key in "
|
211 |
+
f"pyproject.toml.\n{reason}"
|
212 |
+
),
|
213 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
214 |
+
hint_stmt=Text("See PEP 518 for the detailed specification."),
|
215 |
+
)
|
216 |
+
|
217 |
+
|
218 |
+
class NoneMetadataError(PipError):
|
219 |
+
"""Raised when accessing a Distribution's "METADATA" or "PKG-INFO".
|
220 |
+
|
221 |
+
This signifies an inconsistency, when the Distribution claims to have
|
222 |
+
the metadata file (if not, raise ``FileNotFoundError`` instead), but is
|
223 |
+
not actually able to produce its content. This may be due to permission
|
224 |
+
errors.
|
225 |
+
"""
|
226 |
+
|
227 |
+
def __init__(
|
228 |
+
self,
|
229 |
+
dist: "BaseDistribution",
|
230 |
+
metadata_name: str,
|
231 |
+
) -> None:
|
232 |
+
"""
|
233 |
+
:param dist: A Distribution object.
|
234 |
+
:param metadata_name: The name of the metadata being accessed
|
235 |
+
(can be "METADATA" or "PKG-INFO").
|
236 |
+
"""
|
237 |
+
self.dist = dist
|
238 |
+
self.metadata_name = metadata_name
|
239 |
+
|
240 |
+
def __str__(self) -> str:
|
241 |
+
# Use `dist` in the error message because its stringification
|
242 |
+
# includes more information, like the version and location.
|
243 |
+
return "None {} metadata found for distribution: {}".format(
|
244 |
+
self.metadata_name,
|
245 |
+
self.dist,
|
246 |
+
)
|
247 |
+
|
248 |
+
|
249 |
+
class UserInstallationInvalid(InstallationError):
|
250 |
+
"""A --user install is requested on an environment without user site."""
|
251 |
+
|
252 |
+
def __str__(self) -> str:
|
253 |
+
return "User base directory is not specified"
|
254 |
+
|
255 |
+
|
256 |
+
class InvalidSchemeCombination(InstallationError):
|
257 |
+
def __str__(self) -> str:
|
258 |
+
before = ", ".join(str(a) for a in self.args[:-1])
|
259 |
+
return f"Cannot set {before} and {self.args[-1]} together"
|
260 |
+
|
261 |
+
|
262 |
+
class DistributionNotFound(InstallationError):
|
263 |
+
"""Raised when a distribution cannot be found to satisfy a requirement"""
|
264 |
+
|
265 |
+
|
266 |
+
class RequirementsFileParseError(InstallationError):
|
267 |
+
"""Raised when a general error occurs parsing a requirements file line."""
|
268 |
+
|
269 |
+
|
270 |
+
class BestVersionAlreadyInstalled(PipError):
|
271 |
+
"""Raised when the most up-to-date version of a package is already
|
272 |
+
installed."""
|
273 |
+
|
274 |
+
|
275 |
+
class BadCommand(PipError):
|
276 |
+
"""Raised when virtualenv or a command is not found"""
|
277 |
+
|
278 |
+
|
279 |
+
class CommandError(PipError):
|
280 |
+
"""Raised when there is an error in command-line arguments"""
|
281 |
+
|
282 |
+
|
283 |
+
class PreviousBuildDirError(PipError):
|
284 |
+
"""Raised when there's a previous conflicting build directory"""
|
285 |
+
|
286 |
+
|
287 |
+
class NetworkConnectionError(PipError):
|
288 |
+
"""HTTP connection error"""
|
289 |
+
|
290 |
+
def __init__(
|
291 |
+
self, error_msg: str, response: Response = None, request: Request = None
|
292 |
+
) -> None:
|
293 |
+
"""
|
294 |
+
Initialize NetworkConnectionError with `request` and `response`
|
295 |
+
objects.
|
296 |
+
"""
|
297 |
+
self.response = response
|
298 |
+
self.request = request
|
299 |
+
self.error_msg = error_msg
|
300 |
+
if (
|
301 |
+
self.response is not None
|
302 |
+
and not self.request
|
303 |
+
and hasattr(response, "request")
|
304 |
+
):
|
305 |
+
self.request = self.response.request
|
306 |
+
super().__init__(error_msg, response, request)
|
307 |
+
|
308 |
+
def __str__(self) -> str:
|
309 |
+
return str(self.error_msg)
|
310 |
+
|
311 |
+
|
312 |
+
class InvalidWheelFilename(InstallationError):
|
313 |
+
"""Invalid wheel filename."""
|
314 |
+
|
315 |
+
|
316 |
+
class UnsupportedWheel(InstallationError):
|
317 |
+
"""Unsupported wheel."""
|
318 |
+
|
319 |
+
|
320 |
+
class InvalidWheel(InstallationError):
|
321 |
+
"""Invalid (e.g. corrupt) wheel."""
|
322 |
+
|
323 |
+
def __init__(self, location: str, name: str):
|
324 |
+
self.location = location
|
325 |
+
self.name = name
|
326 |
+
|
327 |
+
def __str__(self) -> str:
|
328 |
+
return f"Wheel '{self.name}' located at {self.location} is invalid."
|
329 |
+
|
330 |
+
|
331 |
+
class MetadataInconsistent(InstallationError):
|
332 |
+
"""Built metadata contains inconsistent information.
|
333 |
+
|
334 |
+
This is raised when the metadata contains values (e.g. name and version)
|
335 |
+
that do not match the information previously obtained from sdist filename
|
336 |
+
or user-supplied ``#egg=`` value.
|
337 |
+
"""
|
338 |
+
|
339 |
+
def __init__(
|
340 |
+
self, ireq: "InstallRequirement", field: str, f_val: str, m_val: str
|
341 |
+
) -> None:
|
342 |
+
self.ireq = ireq
|
343 |
+
self.field = field
|
344 |
+
self.f_val = f_val
|
345 |
+
self.m_val = m_val
|
346 |
+
|
347 |
+
def __str__(self) -> str:
|
348 |
+
template = (
|
349 |
+
"Requested {} has inconsistent {}: "
|
350 |
+
"filename has {!r}, but metadata has {!r}"
|
351 |
+
)
|
352 |
+
return template.format(self.ireq, self.field, self.f_val, self.m_val)
|
353 |
+
|
354 |
+
|
355 |
+
class LegacyInstallFailure(DiagnosticPipError):
|
356 |
+
"""Error occurred while executing `setup.py install`"""
|
357 |
+
|
358 |
+
reference = "legacy-install-failure"
|
359 |
+
|
360 |
+
def __init__(self, package_details: str) -> None:
|
361 |
+
super().__init__(
|
362 |
+
message="Encountered error while trying to install package.",
|
363 |
+
context=package_details,
|
364 |
+
hint_stmt="See above for output from the failure.",
|
365 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
366 |
+
)
|
367 |
+
|
368 |
+
|
369 |
+
class InstallationSubprocessError(DiagnosticPipError, InstallationError):
|
370 |
+
"""A subprocess call failed."""
|
371 |
+
|
372 |
+
reference = "subprocess-exited-with-error"
|
373 |
+
|
374 |
+
def __init__(
|
375 |
+
self,
|
376 |
+
*,
|
377 |
+
command_description: str,
|
378 |
+
exit_code: int,
|
379 |
+
output_lines: Optional[List[str]],
|
380 |
+
) -> None:
|
381 |
+
if output_lines is None:
|
382 |
+
output_prompt = Text("See above for output.")
|
383 |
+
else:
|
384 |
+
output_prompt = (
|
385 |
+
Text.from_markup(f"[red][{len(output_lines)} lines of output][/]\n")
|
386 |
+
+ Text("".join(output_lines))
|
387 |
+
+ Text.from_markup(R"[red]\[end of output][/]")
|
388 |
+
)
|
389 |
+
|
390 |
+
super().__init__(
|
391 |
+
message=(
|
392 |
+
f"[green]{escape(command_description)}[/] did not run successfully.\n"
|
393 |
+
f"exit code: {exit_code}"
|
394 |
+
),
|
395 |
+
context=output_prompt,
|
396 |
+
hint_stmt=None,
|
397 |
+
note_stmt=(
|
398 |
+
"This error originates from a subprocess, and is likely not a "
|
399 |
+
"problem with pip."
|
400 |
+
),
|
401 |
+
)
|
402 |
+
|
403 |
+
self.command_description = command_description
|
404 |
+
self.exit_code = exit_code
|
405 |
+
|
406 |
+
def __str__(self) -> str:
|
407 |
+
return f"{self.command_description} exited with {self.exit_code}"
|
408 |
+
|
409 |
+
|
410 |
+
class MetadataGenerationFailed(InstallationSubprocessError, InstallationError):
|
411 |
+
reference = "metadata-generation-failed"
|
412 |
+
|
413 |
+
def __init__(
|
414 |
+
self,
|
415 |
+
*,
|
416 |
+
package_details: str,
|
417 |
+
) -> None:
|
418 |
+
super(InstallationSubprocessError, self).__init__(
|
419 |
+
message="Encountered error while generating package metadata.",
|
420 |
+
context=escape(package_details),
|
421 |
+
hint_stmt="See above for details.",
|
422 |
+
note_stmt="This is an issue with the package mentioned above, not pip.",
|
423 |
+
)
|
424 |
+
|
425 |
+
def __str__(self) -> str:
|
426 |
+
return "metadata generation failed"
|
427 |
+
|
428 |
+
|
429 |
+
class HashErrors(InstallationError):
|
430 |
+
"""Multiple HashError instances rolled into one for reporting"""
|
431 |
+
|
432 |
+
def __init__(self) -> None:
|
433 |
+
self.errors: List["HashError"] = []
|
434 |
+
|
435 |
+
def append(self, error: "HashError") -> None:
|
436 |
+
self.errors.append(error)
|
437 |
+
|
438 |
+
def __str__(self) -> str:
|
439 |
+
lines = []
|
440 |
+
self.errors.sort(key=lambda e: e.order)
|
441 |
+
for cls, errors_of_cls in groupby(self.errors, lambda e: e.__class__):
|
442 |
+
lines.append(cls.head)
|
443 |
+
lines.extend(e.body() for e in errors_of_cls)
|
444 |
+
if lines:
|
445 |
+
return "\n".join(lines)
|
446 |
+
return ""
|
447 |
+
|
448 |
+
def __bool__(self) -> bool:
|
449 |
+
return bool(self.errors)
|
450 |
+
|
451 |
+
|
452 |
+
class HashError(InstallationError):
|
453 |
+
"""
|
454 |
+
A failure to verify a package against known-good hashes
|
455 |
+
|
456 |
+
:cvar order: An int sorting hash exception classes by difficulty of
|
457 |
+
recovery (lower being harder), so the user doesn't bother fretting
|
458 |
+
about unpinned packages when he has deeper issues, like VCS
|
459 |
+
dependencies, to deal with. Also keeps error reports in a
|
460 |
+
deterministic order.
|
461 |
+
:cvar head: A section heading for display above potentially many
|
462 |
+
exceptions of this kind
|
463 |
+
:ivar req: The InstallRequirement that triggered this error. This is
|
464 |
+
pasted on after the exception is instantiated, because it's not
|
465 |
+
typically available earlier.
|
466 |
+
|
467 |
+
"""
|
468 |
+
|
469 |
+
req: Optional["InstallRequirement"] = None
|
470 |
+
head = ""
|
471 |
+
order: int = -1
|
472 |
+
|
473 |
+
def body(self) -> str:
|
474 |
+
"""Return a summary of me for display under the heading.
|
475 |
+
|
476 |
+
This default implementation simply prints a description of the
|
477 |
+
triggering requirement.
|
478 |
+
|
479 |
+
:param req: The InstallRequirement that provoked this error, with
|
480 |
+
its link already populated by the resolver's _populate_link().
|
481 |
+
|
482 |
+
"""
|
483 |
+
return f" {self._requirement_name()}"
|
484 |
+
|
485 |
+
def __str__(self) -> str:
|
486 |
+
return f"{self.head}\n{self.body()}"
|
487 |
+
|
488 |
+
def _requirement_name(self) -> str:
|
489 |
+
"""Return a description of the requirement that triggered me.
|
490 |
+
|
491 |
+
This default implementation returns long description of the req, with
|
492 |
+
line numbers
|
493 |
+
|
494 |
+
"""
|
495 |
+
return str(self.req) if self.req else "unknown package"
|
496 |
+
|
497 |
+
|
498 |
+
class VcsHashUnsupported(HashError):
|
499 |
+
"""A hash was provided for a version-control-system-based requirement, but
|
500 |
+
we don't have a method for hashing those."""
|
501 |
+
|
502 |
+
order = 0
|
503 |
+
head = (
|
504 |
+
"Can't verify hashes for these requirements because we don't "
|
505 |
+
"have a way to hash version control repositories:"
|
506 |
+
)
|
507 |
+
|
508 |
+
|
509 |
+
class DirectoryUrlHashUnsupported(HashError):
|
510 |
+
"""A hash was provided for a version-control-system-based requirement, but
|
511 |
+
we don't have a method for hashing those."""
|
512 |
+
|
513 |
+
order = 1
|
514 |
+
head = (
|
515 |
+
"Can't verify hashes for these file:// requirements because they "
|
516 |
+
"point to directories:"
|
517 |
+
)
|
518 |
+
|
519 |
+
|
520 |
+
class HashMissing(HashError):
|
521 |
+
"""A hash was needed for a requirement but is absent."""
|
522 |
+
|
523 |
+
order = 2
|
524 |
+
head = (
|
525 |
+
"Hashes are required in --require-hashes mode, but they are "
|
526 |
+
"missing from some requirements. Here is a list of those "
|
527 |
+
"requirements along with the hashes their downloaded archives "
|
528 |
+
"actually had. Add lines like these to your requirements files to "
|
529 |
+
"prevent tampering. (If you did not enable --require-hashes "
|
530 |
+
"manually, note that it turns on automatically when any package "
|
531 |
+
"has a hash.)"
|
532 |
+
)
|
533 |
+
|
534 |
+
def __init__(self, gotten_hash: str) -> None:
|
535 |
+
"""
|
536 |
+
:param gotten_hash: The hash of the (possibly malicious) archive we
|
537 |
+
just downloaded
|
538 |
+
"""
|
539 |
+
self.gotten_hash = gotten_hash
|
540 |
+
|
541 |
+
def body(self) -> str:
|
542 |
+
# Dodge circular import.
|
543 |
+
from pip._internal.utils.hashes import FAVORITE_HASH
|
544 |
+
|
545 |
+
package = None
|
546 |
+
if self.req:
|
547 |
+
# In the case of URL-based requirements, display the original URL
|
548 |
+
# seen in the requirements file rather than the package name,
|
549 |
+
# so the output can be directly copied into the requirements file.
|
550 |
+
package = (
|
551 |
+
self.req.original_link
|
552 |
+
if self.req.original_link
|
553 |
+
# In case someone feeds something downright stupid
|
554 |
+
# to InstallRequirement's constructor.
|
555 |
+
else getattr(self.req, "req", None)
|
556 |
+
)
|
557 |
+
return " {} --hash={}:{}".format(
|
558 |
+
package or "unknown package", FAVORITE_HASH, self.gotten_hash
|
559 |
+
)
|
560 |
+
|
561 |
+
|
562 |
+
class HashUnpinned(HashError):
|
563 |
+
"""A requirement had a hash specified but was not pinned to a specific
|
564 |
+
version."""
|
565 |
+
|
566 |
+
order = 3
|
567 |
+
head = (
|
568 |
+
"In --require-hashes mode, all requirements must have their "
|
569 |
+
"versions pinned with ==. These do not:"
|
570 |
+
)
|
571 |
+
|
572 |
+
|
573 |
+
class HashMismatch(HashError):
|
574 |
+
"""
|
575 |
+
Distribution file hash values don't match.
|
576 |
+
|
577 |
+
:ivar package_name: The name of the package that triggered the hash
|
578 |
+
mismatch. Feel free to write to this after the exception is raise to
|
579 |
+
improve its error message.
|
580 |
+
|
581 |
+
"""
|
582 |
+
|
583 |
+
order = 4
|
584 |
+
head = (
|
585 |
+
"THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS "
|
586 |
+
"FILE. If you have updated the package versions, please update "
|
587 |
+
"the hashes. Otherwise, examine the package contents carefully; "
|
588 |
+
"someone may have tampered with them."
|
589 |
+
)
|
590 |
+
|
591 |
+
def __init__(self, allowed: Dict[str, List[str]], gots: Dict[str, "_Hash"]) -> None:
|
592 |
+
"""
|
593 |
+
:param allowed: A dict of algorithm names pointing to lists of allowed
|
594 |
+
hex digests
|
595 |
+
:param gots: A dict of algorithm names pointing to hashes we
|
596 |
+
actually got from the files under suspicion
|
597 |
+
"""
|
598 |
+
self.allowed = allowed
|
599 |
+
self.gots = gots
|
600 |
+
|
601 |
+
def body(self) -> str:
|
602 |
+
return " {}:\n{}".format(self._requirement_name(), self._hash_comparison())
|
603 |
+
|
604 |
+
def _hash_comparison(self) -> str:
|
605 |
+
"""
|
606 |
+
Return a comparison of actual and expected hash values.
|
607 |
+
|
608 |
+
Example::
|
609 |
+
|
610 |
+
Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde
|
611 |
+
or 123451234512345123451234512345123451234512345
|
612 |
+
Got bcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdef
|
613 |
+
|
614 |
+
"""
|
615 |
+
|
616 |
+
def hash_then_or(hash_name: str) -> "chain[str]":
|
617 |
+
# For now, all the decent hashes have 6-char names, so we can get
|
618 |
+
# away with hard-coding space literals.
|
619 |
+
return chain([hash_name], repeat(" or"))
|
620 |
+
|
621 |
+
lines: List[str] = []
|
622 |
+
for hash_name, expecteds in self.allowed.items():
|
623 |
+
prefix = hash_then_or(hash_name)
|
624 |
+
lines.extend(
|
625 |
+
(" Expected {} {}".format(next(prefix), e)) for e in expecteds
|
626 |
+
)
|
627 |
+
lines.append(
|
628 |
+
" Got {}\n".format(self.gots[hash_name].hexdigest())
|
629 |
+
)
|
630 |
+
return "\n".join(lines)
|
631 |
+
|
632 |
+
|
633 |
+
class UnsupportedPythonVersion(InstallationError):
|
634 |
+
"""Unsupported python version according to Requires-Python package
|
635 |
+
metadata."""
|
636 |
+
|
637 |
+
|
638 |
+
class ConfigurationFileCouldNotBeLoaded(ConfigurationError):
|
639 |
+
"""When there are errors while loading a configuration file"""
|
640 |
+
|
641 |
+
def __init__(
|
642 |
+
self,
|
643 |
+
reason: str = "could not be loaded",
|
644 |
+
fname: Optional[str] = None,
|
645 |
+
error: Optional[configparser.Error] = None,
|
646 |
+
) -> None:
|
647 |
+
super().__init__(error)
|
648 |
+
self.reason = reason
|
649 |
+
self.fname = fname
|
650 |
+
self.error = error
|
651 |
+
|
652 |
+
def __str__(self) -> str:
|
653 |
+
if self.fname is not None:
|
654 |
+
message_part = f" in {self.fname}."
|
655 |
+
else:
|
656 |
+
assert self.error is not None
|
657 |
+
message_part = f".\n{self.error}\n"
|
658 |
+
return f"Configuration file {self.reason}{message_part}"
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__init__.py
ADDED
@@ -0,0 +1,520 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import functools
|
2 |
+
import logging
|
3 |
+
import os
|
4 |
+
import pathlib
|
5 |
+
import sys
|
6 |
+
import sysconfig
|
7 |
+
from typing import Any, Dict, Iterator, List, Optional, Tuple
|
8 |
+
|
9 |
+
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
|
10 |
+
from pip._internal.utils.compat import WINDOWS
|
11 |
+
from pip._internal.utils.deprecation import deprecated
|
12 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
13 |
+
|
14 |
+
from . import _distutils, _sysconfig
|
15 |
+
from .base import (
|
16 |
+
USER_CACHE_DIR,
|
17 |
+
get_major_minor_version,
|
18 |
+
get_src_prefix,
|
19 |
+
is_osx_framework,
|
20 |
+
site_packages,
|
21 |
+
user_site,
|
22 |
+
)
|
23 |
+
|
24 |
+
__all__ = [
|
25 |
+
"USER_CACHE_DIR",
|
26 |
+
"get_bin_prefix",
|
27 |
+
"get_bin_user",
|
28 |
+
"get_major_minor_version",
|
29 |
+
"get_platlib",
|
30 |
+
"get_prefixed_libs",
|
31 |
+
"get_purelib",
|
32 |
+
"get_scheme",
|
33 |
+
"get_src_prefix",
|
34 |
+
"site_packages",
|
35 |
+
"user_site",
|
36 |
+
]
|
37 |
+
|
38 |
+
|
39 |
+
logger = logging.getLogger(__name__)
|
40 |
+
|
41 |
+
|
42 |
+
_PLATLIBDIR: str = getattr(sys, "platlibdir", "lib")
|
43 |
+
|
44 |
+
_USE_SYSCONFIG_DEFAULT = sys.version_info >= (3, 10)
|
45 |
+
|
46 |
+
|
47 |
+
def _should_use_sysconfig() -> bool:
|
48 |
+
"""This function determines the value of _USE_SYSCONFIG.
|
49 |
+
|
50 |
+
By default, pip uses sysconfig on Python 3.10+.
|
51 |
+
But Python distributors can override this decision by setting:
|
52 |
+
sysconfig._PIP_USE_SYSCONFIG = True / False
|
53 |
+
Rationale in https://github.com/pypa/pip/issues/10647
|
54 |
+
|
55 |
+
This is a function for testability, but should be constant during any one
|
56 |
+
run.
|
57 |
+
"""
|
58 |
+
return bool(getattr(sysconfig, "_PIP_USE_SYSCONFIG", _USE_SYSCONFIG_DEFAULT))
|
59 |
+
|
60 |
+
|
61 |
+
_USE_SYSCONFIG = _should_use_sysconfig()
|
62 |
+
|
63 |
+
# Be noisy about incompatibilities if this platforms "should" be using
|
64 |
+
# sysconfig, but is explicitly opting out and using distutils instead.
|
65 |
+
if _USE_SYSCONFIG_DEFAULT and not _USE_SYSCONFIG:
|
66 |
+
_MISMATCH_LEVEL = logging.WARNING
|
67 |
+
else:
|
68 |
+
_MISMATCH_LEVEL = logging.DEBUG
|
69 |
+
|
70 |
+
|
71 |
+
def _looks_like_bpo_44860() -> bool:
|
72 |
+
"""The resolution to bpo-44860 will change this incorrect platlib.
|
73 |
+
|
74 |
+
See <https://bugs.python.org/issue44860>.
|
75 |
+
"""
|
76 |
+
from distutils.command.install import INSTALL_SCHEMES # type: ignore
|
77 |
+
|
78 |
+
try:
|
79 |
+
unix_user_platlib = INSTALL_SCHEMES["unix_user"]["platlib"]
|
80 |
+
except KeyError:
|
81 |
+
return False
|
82 |
+
return unix_user_platlib == "$usersite"
|
83 |
+
|
84 |
+
|
85 |
+
def _looks_like_red_hat_patched_platlib_purelib(scheme: Dict[str, str]) -> bool:
|
86 |
+
platlib = scheme["platlib"]
|
87 |
+
if "/$platlibdir/" in platlib:
|
88 |
+
platlib = platlib.replace("/$platlibdir/", f"/{_PLATLIBDIR}/")
|
89 |
+
if "/lib64/" not in platlib:
|
90 |
+
return False
|
91 |
+
unpatched = platlib.replace("/lib64/", "/lib/")
|
92 |
+
return unpatched.replace("$platbase/", "$base/") == scheme["purelib"]
|
93 |
+
|
94 |
+
|
95 |
+
@functools.lru_cache(maxsize=None)
|
96 |
+
def _looks_like_red_hat_lib() -> bool:
|
97 |
+
"""Red Hat patches platlib in unix_prefix and unix_home, but not purelib.
|
98 |
+
|
99 |
+
This is the only way I can see to tell a Red Hat-patched Python.
|
100 |
+
"""
|
101 |
+
from distutils.command.install import INSTALL_SCHEMES # type: ignore
|
102 |
+
|
103 |
+
return all(
|
104 |
+
k in INSTALL_SCHEMES
|
105 |
+
and _looks_like_red_hat_patched_platlib_purelib(INSTALL_SCHEMES[k])
|
106 |
+
for k in ("unix_prefix", "unix_home")
|
107 |
+
)
|
108 |
+
|
109 |
+
|
110 |
+
@functools.lru_cache(maxsize=None)
|
111 |
+
def _looks_like_debian_scheme() -> bool:
|
112 |
+
"""Debian adds two additional schemes."""
|
113 |
+
from distutils.command.install import INSTALL_SCHEMES # type: ignore
|
114 |
+
|
115 |
+
return "deb_system" in INSTALL_SCHEMES and "unix_local" in INSTALL_SCHEMES
|
116 |
+
|
117 |
+
|
118 |
+
@functools.lru_cache(maxsize=None)
|
119 |
+
def _looks_like_red_hat_scheme() -> bool:
|
120 |
+
"""Red Hat patches ``sys.prefix`` and ``sys.exec_prefix``.
|
121 |
+
|
122 |
+
Red Hat's ``00251-change-user-install-location.patch`` changes the install
|
123 |
+
command's ``prefix`` and ``exec_prefix`` to append ``"/local"``. This is
|
124 |
+
(fortunately?) done quite unconditionally, so we create a default command
|
125 |
+
object without any configuration to detect this.
|
126 |
+
"""
|
127 |
+
from distutils.command.install import install
|
128 |
+
from distutils.dist import Distribution
|
129 |
+
|
130 |
+
cmd: Any = install(Distribution())
|
131 |
+
cmd.finalize_options()
|
132 |
+
return (
|
133 |
+
cmd.exec_prefix == f"{os.path.normpath(sys.exec_prefix)}/local"
|
134 |
+
and cmd.prefix == f"{os.path.normpath(sys.prefix)}/local"
|
135 |
+
)
|
136 |
+
|
137 |
+
|
138 |
+
@functools.lru_cache(maxsize=None)
|
139 |
+
def _looks_like_slackware_scheme() -> bool:
|
140 |
+
"""Slackware patches sysconfig but fails to patch distutils and site.
|
141 |
+
|
142 |
+
Slackware changes sysconfig's user scheme to use ``"lib64"`` for the lib
|
143 |
+
path, but does not do the same to the site module.
|
144 |
+
"""
|
145 |
+
if user_site is None: # User-site not available.
|
146 |
+
return False
|
147 |
+
try:
|
148 |
+
paths = sysconfig.get_paths(scheme="posix_user", expand=False)
|
149 |
+
except KeyError: # User-site not available.
|
150 |
+
return False
|
151 |
+
return "/lib64/" in paths["purelib"] and "/lib64/" not in user_site
|
152 |
+
|
153 |
+
|
154 |
+
@functools.lru_cache(maxsize=None)
|
155 |
+
def _looks_like_msys2_mingw_scheme() -> bool:
|
156 |
+
"""MSYS2 patches distutils and sysconfig to use a UNIX-like scheme.
|
157 |
+
|
158 |
+
However, MSYS2 incorrectly patches sysconfig ``nt`` scheme. The fix is
|
159 |
+
likely going to be included in their 3.10 release, so we ignore the warning.
|
160 |
+
See msys2/MINGW-packages#9319.
|
161 |
+
|
162 |
+
MSYS2 MINGW's patch uses lowercase ``"lib"`` instead of the usual uppercase,
|
163 |
+
and is missing the final ``"site-packages"``.
|
164 |
+
"""
|
165 |
+
paths = sysconfig.get_paths("nt", expand=False)
|
166 |
+
return all(
|
167 |
+
"Lib" not in p and "lib" in p and not p.endswith("site-packages")
|
168 |
+
for p in (paths[key] for key in ("platlib", "purelib"))
|
169 |
+
)
|
170 |
+
|
171 |
+
|
172 |
+
def _fix_abiflags(parts: Tuple[str]) -> Iterator[str]:
|
173 |
+
ldversion = sysconfig.get_config_var("LDVERSION")
|
174 |
+
abiflags: str = getattr(sys, "abiflags", None)
|
175 |
+
|
176 |
+
# LDVERSION does not end with sys.abiflags. Just return the path unchanged.
|
177 |
+
if not ldversion or not abiflags or not ldversion.endswith(abiflags):
|
178 |
+
yield from parts
|
179 |
+
return
|
180 |
+
|
181 |
+
# Strip sys.abiflags from LDVERSION-based path components.
|
182 |
+
for part in parts:
|
183 |
+
if part.endswith(ldversion):
|
184 |
+
part = part[: (0 - len(abiflags))]
|
185 |
+
yield part
|
186 |
+
|
187 |
+
|
188 |
+
@functools.lru_cache(maxsize=None)
|
189 |
+
def _warn_mismatched(old: pathlib.Path, new: pathlib.Path, *, key: str) -> None:
|
190 |
+
issue_url = "https://github.com/pypa/pip/issues/10151"
|
191 |
+
message = (
|
192 |
+
"Value for %s does not match. Please report this to <%s>"
|
193 |
+
"\ndistutils: %s"
|
194 |
+
"\nsysconfig: %s"
|
195 |
+
)
|
196 |
+
logger.log(_MISMATCH_LEVEL, message, key, issue_url, old, new)
|
197 |
+
|
198 |
+
|
199 |
+
def _warn_if_mismatch(old: pathlib.Path, new: pathlib.Path, *, key: str) -> bool:
|
200 |
+
if old == new:
|
201 |
+
return False
|
202 |
+
_warn_mismatched(old, new, key=key)
|
203 |
+
return True
|
204 |
+
|
205 |
+
|
206 |
+
@functools.lru_cache(maxsize=None)
|
207 |
+
def _log_context(
|
208 |
+
*,
|
209 |
+
user: bool = False,
|
210 |
+
home: Optional[str] = None,
|
211 |
+
root: Optional[str] = None,
|
212 |
+
prefix: Optional[str] = None,
|
213 |
+
) -> None:
|
214 |
+
parts = [
|
215 |
+
"Additional context:",
|
216 |
+
"user = %r",
|
217 |
+
"home = %r",
|
218 |
+
"root = %r",
|
219 |
+
"prefix = %r",
|
220 |
+
]
|
221 |
+
|
222 |
+
logger.log(_MISMATCH_LEVEL, "\n".join(parts), user, home, root, prefix)
|
223 |
+
|
224 |
+
|
225 |
+
def get_scheme(
|
226 |
+
dist_name: str,
|
227 |
+
user: bool = False,
|
228 |
+
home: Optional[str] = None,
|
229 |
+
root: Optional[str] = None,
|
230 |
+
isolated: bool = False,
|
231 |
+
prefix: Optional[str] = None,
|
232 |
+
) -> Scheme:
|
233 |
+
new = _sysconfig.get_scheme(
|
234 |
+
dist_name,
|
235 |
+
user=user,
|
236 |
+
home=home,
|
237 |
+
root=root,
|
238 |
+
isolated=isolated,
|
239 |
+
prefix=prefix,
|
240 |
+
)
|
241 |
+
if _USE_SYSCONFIG:
|
242 |
+
return new
|
243 |
+
|
244 |
+
old = _distutils.get_scheme(
|
245 |
+
dist_name,
|
246 |
+
user=user,
|
247 |
+
home=home,
|
248 |
+
root=root,
|
249 |
+
isolated=isolated,
|
250 |
+
prefix=prefix,
|
251 |
+
)
|
252 |
+
|
253 |
+
warning_contexts = []
|
254 |
+
for k in SCHEME_KEYS:
|
255 |
+
old_v = pathlib.Path(getattr(old, k))
|
256 |
+
new_v = pathlib.Path(getattr(new, k))
|
257 |
+
|
258 |
+
if old_v == new_v:
|
259 |
+
continue
|
260 |
+
|
261 |
+
# distutils incorrectly put PyPy packages under ``site-packages/python``
|
262 |
+
# in the ``posix_home`` scheme, but PyPy devs said they expect the
|
263 |
+
# directory name to be ``pypy`` instead. So we treat this as a bug fix
|
264 |
+
# and not warn about it. See bpo-43307 and python/cpython#24628.
|
265 |
+
skip_pypy_special_case = (
|
266 |
+
sys.implementation.name == "pypy"
|
267 |
+
and home is not None
|
268 |
+
and k in ("platlib", "purelib")
|
269 |
+
and old_v.parent == new_v.parent
|
270 |
+
and old_v.name.startswith("python")
|
271 |
+
and new_v.name.startswith("pypy")
|
272 |
+
)
|
273 |
+
if skip_pypy_special_case:
|
274 |
+
continue
|
275 |
+
|
276 |
+
# sysconfig's ``osx_framework_user`` does not include ``pythonX.Y`` in
|
277 |
+
# the ``include`` value, but distutils's ``headers`` does. We'll let
|
278 |
+
# CPython decide whether this is a bug or feature. See bpo-43948.
|
279 |
+
skip_osx_framework_user_special_case = (
|
280 |
+
user
|
281 |
+
and is_osx_framework()
|
282 |
+
and k == "headers"
|
283 |
+
and old_v.parent.parent == new_v.parent
|
284 |
+
and old_v.parent.name.startswith("python")
|
285 |
+
)
|
286 |
+
if skip_osx_framework_user_special_case:
|
287 |
+
continue
|
288 |
+
|
289 |
+
# On Red Hat and derived Linux distributions, distutils is patched to
|
290 |
+
# use "lib64" instead of "lib" for platlib.
|
291 |
+
if k == "platlib" and _looks_like_red_hat_lib():
|
292 |
+
continue
|
293 |
+
|
294 |
+
# On Python 3.9+, sysconfig's posix_user scheme sets platlib against
|
295 |
+
# sys.platlibdir, but distutils's unix_user incorrectly coninutes
|
296 |
+
# using the same $usersite for both platlib and purelib. This creates a
|
297 |
+
# mismatch when sys.platlibdir is not "lib".
|
298 |
+
skip_bpo_44860 = (
|
299 |
+
user
|
300 |
+
and k == "platlib"
|
301 |
+
and not WINDOWS
|
302 |
+
and sys.version_info >= (3, 9)
|
303 |
+
and _PLATLIBDIR != "lib"
|
304 |
+
and _looks_like_bpo_44860()
|
305 |
+
)
|
306 |
+
if skip_bpo_44860:
|
307 |
+
continue
|
308 |
+
|
309 |
+
# Slackware incorrectly patches posix_user to use lib64 instead of lib,
|
310 |
+
# but not usersite to match the location.
|
311 |
+
skip_slackware_user_scheme = (
|
312 |
+
user
|
313 |
+
and k in ("platlib", "purelib")
|
314 |
+
and not WINDOWS
|
315 |
+
and _looks_like_slackware_scheme()
|
316 |
+
)
|
317 |
+
if skip_slackware_user_scheme:
|
318 |
+
continue
|
319 |
+
|
320 |
+
# Both Debian and Red Hat patch Python to place the system site under
|
321 |
+
# /usr/local instead of /usr. Debian also places lib in dist-packages
|
322 |
+
# instead of site-packages, but the /usr/local check should cover it.
|
323 |
+
skip_linux_system_special_case = (
|
324 |
+
not (user or home or prefix or running_under_virtualenv())
|
325 |
+
and old_v.parts[1:3] == ("usr", "local")
|
326 |
+
and len(new_v.parts) > 1
|
327 |
+
and new_v.parts[1] == "usr"
|
328 |
+
and (len(new_v.parts) < 3 or new_v.parts[2] != "local")
|
329 |
+
and (_looks_like_red_hat_scheme() or _looks_like_debian_scheme())
|
330 |
+
)
|
331 |
+
if skip_linux_system_special_case:
|
332 |
+
continue
|
333 |
+
|
334 |
+
# On Python 3.7 and earlier, sysconfig does not include sys.abiflags in
|
335 |
+
# the "pythonX.Y" part of the path, but distutils does.
|
336 |
+
skip_sysconfig_abiflag_bug = (
|
337 |
+
sys.version_info < (3, 8)
|
338 |
+
and not WINDOWS
|
339 |
+
and k in ("headers", "platlib", "purelib")
|
340 |
+
and tuple(_fix_abiflags(old_v.parts)) == new_v.parts
|
341 |
+
)
|
342 |
+
if skip_sysconfig_abiflag_bug:
|
343 |
+
continue
|
344 |
+
|
345 |
+
# MSYS2 MINGW's sysconfig patch does not include the "site-packages"
|
346 |
+
# part of the path. This is incorrect and will be fixed in MSYS.
|
347 |
+
skip_msys2_mingw_bug = (
|
348 |
+
WINDOWS and k in ("platlib", "purelib") and _looks_like_msys2_mingw_scheme()
|
349 |
+
)
|
350 |
+
if skip_msys2_mingw_bug:
|
351 |
+
continue
|
352 |
+
|
353 |
+
# CPython's POSIX install script invokes pip (via ensurepip) against the
|
354 |
+
# interpreter located in the source tree, not the install site. This
|
355 |
+
# triggers special logic in sysconfig that's not present in distutils.
|
356 |
+
# https://github.com/python/cpython/blob/8c21941ddaf/Lib/sysconfig.py#L178-L194
|
357 |
+
skip_cpython_build = (
|
358 |
+
sysconfig.is_python_build(check_home=True)
|
359 |
+
and not WINDOWS
|
360 |
+
and k in ("headers", "include", "platinclude")
|
361 |
+
)
|
362 |
+
if skip_cpython_build:
|
363 |
+
continue
|
364 |
+
|
365 |
+
warning_contexts.append((old_v, new_v, f"scheme.{k}"))
|
366 |
+
|
367 |
+
if not warning_contexts:
|
368 |
+
return old
|
369 |
+
|
370 |
+
# Check if this path mismatch is caused by distutils config files. Those
|
371 |
+
# files will no longer work once we switch to sysconfig, so this raises a
|
372 |
+
# deprecation message for them.
|
373 |
+
default_old = _distutils.distutils_scheme(
|
374 |
+
dist_name,
|
375 |
+
user,
|
376 |
+
home,
|
377 |
+
root,
|
378 |
+
isolated,
|
379 |
+
prefix,
|
380 |
+
ignore_config_files=True,
|
381 |
+
)
|
382 |
+
if any(default_old[k] != getattr(old, k) for k in SCHEME_KEYS):
|
383 |
+
deprecated(
|
384 |
+
reason=(
|
385 |
+
"Configuring installation scheme with distutils config files "
|
386 |
+
"is deprecated and will no longer work in the near future. If you "
|
387 |
+
"are using a Homebrew or Linuxbrew Python, please see discussion "
|
388 |
+
"at https://github.com/Homebrew/homebrew-core/issues/76621"
|
389 |
+
),
|
390 |
+
replacement=None,
|
391 |
+
gone_in=None,
|
392 |
+
)
|
393 |
+
return old
|
394 |
+
|
395 |
+
# Post warnings about this mismatch so user can report them back.
|
396 |
+
for old_v, new_v, key in warning_contexts:
|
397 |
+
_warn_mismatched(old_v, new_v, key=key)
|
398 |
+
_log_context(user=user, home=home, root=root, prefix=prefix)
|
399 |
+
|
400 |
+
return old
|
401 |
+
|
402 |
+
|
403 |
+
def get_bin_prefix() -> str:
|
404 |
+
new = _sysconfig.get_bin_prefix()
|
405 |
+
if _USE_SYSCONFIG:
|
406 |
+
return new
|
407 |
+
|
408 |
+
old = _distutils.get_bin_prefix()
|
409 |
+
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_prefix"):
|
410 |
+
_log_context()
|
411 |
+
return old
|
412 |
+
|
413 |
+
|
414 |
+
def get_bin_user() -> str:
|
415 |
+
return _sysconfig.get_scheme("", user=True).scripts
|
416 |
+
|
417 |
+
|
418 |
+
def _looks_like_deb_system_dist_packages(value: str) -> bool:
|
419 |
+
"""Check if the value is Debian's APT-controlled dist-packages.
|
420 |
+
|
421 |
+
Debian's ``distutils.sysconfig.get_python_lib()`` implementation returns the
|
422 |
+
default package path controlled by APT, but does not patch ``sysconfig`` to
|
423 |
+
do the same. This is similar to the bug worked around in ``get_scheme()``,
|
424 |
+
but here the default is ``deb_system`` instead of ``unix_local``. Ultimately
|
425 |
+
we can't do anything about this Debian bug, and this detection allows us to
|
426 |
+
skip the warning when needed.
|
427 |
+
"""
|
428 |
+
if not _looks_like_debian_scheme():
|
429 |
+
return False
|
430 |
+
if value == "/usr/lib/python3/dist-packages":
|
431 |
+
return True
|
432 |
+
return False
|
433 |
+
|
434 |
+
|
435 |
+
def get_purelib() -> str:
|
436 |
+
"""Return the default pure-Python lib location."""
|
437 |
+
new = _sysconfig.get_purelib()
|
438 |
+
if _USE_SYSCONFIG:
|
439 |
+
return new
|
440 |
+
|
441 |
+
old = _distutils.get_purelib()
|
442 |
+
if _looks_like_deb_system_dist_packages(old):
|
443 |
+
return old
|
444 |
+
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="purelib"):
|
445 |
+
_log_context()
|
446 |
+
return old
|
447 |
+
|
448 |
+
|
449 |
+
def get_platlib() -> str:
|
450 |
+
"""Return the default platform-shared lib location."""
|
451 |
+
new = _sysconfig.get_platlib()
|
452 |
+
if _USE_SYSCONFIG:
|
453 |
+
return new
|
454 |
+
|
455 |
+
old = _distutils.get_platlib()
|
456 |
+
if _looks_like_deb_system_dist_packages(old):
|
457 |
+
return old
|
458 |
+
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="platlib"):
|
459 |
+
_log_context()
|
460 |
+
return old
|
461 |
+
|
462 |
+
|
463 |
+
def _deduplicated(v1: str, v2: str) -> List[str]:
|
464 |
+
"""Deduplicate values from a list."""
|
465 |
+
if v1 == v2:
|
466 |
+
return [v1]
|
467 |
+
return [v1, v2]
|
468 |
+
|
469 |
+
|
470 |
+
def _looks_like_apple_library(path: str) -> bool:
|
471 |
+
"""Apple patches sysconfig to *always* look under */Library/Python*."""
|
472 |
+
if sys.platform[:6] != "darwin":
|
473 |
+
return False
|
474 |
+
return path == f"/Library/Python/{get_major_minor_version()}/site-packages"
|
475 |
+
|
476 |
+
|
477 |
+
def get_prefixed_libs(prefix: str) -> List[str]:
|
478 |
+
"""Return the lib locations under ``prefix``."""
|
479 |
+
new_pure, new_plat = _sysconfig.get_prefixed_libs(prefix)
|
480 |
+
if _USE_SYSCONFIG:
|
481 |
+
return _deduplicated(new_pure, new_plat)
|
482 |
+
|
483 |
+
old_pure, old_plat = _distutils.get_prefixed_libs(prefix)
|
484 |
+
old_lib_paths = _deduplicated(old_pure, old_plat)
|
485 |
+
|
486 |
+
# Apple's Python (shipped with Xcode and Command Line Tools) hard-code
|
487 |
+
# platlib and purelib to '/Library/Python/X.Y/site-packages'. This will
|
488 |
+
# cause serious build isolation bugs when Apple starts shipping 3.10 because
|
489 |
+
# pip will install build backends to the wrong location. This tells users
|
490 |
+
# who is at fault so Apple may notice it and fix the issue in time.
|
491 |
+
if all(_looks_like_apple_library(p) for p in old_lib_paths):
|
492 |
+
deprecated(
|
493 |
+
reason=(
|
494 |
+
"Python distributed by Apple's Command Line Tools incorrectly "
|
495 |
+
"patches sysconfig to always point to '/Library/Python'. This "
|
496 |
+
"will cause build isolation to operate incorrectly on Python "
|
497 |
+
"3.10 or later. Please help report this to Apple so they can "
|
498 |
+
"fix this. https://developer.apple.com/bug-reporting/"
|
499 |
+
),
|
500 |
+
replacement=None,
|
501 |
+
gone_in=None,
|
502 |
+
)
|
503 |
+
return old_lib_paths
|
504 |
+
|
505 |
+
warned = [
|
506 |
+
_warn_if_mismatch(
|
507 |
+
pathlib.Path(old_pure),
|
508 |
+
pathlib.Path(new_pure),
|
509 |
+
key="prefixed-purelib",
|
510 |
+
),
|
511 |
+
_warn_if_mismatch(
|
512 |
+
pathlib.Path(old_plat),
|
513 |
+
pathlib.Path(new_plat),
|
514 |
+
key="prefixed-platlib",
|
515 |
+
),
|
516 |
+
]
|
517 |
+
if any(warned):
|
518 |
+
_log_context(prefix=prefix)
|
519 |
+
|
520 |
+
return old_lib_paths
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (12.4 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_distutils.cpython-310.pyc
ADDED
Binary file (4.66 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_sysconfig.cpython-310.pyc
ADDED
Binary file (6.24 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/base.cpython-310.pyc
ADDED
Binary file (1.54 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/_distutils.py
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Locations where we look for configs, install stuff, etc"""
|
2 |
+
|
3 |
+
# The following comment should be removed at some point in the future.
|
4 |
+
# mypy: strict-optional=False
|
5 |
+
|
6 |
+
import logging
|
7 |
+
import os
|
8 |
+
import sys
|
9 |
+
from distutils.cmd import Command as DistutilsCommand
|
10 |
+
from distutils.command.install import SCHEME_KEYS
|
11 |
+
from distutils.command.install import install as distutils_install_command
|
12 |
+
from distutils.sysconfig import get_python_lib
|
13 |
+
from typing import Dict, List, Optional, Tuple, Union, cast
|
14 |
+
|
15 |
+
from pip._internal.models.scheme import Scheme
|
16 |
+
from pip._internal.utils.compat import WINDOWS
|
17 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
18 |
+
|
19 |
+
from .base import get_major_minor_version
|
20 |
+
|
21 |
+
logger = logging.getLogger(__name__)
|
22 |
+
|
23 |
+
|
24 |
+
def distutils_scheme(
|
25 |
+
dist_name: str,
|
26 |
+
user: bool = False,
|
27 |
+
home: str = None,
|
28 |
+
root: str = None,
|
29 |
+
isolated: bool = False,
|
30 |
+
prefix: str = None,
|
31 |
+
*,
|
32 |
+
ignore_config_files: bool = False,
|
33 |
+
) -> Dict[str, str]:
|
34 |
+
"""
|
35 |
+
Return a distutils install scheme
|
36 |
+
"""
|
37 |
+
from distutils.dist import Distribution
|
38 |
+
|
39 |
+
dist_args: Dict[str, Union[str, List[str]]] = {"name": dist_name}
|
40 |
+
if isolated:
|
41 |
+
dist_args["script_args"] = ["--no-user-cfg"]
|
42 |
+
|
43 |
+
d = Distribution(dist_args)
|
44 |
+
if not ignore_config_files:
|
45 |
+
try:
|
46 |
+
d.parse_config_files()
|
47 |
+
except UnicodeDecodeError:
|
48 |
+
# Typeshed does not include find_config_files() for some reason.
|
49 |
+
paths = d.find_config_files() # type: ignore
|
50 |
+
logger.warning(
|
51 |
+
"Ignore distutils configs in %s due to encoding errors.",
|
52 |
+
", ".join(os.path.basename(p) for p in paths),
|
53 |
+
)
|
54 |
+
obj: Optional[DistutilsCommand] = None
|
55 |
+
obj = d.get_command_obj("install", create=True)
|
56 |
+
assert obj is not None
|
57 |
+
i = cast(distutils_install_command, obj)
|
58 |
+
# NOTE: setting user or home has the side-effect of creating the home dir
|
59 |
+
# or user base for installations during finalize_options()
|
60 |
+
# ideally, we'd prefer a scheme class that has no side-effects.
|
61 |
+
assert not (user and prefix), f"user={user} prefix={prefix}"
|
62 |
+
assert not (home and prefix), f"home={home} prefix={prefix}"
|
63 |
+
i.user = user or i.user
|
64 |
+
if user or home:
|
65 |
+
i.prefix = ""
|
66 |
+
i.prefix = prefix or i.prefix
|
67 |
+
i.home = home or i.home
|
68 |
+
i.root = root or i.root
|
69 |
+
i.finalize_options()
|
70 |
+
|
71 |
+
scheme = {}
|
72 |
+
for key in SCHEME_KEYS:
|
73 |
+
scheme[key] = getattr(i, "install_" + key)
|
74 |
+
|
75 |
+
# install_lib specified in setup.cfg should install *everything*
|
76 |
+
# into there (i.e. it takes precedence over both purelib and
|
77 |
+
# platlib). Note, i.install_lib is *always* set after
|
78 |
+
# finalize_options(); we only want to override here if the user
|
79 |
+
# has explicitly requested it hence going back to the config
|
80 |
+
if "install_lib" in d.get_option_dict("install"):
|
81 |
+
scheme.update(dict(purelib=i.install_lib, platlib=i.install_lib))
|
82 |
+
|
83 |
+
if running_under_virtualenv():
|
84 |
+
if home:
|
85 |
+
prefix = home
|
86 |
+
elif user:
|
87 |
+
prefix = i.install_userbase # type: ignore
|
88 |
+
else:
|
89 |
+
prefix = i.prefix
|
90 |
+
scheme["headers"] = os.path.join(
|
91 |
+
prefix,
|
92 |
+
"include",
|
93 |
+
"site",
|
94 |
+
f"python{get_major_minor_version()}",
|
95 |
+
dist_name,
|
96 |
+
)
|
97 |
+
|
98 |
+
if root is not None:
|
99 |
+
path_no_drive = os.path.splitdrive(os.path.abspath(scheme["headers"]))[1]
|
100 |
+
scheme["headers"] = os.path.join(root, path_no_drive[1:])
|
101 |
+
|
102 |
+
return scheme
|
103 |
+
|
104 |
+
|
105 |
+
def get_scheme(
|
106 |
+
dist_name: str,
|
107 |
+
user: bool = False,
|
108 |
+
home: Optional[str] = None,
|
109 |
+
root: Optional[str] = None,
|
110 |
+
isolated: bool = False,
|
111 |
+
prefix: Optional[str] = None,
|
112 |
+
) -> Scheme:
|
113 |
+
"""
|
114 |
+
Get the "scheme" corresponding to the input parameters. The distutils
|
115 |
+
documentation provides the context for the available schemes:
|
116 |
+
https://docs.python.org/3/install/index.html#alternate-installation
|
117 |
+
|
118 |
+
:param dist_name: the name of the package to retrieve the scheme for, used
|
119 |
+
in the headers scheme path
|
120 |
+
:param user: indicates to use the "user" scheme
|
121 |
+
:param home: indicates to use the "home" scheme and provides the base
|
122 |
+
directory for the same
|
123 |
+
:param root: root under which other directories are re-based
|
124 |
+
:param isolated: equivalent to --no-user-cfg, i.e. do not consider
|
125 |
+
~/.pydistutils.cfg (posix) or ~/pydistutils.cfg (non-posix) for
|
126 |
+
scheme paths
|
127 |
+
:param prefix: indicates to use the "prefix" scheme and provides the
|
128 |
+
base directory for the same
|
129 |
+
"""
|
130 |
+
scheme = distutils_scheme(dist_name, user, home, root, isolated, prefix)
|
131 |
+
return Scheme(
|
132 |
+
platlib=scheme["platlib"],
|
133 |
+
purelib=scheme["purelib"],
|
134 |
+
headers=scheme["headers"],
|
135 |
+
scripts=scheme["scripts"],
|
136 |
+
data=scheme["data"],
|
137 |
+
)
|
138 |
+
|
139 |
+
|
140 |
+
def get_bin_prefix() -> str:
|
141 |
+
# XXX: In old virtualenv versions, sys.prefix can contain '..' components,
|
142 |
+
# so we need to call normpath to eliminate them.
|
143 |
+
prefix = os.path.normpath(sys.prefix)
|
144 |
+
if WINDOWS:
|
145 |
+
bin_py = os.path.join(prefix, "Scripts")
|
146 |
+
# buildout uses 'bin' on Windows too?
|
147 |
+
if not os.path.exists(bin_py):
|
148 |
+
bin_py = os.path.join(prefix, "bin")
|
149 |
+
return bin_py
|
150 |
+
# Forcing to use /usr/local/bin for standard macOS framework installs
|
151 |
+
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
|
152 |
+
if sys.platform[:6] == "darwin" and prefix[:16] == "/System/Library/":
|
153 |
+
return "/usr/local/bin"
|
154 |
+
return os.path.join(prefix, "bin")
|
155 |
+
|
156 |
+
|
157 |
+
def get_purelib() -> str:
|
158 |
+
return get_python_lib(plat_specific=False)
|
159 |
+
|
160 |
+
|
161 |
+
def get_platlib() -> str:
|
162 |
+
return get_python_lib(plat_specific=True)
|
163 |
+
|
164 |
+
|
165 |
+
def get_prefixed_libs(prefix: str) -> Tuple[str, str]:
|
166 |
+
return (
|
167 |
+
get_python_lib(plat_specific=False, prefix=prefix),
|
168 |
+
get_python_lib(plat_specific=True, prefix=prefix),
|
169 |
+
)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/_sysconfig.py
ADDED
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import distutils.util # FIXME: For change_root.
|
2 |
+
import logging
|
3 |
+
import os
|
4 |
+
import sys
|
5 |
+
import sysconfig
|
6 |
+
import typing
|
7 |
+
|
8 |
+
from pip._internal.exceptions import InvalidSchemeCombination, UserInstallationInvalid
|
9 |
+
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
|
10 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
11 |
+
|
12 |
+
from .base import get_major_minor_version, is_osx_framework
|
13 |
+
|
14 |
+
logger = logging.getLogger(__name__)
|
15 |
+
|
16 |
+
|
17 |
+
# Notes on _infer_* functions.
|
18 |
+
# Unfortunately ``get_default_scheme()`` didn't exist before 3.10, so there's no
|
19 |
+
# way to ask things like "what is the '_prefix' scheme on this platform". These
|
20 |
+
# functions try to answer that with some heuristics while accounting for ad-hoc
|
21 |
+
# platforms not covered by CPython's default sysconfig implementation. If the
|
22 |
+
# ad-hoc implementation does not fully implement sysconfig, we'll fall back to
|
23 |
+
# a POSIX scheme.
|
24 |
+
|
25 |
+
_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())
|
26 |
+
|
27 |
+
_PREFERRED_SCHEME_API = getattr(sysconfig, "get_preferred_scheme", None)
|
28 |
+
|
29 |
+
|
30 |
+
def _should_use_osx_framework_prefix() -> bool:
|
31 |
+
"""Check for Apple's ``osx_framework_library`` scheme.
|
32 |
+
|
33 |
+
Python distributed by Apple's Command Line Tools has this special scheme
|
34 |
+
that's used when:
|
35 |
+
|
36 |
+
* This is a framework build.
|
37 |
+
* We are installing into the system prefix.
|
38 |
+
|
39 |
+
This does not account for ``pip install --prefix`` (also means we're not
|
40 |
+
installing to the system prefix), which should use ``posix_prefix``, but
|
41 |
+
logic here means ``_infer_prefix()`` outputs ``osx_framework_library``. But
|
42 |
+
since ``prefix`` is not available for ``sysconfig.get_default_scheme()``,
|
43 |
+
which is the stdlib replacement for ``_infer_prefix()``, presumably Apple
|
44 |
+
wouldn't be able to magically switch between ``osx_framework_library`` and
|
45 |
+
``posix_prefix``. ``_infer_prefix()`` returning ``osx_framework_library``
|
46 |
+
means its behavior is consistent whether we use the stdlib implementation
|
47 |
+
or our own, and we deal with this special case in ``get_scheme()`` instead.
|
48 |
+
"""
|
49 |
+
return (
|
50 |
+
"osx_framework_library" in _AVAILABLE_SCHEMES
|
51 |
+
and not running_under_virtualenv()
|
52 |
+
and is_osx_framework()
|
53 |
+
)
|
54 |
+
|
55 |
+
|
56 |
+
def _infer_prefix() -> str:
|
57 |
+
"""Try to find a prefix scheme for the current platform.
|
58 |
+
|
59 |
+
This tries:
|
60 |
+
|
61 |
+
* A special ``osx_framework_library`` for Python distributed by Apple's
|
62 |
+
Command Line Tools, when not running in a virtual environment.
|
63 |
+
* Implementation + OS, used by PyPy on Windows (``pypy_nt``).
|
64 |
+
* Implementation without OS, used by PyPy on POSIX (``pypy``).
|
65 |
+
* OS + "prefix", used by CPython on POSIX (``posix_prefix``).
|
66 |
+
* Just the OS name, used by CPython on Windows (``nt``).
|
67 |
+
|
68 |
+
If none of the above works, fall back to ``posix_prefix``.
|
69 |
+
"""
|
70 |
+
if _PREFERRED_SCHEME_API:
|
71 |
+
return _PREFERRED_SCHEME_API("prefix")
|
72 |
+
if _should_use_osx_framework_prefix():
|
73 |
+
return "osx_framework_library"
|
74 |
+
implementation_suffixed = f"{sys.implementation.name}_{os.name}"
|
75 |
+
if implementation_suffixed in _AVAILABLE_SCHEMES:
|
76 |
+
return implementation_suffixed
|
77 |
+
if sys.implementation.name in _AVAILABLE_SCHEMES:
|
78 |
+
return sys.implementation.name
|
79 |
+
suffixed = f"{os.name}_prefix"
|
80 |
+
if suffixed in _AVAILABLE_SCHEMES:
|
81 |
+
return suffixed
|
82 |
+
if os.name in _AVAILABLE_SCHEMES: # On Windows, prefx is just called "nt".
|
83 |
+
return os.name
|
84 |
+
return "posix_prefix"
|
85 |
+
|
86 |
+
|
87 |
+
def _infer_user() -> str:
|
88 |
+
"""Try to find a user scheme for the current platform."""
|
89 |
+
if _PREFERRED_SCHEME_API:
|
90 |
+
return _PREFERRED_SCHEME_API("user")
|
91 |
+
if is_osx_framework() and not running_under_virtualenv():
|
92 |
+
suffixed = "osx_framework_user"
|
93 |
+
else:
|
94 |
+
suffixed = f"{os.name}_user"
|
95 |
+
if suffixed in _AVAILABLE_SCHEMES:
|
96 |
+
return suffixed
|
97 |
+
if "posix_user" not in _AVAILABLE_SCHEMES: # User scheme unavailable.
|
98 |
+
raise UserInstallationInvalid()
|
99 |
+
return "posix_user"
|
100 |
+
|
101 |
+
|
102 |
+
def _infer_home() -> str:
|
103 |
+
"""Try to find a home for the current platform."""
|
104 |
+
if _PREFERRED_SCHEME_API:
|
105 |
+
return _PREFERRED_SCHEME_API("home")
|
106 |
+
suffixed = f"{os.name}_home"
|
107 |
+
if suffixed in _AVAILABLE_SCHEMES:
|
108 |
+
return suffixed
|
109 |
+
return "posix_home"
|
110 |
+
|
111 |
+
|
112 |
+
# Update these keys if the user sets a custom home.
|
113 |
+
_HOME_KEYS = [
|
114 |
+
"installed_base",
|
115 |
+
"base",
|
116 |
+
"installed_platbase",
|
117 |
+
"platbase",
|
118 |
+
"prefix",
|
119 |
+
"exec_prefix",
|
120 |
+
]
|
121 |
+
if sysconfig.get_config_var("userbase") is not None:
|
122 |
+
_HOME_KEYS.append("userbase")
|
123 |
+
|
124 |
+
|
125 |
+
def get_scheme(
|
126 |
+
dist_name: str,
|
127 |
+
user: bool = False,
|
128 |
+
home: typing.Optional[str] = None,
|
129 |
+
root: typing.Optional[str] = None,
|
130 |
+
isolated: bool = False,
|
131 |
+
prefix: typing.Optional[str] = None,
|
132 |
+
) -> Scheme:
|
133 |
+
"""
|
134 |
+
Get the "scheme" corresponding to the input parameters.
|
135 |
+
|
136 |
+
:param dist_name: the name of the package to retrieve the scheme for, used
|
137 |
+
in the headers scheme path
|
138 |
+
:param user: indicates to use the "user" scheme
|
139 |
+
:param home: indicates to use the "home" scheme
|
140 |
+
:param root: root under which other directories are re-based
|
141 |
+
:param isolated: ignored, but kept for distutils compatibility (where
|
142 |
+
this controls whether the user-site pydistutils.cfg is honored)
|
143 |
+
:param prefix: indicates to use the "prefix" scheme and provides the
|
144 |
+
base directory for the same
|
145 |
+
"""
|
146 |
+
if user and prefix:
|
147 |
+
raise InvalidSchemeCombination("--user", "--prefix")
|
148 |
+
if home and prefix:
|
149 |
+
raise InvalidSchemeCombination("--home", "--prefix")
|
150 |
+
|
151 |
+
if home is not None:
|
152 |
+
scheme_name = _infer_home()
|
153 |
+
elif user:
|
154 |
+
scheme_name = _infer_user()
|
155 |
+
else:
|
156 |
+
scheme_name = _infer_prefix()
|
157 |
+
|
158 |
+
# Special case: When installing into a custom prefix, use posix_prefix
|
159 |
+
# instead of osx_framework_library. See _should_use_osx_framework_prefix()
|
160 |
+
# docstring for details.
|
161 |
+
if prefix is not None and scheme_name == "osx_framework_library":
|
162 |
+
scheme_name = "posix_prefix"
|
163 |
+
|
164 |
+
if home is not None:
|
165 |
+
variables = {k: home for k in _HOME_KEYS}
|
166 |
+
elif prefix is not None:
|
167 |
+
variables = {k: prefix for k in _HOME_KEYS}
|
168 |
+
else:
|
169 |
+
variables = {}
|
170 |
+
|
171 |
+
paths = sysconfig.get_paths(scheme=scheme_name, vars=variables)
|
172 |
+
|
173 |
+
# Logic here is very arbitrary, we're doing it for compatibility, don't ask.
|
174 |
+
# 1. Pip historically uses a special header path in virtual environments.
|
175 |
+
# 2. If the distribution name is not known, distutils uses 'UNKNOWN'. We
|
176 |
+
# only do the same when not running in a virtual environment because
|
177 |
+
# pip's historical header path logic (see point 1) did not do this.
|
178 |
+
if running_under_virtualenv():
|
179 |
+
if user:
|
180 |
+
base = variables.get("userbase", sys.prefix)
|
181 |
+
else:
|
182 |
+
base = variables.get("base", sys.prefix)
|
183 |
+
python_xy = f"python{get_major_minor_version()}"
|
184 |
+
paths["include"] = os.path.join(base, "include", "site", python_xy)
|
185 |
+
elif not dist_name:
|
186 |
+
dist_name = "UNKNOWN"
|
187 |
+
|
188 |
+
scheme = Scheme(
|
189 |
+
platlib=paths["platlib"],
|
190 |
+
purelib=paths["purelib"],
|
191 |
+
headers=os.path.join(paths["include"], dist_name),
|
192 |
+
scripts=paths["scripts"],
|
193 |
+
data=paths["data"],
|
194 |
+
)
|
195 |
+
if root is not None:
|
196 |
+
for key in SCHEME_KEYS:
|
197 |
+
value = distutils.util.change_root(root, getattr(scheme, key))
|
198 |
+
setattr(scheme, key, value)
|
199 |
+
return scheme
|
200 |
+
|
201 |
+
|
202 |
+
def get_bin_prefix() -> str:
|
203 |
+
# Forcing to use /usr/local/bin for standard macOS framework installs.
|
204 |
+
if sys.platform[:6] == "darwin" and sys.prefix[:16] == "/System/Library/":
|
205 |
+
return "/usr/local/bin"
|
206 |
+
return sysconfig.get_paths()["scripts"]
|
207 |
+
|
208 |
+
|
209 |
+
def get_purelib() -> str:
|
210 |
+
return sysconfig.get_paths()["purelib"]
|
211 |
+
|
212 |
+
|
213 |
+
def get_platlib() -> str:
|
214 |
+
return sysconfig.get_paths()["platlib"]
|
215 |
+
|
216 |
+
|
217 |
+
def get_prefixed_libs(prefix: str) -> typing.Tuple[str, str]:
|
218 |
+
paths = sysconfig.get_paths(vars={"base": prefix, "platbase": prefix})
|
219 |
+
return (paths["purelib"], paths["platlib"])
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/locations/base.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import functools
|
2 |
+
import os
|
3 |
+
import site
|
4 |
+
import sys
|
5 |
+
import sysconfig
|
6 |
+
import typing
|
7 |
+
|
8 |
+
from pip._internal.utils import appdirs
|
9 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
10 |
+
|
11 |
+
# Application Directories
|
12 |
+
USER_CACHE_DIR = appdirs.user_cache_dir("pip")
|
13 |
+
|
14 |
+
# FIXME doesn't account for venv linked to global site-packages
|
15 |
+
site_packages: typing.Optional[str] = sysconfig.get_path("purelib")
|
16 |
+
|
17 |
+
|
18 |
+
def get_major_minor_version() -> str:
|
19 |
+
"""
|
20 |
+
Return the major-minor version of the current Python as a string, e.g.
|
21 |
+
"3.7" or "3.10".
|
22 |
+
"""
|
23 |
+
return "{}.{}".format(*sys.version_info)
|
24 |
+
|
25 |
+
|
26 |
+
def get_src_prefix() -> str:
|
27 |
+
if running_under_virtualenv():
|
28 |
+
src_prefix = os.path.join(sys.prefix, "src")
|
29 |
+
else:
|
30 |
+
# FIXME: keep src in cwd for now (it is not a temporary folder)
|
31 |
+
try:
|
32 |
+
src_prefix = os.path.join(os.getcwd(), "src")
|
33 |
+
except OSError:
|
34 |
+
# In case the current working directory has been renamed or deleted
|
35 |
+
sys.exit("The folder you are executing pip from can no longer be found.")
|
36 |
+
|
37 |
+
# under macOS + virtualenv sys.prefix is not properly resolved
|
38 |
+
# it is something like /path/to/python/bin/..
|
39 |
+
return os.path.abspath(src_prefix)
|
40 |
+
|
41 |
+
|
42 |
+
try:
|
43 |
+
# Use getusersitepackages if this is present, as it ensures that the
|
44 |
+
# value is initialised properly.
|
45 |
+
user_site: typing.Optional[str] = site.getusersitepackages()
|
46 |
+
except AttributeError:
|
47 |
+
user_site = site.USER_SITE
|
48 |
+
|
49 |
+
|
50 |
+
@functools.lru_cache(maxsize=None)
|
51 |
+
def is_osx_framework() -> bool:
|
52 |
+
return bool(sysconfig.get_config_var("PYTHONFRAMEWORK"))
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/main.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Optional
|
2 |
+
|
3 |
+
|
4 |
+
def main(args: Optional[List[str]] = None) -> int:
|
5 |
+
"""This is preserved for old console scripts that may still be referencing
|
6 |
+
it.
|
7 |
+
|
8 |
+
For additional details, see https://github.com/pypa/pip/issues/7498.
|
9 |
+
"""
|
10 |
+
from pip._internal.utils.entrypoints import _wrapper
|
11 |
+
|
12 |
+
return _wrapper(args)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/pyproject.py
ADDED
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from collections import namedtuple
|
3 |
+
from typing import Any, List, Optional
|
4 |
+
|
5 |
+
from pip._vendor import tomli
|
6 |
+
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
|
7 |
+
|
8 |
+
from pip._internal.exceptions import (
|
9 |
+
InstallationError,
|
10 |
+
InvalidPyProjectBuildRequires,
|
11 |
+
MissingPyProjectBuildRequires,
|
12 |
+
)
|
13 |
+
|
14 |
+
|
15 |
+
def _is_list_of_str(obj: Any) -> bool:
|
16 |
+
return isinstance(obj, list) and all(isinstance(item, str) for item in obj)
|
17 |
+
|
18 |
+
|
19 |
+
def make_pyproject_path(unpacked_source_directory: str) -> str:
|
20 |
+
return os.path.join(unpacked_source_directory, "pyproject.toml")
|
21 |
+
|
22 |
+
|
23 |
+
BuildSystemDetails = namedtuple(
|
24 |
+
"BuildSystemDetails", ["requires", "backend", "check", "backend_path"]
|
25 |
+
)
|
26 |
+
|
27 |
+
|
28 |
+
def load_pyproject_toml(
|
29 |
+
use_pep517: Optional[bool], pyproject_toml: str, setup_py: str, req_name: str
|
30 |
+
) -> Optional[BuildSystemDetails]:
|
31 |
+
"""Load the pyproject.toml file.
|
32 |
+
|
33 |
+
Parameters:
|
34 |
+
use_pep517 - Has the user requested PEP 517 processing? None
|
35 |
+
means the user hasn't explicitly specified.
|
36 |
+
pyproject_toml - Location of the project's pyproject.toml file
|
37 |
+
setup_py - Location of the project's setup.py file
|
38 |
+
req_name - The name of the requirement we're processing (for
|
39 |
+
error reporting)
|
40 |
+
|
41 |
+
Returns:
|
42 |
+
None if we should use the legacy code path, otherwise a tuple
|
43 |
+
(
|
44 |
+
requirements from pyproject.toml,
|
45 |
+
name of PEP 517 backend,
|
46 |
+
requirements we should check are installed after setting
|
47 |
+
up the build environment
|
48 |
+
directory paths to import the backend from (backend-path),
|
49 |
+
relative to the project root.
|
50 |
+
)
|
51 |
+
"""
|
52 |
+
has_pyproject = os.path.isfile(pyproject_toml)
|
53 |
+
has_setup = os.path.isfile(setup_py)
|
54 |
+
|
55 |
+
if not has_pyproject and not has_setup:
|
56 |
+
raise InstallationError(
|
57 |
+
f"{req_name} does not appear to be a Python project: "
|
58 |
+
f"neither 'setup.py' nor 'pyproject.toml' found."
|
59 |
+
)
|
60 |
+
|
61 |
+
if has_pyproject:
|
62 |
+
with open(pyproject_toml, encoding="utf-8") as f:
|
63 |
+
pp_toml = tomli.loads(f.read())
|
64 |
+
build_system = pp_toml.get("build-system")
|
65 |
+
else:
|
66 |
+
build_system = None
|
67 |
+
|
68 |
+
# The following cases must use PEP 517
|
69 |
+
# We check for use_pep517 being non-None and falsey because that means
|
70 |
+
# the user explicitly requested --no-use-pep517. The value 0 as
|
71 |
+
# opposed to False can occur when the value is provided via an
|
72 |
+
# environment variable or config file option (due to the quirk of
|
73 |
+
# strtobool() returning an integer in pip's configuration code).
|
74 |
+
if has_pyproject and not has_setup:
|
75 |
+
if use_pep517 is not None and not use_pep517:
|
76 |
+
raise InstallationError(
|
77 |
+
"Disabling PEP 517 processing is invalid: "
|
78 |
+
"project does not have a setup.py"
|
79 |
+
)
|
80 |
+
use_pep517 = True
|
81 |
+
elif build_system and "build-backend" in build_system:
|
82 |
+
if use_pep517 is not None and not use_pep517:
|
83 |
+
raise InstallationError(
|
84 |
+
"Disabling PEP 517 processing is invalid: "
|
85 |
+
"project specifies a build backend of {} "
|
86 |
+
"in pyproject.toml".format(build_system["build-backend"])
|
87 |
+
)
|
88 |
+
use_pep517 = True
|
89 |
+
|
90 |
+
# If we haven't worked out whether to use PEP 517 yet,
|
91 |
+
# and the user hasn't explicitly stated a preference,
|
92 |
+
# we do so if the project has a pyproject.toml file.
|
93 |
+
elif use_pep517 is None:
|
94 |
+
use_pep517 = has_pyproject
|
95 |
+
|
96 |
+
# At this point, we know whether we're going to use PEP 517.
|
97 |
+
assert use_pep517 is not None
|
98 |
+
|
99 |
+
# If we're using the legacy code path, there is nothing further
|
100 |
+
# for us to do here.
|
101 |
+
if not use_pep517:
|
102 |
+
return None
|
103 |
+
|
104 |
+
if build_system is None:
|
105 |
+
# Either the user has a pyproject.toml with no build-system
|
106 |
+
# section, or the user has no pyproject.toml, but has opted in
|
107 |
+
# explicitly via --use-pep517.
|
108 |
+
# In the absence of any explicit backend specification, we
|
109 |
+
# assume the setuptools backend that most closely emulates the
|
110 |
+
# traditional direct setup.py execution, and require wheel and
|
111 |
+
# a version of setuptools that supports that backend.
|
112 |
+
|
113 |
+
build_system = {
|
114 |
+
"requires": ["setuptools>=40.8.0", "wheel"],
|
115 |
+
"build-backend": "setuptools.build_meta:__legacy__",
|
116 |
+
}
|
117 |
+
|
118 |
+
# If we're using PEP 517, we have build system information (either
|
119 |
+
# from pyproject.toml, or defaulted by the code above).
|
120 |
+
# Note that at this point, we do not know if the user has actually
|
121 |
+
# specified a backend, though.
|
122 |
+
assert build_system is not None
|
123 |
+
|
124 |
+
# Ensure that the build-system section in pyproject.toml conforms
|
125 |
+
# to PEP 518.
|
126 |
+
|
127 |
+
# Specifying the build-system table but not the requires key is invalid
|
128 |
+
if "requires" not in build_system:
|
129 |
+
raise MissingPyProjectBuildRequires(package=req_name)
|
130 |
+
|
131 |
+
# Error out if requires is not a list of strings
|
132 |
+
requires = build_system["requires"]
|
133 |
+
if not _is_list_of_str(requires):
|
134 |
+
raise InvalidPyProjectBuildRequires(
|
135 |
+
package=req_name,
|
136 |
+
reason="It is not a list of strings.",
|
137 |
+
)
|
138 |
+
|
139 |
+
# Each requirement must be valid as per PEP 508
|
140 |
+
for requirement in requires:
|
141 |
+
try:
|
142 |
+
Requirement(requirement)
|
143 |
+
except InvalidRequirement as error:
|
144 |
+
raise InvalidPyProjectBuildRequires(
|
145 |
+
package=req_name,
|
146 |
+
reason=f"It contains an invalid requirement: {requirement!r}",
|
147 |
+
) from error
|
148 |
+
|
149 |
+
backend = build_system.get("build-backend")
|
150 |
+
backend_path = build_system.get("backend-path", [])
|
151 |
+
check: List[str] = []
|
152 |
+
if backend is None:
|
153 |
+
# If the user didn't specify a backend, we assume they want to use
|
154 |
+
# the setuptools backend. But we can't be sure they have included
|
155 |
+
# a version of setuptools which supplies the backend, or wheel
|
156 |
+
# (which is needed by the backend) in their requirements. So we
|
157 |
+
# make a note to check that those requirements are present once
|
158 |
+
# we have set up the environment.
|
159 |
+
# This is quite a lot of work to check for a very specific case. But
|
160 |
+
# the problem is, that case is potentially quite common - projects that
|
161 |
+
# adopted PEP 518 early for the ability to specify requirements to
|
162 |
+
# execute setup.py, but never considered needing to mention the build
|
163 |
+
# tools themselves. The original PEP 518 code had a similar check (but
|
164 |
+
# implemented in a different way).
|
165 |
+
backend = "setuptools.build_meta:__legacy__"
|
166 |
+
check = ["setuptools>=40.8.0", "wheel"]
|
167 |
+
|
168 |
+
return BuildSystemDetails(requires, backend, check, backend_path)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (199 Bytes). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/__pycache__/base.cpython-310.pyc
ADDED
Binary file (1.05 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/base.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Callable, List, Optional
|
2 |
+
|
3 |
+
from pip._internal.req.req_install import InstallRequirement
|
4 |
+
from pip._internal.req.req_set import RequirementSet
|
5 |
+
|
6 |
+
InstallRequirementProvider = Callable[
|
7 |
+
[str, Optional[InstallRequirement]], InstallRequirement
|
8 |
+
]
|
9 |
+
|
10 |
+
|
11 |
+
class BaseResolver:
|
12 |
+
def resolve(
|
13 |
+
self, root_reqs: List[InstallRequirement], check_supported_wheels: bool
|
14 |
+
) -> RequirementSet:
|
15 |
+
raise NotImplementedError()
|
16 |
+
|
17 |
+
def get_installation_order(
|
18 |
+
self, req_set: RequirementSet
|
19 |
+
) -> List[InstallRequirement]:
|
20 |
+
raise NotImplementedError()
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/legacy/__init__.py
ADDED
File without changes
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/legacy/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (206 Bytes). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/legacy/resolver.py
ADDED
@@ -0,0 +1,467 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Dependency Resolution
|
2 |
+
|
3 |
+
The dependency resolution in pip is performed as follows:
|
4 |
+
|
5 |
+
for top-level requirements:
|
6 |
+
a. only one spec allowed per project, regardless of conflicts or not.
|
7 |
+
otherwise a "double requirement" exception is raised
|
8 |
+
b. they override sub-dependency requirements.
|
9 |
+
for sub-dependencies
|
10 |
+
a. "first found, wins" (where the order is breadth first)
|
11 |
+
"""
|
12 |
+
|
13 |
+
# The following comment should be removed at some point in the future.
|
14 |
+
# mypy: strict-optional=False
|
15 |
+
|
16 |
+
import logging
|
17 |
+
import sys
|
18 |
+
from collections import defaultdict
|
19 |
+
from itertools import chain
|
20 |
+
from typing import DefaultDict, Iterable, List, Optional, Set, Tuple
|
21 |
+
|
22 |
+
from pip._vendor.packaging import specifiers
|
23 |
+
from pip._vendor.packaging.requirements import Requirement
|
24 |
+
|
25 |
+
from pip._internal.cache import WheelCache
|
26 |
+
from pip._internal.exceptions import (
|
27 |
+
BestVersionAlreadyInstalled,
|
28 |
+
DistributionNotFound,
|
29 |
+
HashError,
|
30 |
+
HashErrors,
|
31 |
+
NoneMetadataError,
|
32 |
+
UnsupportedPythonVersion,
|
33 |
+
)
|
34 |
+
from pip._internal.index.package_finder import PackageFinder
|
35 |
+
from pip._internal.metadata import BaseDistribution
|
36 |
+
from pip._internal.models.link import Link
|
37 |
+
from pip._internal.operations.prepare import RequirementPreparer
|
38 |
+
from pip._internal.req.req_install import (
|
39 |
+
InstallRequirement,
|
40 |
+
check_invalid_constraint_type,
|
41 |
+
)
|
42 |
+
from pip._internal.req.req_set import RequirementSet
|
43 |
+
from pip._internal.resolution.base import BaseResolver, InstallRequirementProvider
|
44 |
+
from pip._internal.utils.compatibility_tags import get_supported
|
45 |
+
from pip._internal.utils.logging import indent_log
|
46 |
+
from pip._internal.utils.misc import normalize_version_info
|
47 |
+
from pip._internal.utils.packaging import check_requires_python
|
48 |
+
|
49 |
+
logger = logging.getLogger(__name__)
|
50 |
+
|
51 |
+
DiscoveredDependencies = DefaultDict[str, List[InstallRequirement]]
|
52 |
+
|
53 |
+
|
54 |
+
def _check_dist_requires_python(
|
55 |
+
dist: BaseDistribution,
|
56 |
+
version_info: Tuple[int, int, int],
|
57 |
+
ignore_requires_python: bool = False,
|
58 |
+
) -> None:
|
59 |
+
"""
|
60 |
+
Check whether the given Python version is compatible with a distribution's
|
61 |
+
"Requires-Python" value.
|
62 |
+
|
63 |
+
:param version_info: A 3-tuple of ints representing the Python
|
64 |
+
major-minor-micro version to check.
|
65 |
+
:param ignore_requires_python: Whether to ignore the "Requires-Python"
|
66 |
+
value if the given Python version isn't compatible.
|
67 |
+
|
68 |
+
:raises UnsupportedPythonVersion: When the given Python version isn't
|
69 |
+
compatible.
|
70 |
+
"""
|
71 |
+
# This idiosyncratically converts the SpecifierSet to str and let
|
72 |
+
# check_requires_python then parse it again into SpecifierSet. But this
|
73 |
+
# is the legacy resolver so I'm just not going to bother refactoring.
|
74 |
+
try:
|
75 |
+
requires_python = str(dist.requires_python)
|
76 |
+
except FileNotFoundError as e:
|
77 |
+
raise NoneMetadataError(dist, str(e))
|
78 |
+
try:
|
79 |
+
is_compatible = check_requires_python(
|
80 |
+
requires_python,
|
81 |
+
version_info=version_info,
|
82 |
+
)
|
83 |
+
except specifiers.InvalidSpecifier as exc:
|
84 |
+
logger.warning(
|
85 |
+
"Package %r has an invalid Requires-Python: %s", dist.raw_name, exc
|
86 |
+
)
|
87 |
+
return
|
88 |
+
|
89 |
+
if is_compatible:
|
90 |
+
return
|
91 |
+
|
92 |
+
version = ".".join(map(str, version_info))
|
93 |
+
if ignore_requires_python:
|
94 |
+
logger.debug(
|
95 |
+
"Ignoring failed Requires-Python check for package %r: %s not in %r",
|
96 |
+
dist.raw_name,
|
97 |
+
version,
|
98 |
+
requires_python,
|
99 |
+
)
|
100 |
+
return
|
101 |
+
|
102 |
+
raise UnsupportedPythonVersion(
|
103 |
+
"Package {!r} requires a different Python: {} not in {!r}".format(
|
104 |
+
dist.raw_name, version, requires_python
|
105 |
+
)
|
106 |
+
)
|
107 |
+
|
108 |
+
|
109 |
+
class Resolver(BaseResolver):
|
110 |
+
"""Resolves which packages need to be installed/uninstalled to perform \
|
111 |
+
the requested operation without breaking the requirements of any package.
|
112 |
+
"""
|
113 |
+
|
114 |
+
_allowed_strategies = {"eager", "only-if-needed", "to-satisfy-only"}
|
115 |
+
|
116 |
+
def __init__(
|
117 |
+
self,
|
118 |
+
preparer: RequirementPreparer,
|
119 |
+
finder: PackageFinder,
|
120 |
+
wheel_cache: Optional[WheelCache],
|
121 |
+
make_install_req: InstallRequirementProvider,
|
122 |
+
use_user_site: bool,
|
123 |
+
ignore_dependencies: bool,
|
124 |
+
ignore_installed: bool,
|
125 |
+
ignore_requires_python: bool,
|
126 |
+
force_reinstall: bool,
|
127 |
+
upgrade_strategy: str,
|
128 |
+
py_version_info: Optional[Tuple[int, ...]] = None,
|
129 |
+
) -> None:
|
130 |
+
super().__init__()
|
131 |
+
assert upgrade_strategy in self._allowed_strategies
|
132 |
+
|
133 |
+
if py_version_info is None:
|
134 |
+
py_version_info = sys.version_info[:3]
|
135 |
+
else:
|
136 |
+
py_version_info = normalize_version_info(py_version_info)
|
137 |
+
|
138 |
+
self._py_version_info = py_version_info
|
139 |
+
|
140 |
+
self.preparer = preparer
|
141 |
+
self.finder = finder
|
142 |
+
self.wheel_cache = wheel_cache
|
143 |
+
|
144 |
+
self.upgrade_strategy = upgrade_strategy
|
145 |
+
self.force_reinstall = force_reinstall
|
146 |
+
self.ignore_dependencies = ignore_dependencies
|
147 |
+
self.ignore_installed = ignore_installed
|
148 |
+
self.ignore_requires_python = ignore_requires_python
|
149 |
+
self.use_user_site = use_user_site
|
150 |
+
self._make_install_req = make_install_req
|
151 |
+
|
152 |
+
self._discovered_dependencies: DiscoveredDependencies = defaultdict(list)
|
153 |
+
|
154 |
+
def resolve(
|
155 |
+
self, root_reqs: List[InstallRequirement], check_supported_wheels: bool
|
156 |
+
) -> RequirementSet:
|
157 |
+
"""Resolve what operations need to be done
|
158 |
+
|
159 |
+
As a side-effect of this method, the packages (and their dependencies)
|
160 |
+
are downloaded, unpacked and prepared for installation. This
|
161 |
+
preparation is done by ``pip.operations.prepare``.
|
162 |
+
|
163 |
+
Once PyPI has static dependency metadata available, it would be
|
164 |
+
possible to move the preparation to become a step separated from
|
165 |
+
dependency resolution.
|
166 |
+
"""
|
167 |
+
requirement_set = RequirementSet(check_supported_wheels=check_supported_wheels)
|
168 |
+
for req in root_reqs:
|
169 |
+
if req.constraint:
|
170 |
+
check_invalid_constraint_type(req)
|
171 |
+
requirement_set.add_requirement(req)
|
172 |
+
|
173 |
+
# Actually prepare the files, and collect any exceptions. Most hash
|
174 |
+
# exceptions cannot be checked ahead of time, because
|
175 |
+
# _populate_link() needs to be called before we can make decisions
|
176 |
+
# based on link type.
|
177 |
+
discovered_reqs: List[InstallRequirement] = []
|
178 |
+
hash_errors = HashErrors()
|
179 |
+
for req in chain(requirement_set.all_requirements, discovered_reqs):
|
180 |
+
try:
|
181 |
+
discovered_reqs.extend(self._resolve_one(requirement_set, req))
|
182 |
+
except HashError as exc:
|
183 |
+
exc.req = req
|
184 |
+
hash_errors.append(exc)
|
185 |
+
|
186 |
+
if hash_errors:
|
187 |
+
raise hash_errors
|
188 |
+
|
189 |
+
return requirement_set
|
190 |
+
|
191 |
+
def _is_upgrade_allowed(self, req: InstallRequirement) -> bool:
|
192 |
+
if self.upgrade_strategy == "to-satisfy-only":
|
193 |
+
return False
|
194 |
+
elif self.upgrade_strategy == "eager":
|
195 |
+
return True
|
196 |
+
else:
|
197 |
+
assert self.upgrade_strategy == "only-if-needed"
|
198 |
+
return req.user_supplied or req.constraint
|
199 |
+
|
200 |
+
def _set_req_to_reinstall(self, req: InstallRequirement) -> None:
|
201 |
+
"""
|
202 |
+
Set a requirement to be installed.
|
203 |
+
"""
|
204 |
+
# Don't uninstall the conflict if doing a user install and the
|
205 |
+
# conflict is not a user install.
|
206 |
+
if not self.use_user_site or req.satisfied_by.in_usersite:
|
207 |
+
req.should_reinstall = True
|
208 |
+
req.satisfied_by = None
|
209 |
+
|
210 |
+
def _check_skip_installed(
|
211 |
+
self, req_to_install: InstallRequirement
|
212 |
+
) -> Optional[str]:
|
213 |
+
"""Check if req_to_install should be skipped.
|
214 |
+
|
215 |
+
This will check if the req is installed, and whether we should upgrade
|
216 |
+
or reinstall it, taking into account all the relevant user options.
|
217 |
+
|
218 |
+
After calling this req_to_install will only have satisfied_by set to
|
219 |
+
None if the req_to_install is to be upgraded/reinstalled etc. Any
|
220 |
+
other value will be a dist recording the current thing installed that
|
221 |
+
satisfies the requirement.
|
222 |
+
|
223 |
+
Note that for vcs urls and the like we can't assess skipping in this
|
224 |
+
routine - we simply identify that we need to pull the thing down,
|
225 |
+
then later on it is pulled down and introspected to assess upgrade/
|
226 |
+
reinstalls etc.
|
227 |
+
|
228 |
+
:return: A text reason for why it was skipped, or None.
|
229 |
+
"""
|
230 |
+
if self.ignore_installed:
|
231 |
+
return None
|
232 |
+
|
233 |
+
req_to_install.check_if_exists(self.use_user_site)
|
234 |
+
if not req_to_install.satisfied_by:
|
235 |
+
return None
|
236 |
+
|
237 |
+
if self.force_reinstall:
|
238 |
+
self._set_req_to_reinstall(req_to_install)
|
239 |
+
return None
|
240 |
+
|
241 |
+
if not self._is_upgrade_allowed(req_to_install):
|
242 |
+
if self.upgrade_strategy == "only-if-needed":
|
243 |
+
return "already satisfied, skipping upgrade"
|
244 |
+
return "already satisfied"
|
245 |
+
|
246 |
+
# Check for the possibility of an upgrade. For link-based
|
247 |
+
# requirements we have to pull the tree down and inspect to assess
|
248 |
+
# the version #, so it's handled way down.
|
249 |
+
if not req_to_install.link:
|
250 |
+
try:
|
251 |
+
self.finder.find_requirement(req_to_install, upgrade=True)
|
252 |
+
except BestVersionAlreadyInstalled:
|
253 |
+
# Then the best version is installed.
|
254 |
+
return "already up-to-date"
|
255 |
+
except DistributionNotFound:
|
256 |
+
# No distribution found, so we squash the error. It will
|
257 |
+
# be raised later when we re-try later to do the install.
|
258 |
+
# Why don't we just raise here?
|
259 |
+
pass
|
260 |
+
|
261 |
+
self._set_req_to_reinstall(req_to_install)
|
262 |
+
return None
|
263 |
+
|
264 |
+
def _find_requirement_link(self, req: InstallRequirement) -> Optional[Link]:
|
265 |
+
upgrade = self._is_upgrade_allowed(req)
|
266 |
+
best_candidate = self.finder.find_requirement(req, upgrade)
|
267 |
+
if not best_candidate:
|
268 |
+
return None
|
269 |
+
|
270 |
+
# Log a warning per PEP 592 if necessary before returning.
|
271 |
+
link = best_candidate.link
|
272 |
+
if link.is_yanked:
|
273 |
+
reason = link.yanked_reason or "<none given>"
|
274 |
+
msg = (
|
275 |
+
# Mark this as a unicode string to prevent
|
276 |
+
# "UnicodeEncodeError: 'ascii' codec can't encode character"
|
277 |
+
# in Python 2 when the reason contains non-ascii characters.
|
278 |
+
"The candidate selected for download or install is a "
|
279 |
+
"yanked version: {candidate}\n"
|
280 |
+
"Reason for being yanked: {reason}"
|
281 |
+
).format(candidate=best_candidate, reason=reason)
|
282 |
+
logger.warning(msg)
|
283 |
+
|
284 |
+
return link
|
285 |
+
|
286 |
+
def _populate_link(self, req: InstallRequirement) -> None:
|
287 |
+
"""Ensure that if a link can be found for this, that it is found.
|
288 |
+
|
289 |
+
Note that req.link may still be None - if the requirement is already
|
290 |
+
installed and not needed to be upgraded based on the return value of
|
291 |
+
_is_upgrade_allowed().
|
292 |
+
|
293 |
+
If preparer.require_hashes is True, don't use the wheel cache, because
|
294 |
+
cached wheels, always built locally, have different hashes than the
|
295 |
+
files downloaded from the index server and thus throw false hash
|
296 |
+
mismatches. Furthermore, cached wheels at present have undeterministic
|
297 |
+
contents due to file modification times.
|
298 |
+
"""
|
299 |
+
if req.link is None:
|
300 |
+
req.link = self._find_requirement_link(req)
|
301 |
+
|
302 |
+
if self.wheel_cache is None or self.preparer.require_hashes:
|
303 |
+
return
|
304 |
+
cache_entry = self.wheel_cache.get_cache_entry(
|
305 |
+
link=req.link,
|
306 |
+
package_name=req.name,
|
307 |
+
supported_tags=get_supported(),
|
308 |
+
)
|
309 |
+
if cache_entry is not None:
|
310 |
+
logger.debug("Using cached wheel link: %s", cache_entry.link)
|
311 |
+
if req.link is req.original_link and cache_entry.persistent:
|
312 |
+
req.original_link_is_in_wheel_cache = True
|
313 |
+
req.link = cache_entry.link
|
314 |
+
|
315 |
+
def _get_dist_for(self, req: InstallRequirement) -> BaseDistribution:
|
316 |
+
"""Takes a InstallRequirement and returns a single AbstractDist \
|
317 |
+
representing a prepared variant of the same.
|
318 |
+
"""
|
319 |
+
if req.editable:
|
320 |
+
return self.preparer.prepare_editable_requirement(req)
|
321 |
+
|
322 |
+
# satisfied_by is only evaluated by calling _check_skip_installed,
|
323 |
+
# so it must be None here.
|
324 |
+
assert req.satisfied_by is None
|
325 |
+
skip_reason = self._check_skip_installed(req)
|
326 |
+
|
327 |
+
if req.satisfied_by:
|
328 |
+
return self.preparer.prepare_installed_requirement(req, skip_reason)
|
329 |
+
|
330 |
+
# We eagerly populate the link, since that's our "legacy" behavior.
|
331 |
+
self._populate_link(req)
|
332 |
+
dist = self.preparer.prepare_linked_requirement(req)
|
333 |
+
|
334 |
+
# NOTE
|
335 |
+
# The following portion is for determining if a certain package is
|
336 |
+
# going to be re-installed/upgraded or not and reporting to the user.
|
337 |
+
# This should probably get cleaned up in a future refactor.
|
338 |
+
|
339 |
+
# req.req is only avail after unpack for URL
|
340 |
+
# pkgs repeat check_if_exists to uninstall-on-upgrade
|
341 |
+
# (#14)
|
342 |
+
if not self.ignore_installed:
|
343 |
+
req.check_if_exists(self.use_user_site)
|
344 |
+
|
345 |
+
if req.satisfied_by:
|
346 |
+
should_modify = (
|
347 |
+
self.upgrade_strategy != "to-satisfy-only"
|
348 |
+
or self.force_reinstall
|
349 |
+
or self.ignore_installed
|
350 |
+
or req.link.scheme == "file"
|
351 |
+
)
|
352 |
+
if should_modify:
|
353 |
+
self._set_req_to_reinstall(req)
|
354 |
+
else:
|
355 |
+
logger.info(
|
356 |
+
"Requirement already satisfied (use --upgrade to upgrade): %s",
|
357 |
+
req,
|
358 |
+
)
|
359 |
+
return dist
|
360 |
+
|
361 |
+
def _resolve_one(
|
362 |
+
self,
|
363 |
+
requirement_set: RequirementSet,
|
364 |
+
req_to_install: InstallRequirement,
|
365 |
+
) -> List[InstallRequirement]:
|
366 |
+
"""Prepare a single requirements file.
|
367 |
+
|
368 |
+
:return: A list of additional InstallRequirements to also install.
|
369 |
+
"""
|
370 |
+
# Tell user what we are doing for this requirement:
|
371 |
+
# obtain (editable), skipping, processing (local url), collecting
|
372 |
+
# (remote url or package name)
|
373 |
+
if req_to_install.constraint or req_to_install.prepared:
|
374 |
+
return []
|
375 |
+
|
376 |
+
req_to_install.prepared = True
|
377 |
+
|
378 |
+
# Parse and return dependencies
|
379 |
+
dist = self._get_dist_for(req_to_install)
|
380 |
+
# This will raise UnsupportedPythonVersion if the given Python
|
381 |
+
# version isn't compatible with the distribution's Requires-Python.
|
382 |
+
_check_dist_requires_python(
|
383 |
+
dist,
|
384 |
+
version_info=self._py_version_info,
|
385 |
+
ignore_requires_python=self.ignore_requires_python,
|
386 |
+
)
|
387 |
+
|
388 |
+
more_reqs: List[InstallRequirement] = []
|
389 |
+
|
390 |
+
def add_req(subreq: Requirement, extras_requested: Iterable[str]) -> None:
|
391 |
+
# This idiosyncratically converts the Requirement to str and let
|
392 |
+
# make_install_req then parse it again into Requirement. But this is
|
393 |
+
# the legacy resolver so I'm just not going to bother refactoring.
|
394 |
+
sub_install_req = self._make_install_req(str(subreq), req_to_install)
|
395 |
+
parent_req_name = req_to_install.name
|
396 |
+
to_scan_again, add_to_parent = requirement_set.add_requirement(
|
397 |
+
sub_install_req,
|
398 |
+
parent_req_name=parent_req_name,
|
399 |
+
extras_requested=extras_requested,
|
400 |
+
)
|
401 |
+
if parent_req_name and add_to_parent:
|
402 |
+
self._discovered_dependencies[parent_req_name].append(add_to_parent)
|
403 |
+
more_reqs.extend(to_scan_again)
|
404 |
+
|
405 |
+
with indent_log():
|
406 |
+
# We add req_to_install before its dependencies, so that we
|
407 |
+
# can refer to it when adding dependencies.
|
408 |
+
if not requirement_set.has_requirement(req_to_install.name):
|
409 |
+
# 'unnamed' requirements will get added here
|
410 |
+
# 'unnamed' requirements can only come from being directly
|
411 |
+
# provided by the user.
|
412 |
+
assert req_to_install.user_supplied
|
413 |
+
requirement_set.add_requirement(req_to_install, parent_req_name=None)
|
414 |
+
|
415 |
+
if not self.ignore_dependencies:
|
416 |
+
if req_to_install.extras:
|
417 |
+
logger.debug(
|
418 |
+
"Installing extra requirements: %r",
|
419 |
+
",".join(req_to_install.extras),
|
420 |
+
)
|
421 |
+
missing_requested = sorted(
|
422 |
+
set(req_to_install.extras) - set(dist.iter_provided_extras())
|
423 |
+
)
|
424 |
+
for missing in missing_requested:
|
425 |
+
logger.warning(
|
426 |
+
"%s %s does not provide the extra '%s'",
|
427 |
+
dist.raw_name,
|
428 |
+
dist.version,
|
429 |
+
missing,
|
430 |
+
)
|
431 |
+
|
432 |
+
available_requested = sorted(
|
433 |
+
set(dist.iter_provided_extras()) & set(req_to_install.extras)
|
434 |
+
)
|
435 |
+
for subreq in dist.iter_dependencies(available_requested):
|
436 |
+
add_req(subreq, extras_requested=available_requested)
|
437 |
+
|
438 |
+
return more_reqs
|
439 |
+
|
440 |
+
def get_installation_order(
|
441 |
+
self, req_set: RequirementSet
|
442 |
+
) -> List[InstallRequirement]:
|
443 |
+
"""Create the installation order.
|
444 |
+
|
445 |
+
The installation order is topological - requirements are installed
|
446 |
+
before the requiring thing. We break cycles at an arbitrary point,
|
447 |
+
and make no other guarantees.
|
448 |
+
"""
|
449 |
+
# The current implementation, which we may change at any point
|
450 |
+
# installs the user specified things in the order given, except when
|
451 |
+
# dependencies must come earlier to achieve topological order.
|
452 |
+
order = []
|
453 |
+
ordered_reqs: Set[InstallRequirement] = set()
|
454 |
+
|
455 |
+
def schedule(req: InstallRequirement) -> None:
|
456 |
+
if req.satisfied_by or req in ordered_reqs:
|
457 |
+
return
|
458 |
+
if req.constraint:
|
459 |
+
return
|
460 |
+
ordered_reqs.add(req)
|
461 |
+
for dep in self._discovered_dependencies[req.name]:
|
462 |
+
schedule(dep)
|
463 |
+
order.append(req)
|
464 |
+
|
465 |
+
for install_req in req_set.requirements.values():
|
466 |
+
schedule(install_req)
|
467 |
+
return order
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__init__.py
ADDED
File without changes
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (210 Bytes). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/base.cpython-310.pyc
ADDED
Binary file (6.45 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/candidates.cpython-310.pyc
ADDED
Binary file (18.4 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/found_candidates.cpython-310.pyc
ADDED
Binary file (4.87 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/provider.cpython-310.pyc
ADDED
Binary file (7.71 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/reporter.cpython-310.pyc
ADDED
Binary file (3.18 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/__pycache__/requirements.cpython-310.pyc
ADDED
Binary file (7.47 kB). View file
|
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/reporter.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from collections import defaultdict
|
2 |
+
from logging import getLogger
|
3 |
+
from typing import Any, DefaultDict
|
4 |
+
|
5 |
+
from pip._vendor.resolvelib.reporters import BaseReporter
|
6 |
+
|
7 |
+
from .base import Candidate, Requirement
|
8 |
+
|
9 |
+
logger = getLogger(__name__)
|
10 |
+
|
11 |
+
|
12 |
+
class PipReporter(BaseReporter):
|
13 |
+
def __init__(self) -> None:
|
14 |
+
self.backtracks_by_package: DefaultDict[str, int] = defaultdict(int)
|
15 |
+
|
16 |
+
self._messages_at_backtrack = {
|
17 |
+
1: (
|
18 |
+
"pip is looking at multiple versions of {package_name} to "
|
19 |
+
"determine which version is compatible with other "
|
20 |
+
"requirements. This could take a while."
|
21 |
+
),
|
22 |
+
8: (
|
23 |
+
"pip is looking at multiple versions of {package_name} to "
|
24 |
+
"determine which version is compatible with other "
|
25 |
+
"requirements. This could take a while."
|
26 |
+
),
|
27 |
+
13: (
|
28 |
+
"This is taking longer than usual. You might need to provide "
|
29 |
+
"the dependency resolver with stricter constraints to reduce "
|
30 |
+
"runtime. See https://pip.pypa.io/warnings/backtracking for "
|
31 |
+
"guidance. If you want to abort this run, press Ctrl + C."
|
32 |
+
),
|
33 |
+
}
|
34 |
+
|
35 |
+
def backtracking(self, candidate: Candidate) -> None:
|
36 |
+
self.backtracks_by_package[candidate.name] += 1
|
37 |
+
|
38 |
+
count = self.backtracks_by_package[candidate.name]
|
39 |
+
if count not in self._messages_at_backtrack:
|
40 |
+
return
|
41 |
+
|
42 |
+
message = self._messages_at_backtrack[count]
|
43 |
+
logger.info("INFO: %s", message.format(package_name=candidate.name))
|
44 |
+
|
45 |
+
|
46 |
+
class PipDebuggingReporter(BaseReporter):
|
47 |
+
"""A reporter that does an info log for every event it sees."""
|
48 |
+
|
49 |
+
def starting(self) -> None:
|
50 |
+
logger.info("Reporter.starting()")
|
51 |
+
|
52 |
+
def starting_round(self, index: int) -> None:
|
53 |
+
logger.info("Reporter.starting_round(%r)", index)
|
54 |
+
|
55 |
+
def ending_round(self, index: int, state: Any) -> None:
|
56 |
+
logger.info("Reporter.ending_round(%r, state)", index)
|
57 |
+
|
58 |
+
def ending(self, state: Any) -> None:
|
59 |
+
logger.info("Reporter.ending(%r)", state)
|
60 |
+
|
61 |
+
def adding_requirement(self, requirement: Requirement, parent: Candidate) -> None:
|
62 |
+
logger.info("Reporter.adding_requirement(%r, %r)", requirement, parent)
|
63 |
+
|
64 |
+
def backtracking(self, candidate: Candidate) -> None:
|
65 |
+
logger.info("Reporter.backtracking(%r)", candidate)
|
66 |
+
|
67 |
+
def pinning(self, candidate: Candidate) -> None:
|
68 |
+
logger.info("Reporter.pinning(%r)", candidate)
|
scripts/myenv/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/requirements.py
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pip._vendor.packaging.specifiers import SpecifierSet
|
2 |
+
from pip._vendor.packaging.utils import NormalizedName, canonicalize_name
|
3 |
+
|
4 |
+
from pip._internal.req.req_install import InstallRequirement
|
5 |
+
|
6 |
+
from .base import Candidate, CandidateLookup, Requirement, format_name
|
7 |
+
|
8 |
+
|
9 |
+
class ExplicitRequirement(Requirement):
|
10 |
+
def __init__(self, candidate: Candidate) -> None:
|
11 |
+
self.candidate = candidate
|
12 |
+
|
13 |
+
def __str__(self) -> str:
|
14 |
+
return str(self.candidate)
|
15 |
+
|
16 |
+
def __repr__(self) -> str:
|
17 |
+
return "{class_name}({candidate!r})".format(
|
18 |
+
class_name=self.__class__.__name__,
|
19 |
+
candidate=self.candidate,
|
20 |
+
)
|
21 |
+
|
22 |
+
@property
|
23 |
+
def project_name(self) -> NormalizedName:
|
24 |
+
# No need to canonicalize - the candidate did this
|
25 |
+
return self.candidate.project_name
|
26 |
+
|
27 |
+
@property
|
28 |
+
def name(self) -> str:
|
29 |
+
# No need to canonicalize - the candidate did this
|
30 |
+
return self.candidate.name
|
31 |
+
|
32 |
+
def format_for_error(self) -> str:
|
33 |
+
return self.candidate.format_for_error()
|
34 |
+
|
35 |
+
def get_candidate_lookup(self) -> CandidateLookup:
|
36 |
+
return self.candidate, None
|
37 |
+
|
38 |
+
def is_satisfied_by(self, candidate: Candidate) -> bool:
|
39 |
+
return candidate == self.candidate
|
40 |
+
|
41 |
+
|
42 |
+
class SpecifierRequirement(Requirement):
|
43 |
+
def __init__(self, ireq: InstallRequirement) -> None:
|
44 |
+
assert ireq.link is None, "This is a link, not a specifier"
|
45 |
+
self._ireq = ireq
|
46 |
+
self._extras = frozenset(ireq.extras)
|
47 |
+
|
48 |
+
def __str__(self) -> str:
|
49 |
+
return str(self._ireq.req)
|
50 |
+
|
51 |
+
def __repr__(self) -> str:
|
52 |
+
return "{class_name}({requirement!r})".format(
|
53 |
+
class_name=self.__class__.__name__,
|
54 |
+
requirement=str(self._ireq.req),
|
55 |
+
)
|
56 |
+
|
57 |
+
@property
|
58 |
+
def project_name(self) -> NormalizedName:
|
59 |
+
assert self._ireq.req, "Specifier-backed ireq is always PEP 508"
|
60 |
+
return canonicalize_name(self._ireq.req.name)
|
61 |
+
|
62 |
+
@property
|
63 |
+
def name(self) -> str:
|
64 |
+
return format_name(self.project_name, self._extras)
|
65 |
+
|
66 |
+
def format_for_error(self) -> str:
|
67 |
+
|
68 |
+
# Convert comma-separated specifiers into "A, B, ..., F and G"
|
69 |
+
# This makes the specifier a bit more "human readable", without
|
70 |
+
# risking a change in meaning. (Hopefully! Not all edge cases have
|
71 |
+
# been checked)
|
72 |
+
parts = [s.strip() for s in str(self).split(",")]
|
73 |
+
if len(parts) == 0:
|
74 |
+
return ""
|
75 |
+
elif len(parts) == 1:
|
76 |
+
return parts[0]
|
77 |
+
|
78 |
+
return ", ".join(parts[:-1]) + " and " + parts[-1]
|
79 |
+
|
80 |
+
def get_candidate_lookup(self) -> CandidateLookup:
|
81 |
+
return None, self._ireq
|
82 |
+
|
83 |
+
def is_satisfied_by(self, candidate: Candidate) -> bool:
|
84 |
+
assert candidate.name == self.name, (
|
85 |
+
f"Internal issue: Candidate is not for this requirement "
|
86 |
+
f"{candidate.name} vs {self.name}"
|
87 |
+
)
|
88 |
+
# We can safely always allow prereleases here since PackageFinder
|
89 |
+
# already implements the prerelease logic, and would have filtered out
|
90 |
+
# prerelease candidates if the user does not expect them.
|
91 |
+
assert self._ireq.req, "Specifier-backed ireq is always PEP 508"
|
92 |
+
spec = self._ireq.req.specifier
|
93 |
+
return spec.contains(candidate.version, prereleases=True)
|
94 |
+
|
95 |
+
|
96 |
+
class RequiresPythonRequirement(Requirement):
|
97 |
+
"""A requirement representing Requires-Python metadata."""
|
98 |
+
|
99 |
+
def __init__(self, specifier: SpecifierSet, match: Candidate) -> None:
|
100 |
+
self.specifier = specifier
|
101 |
+
self._candidate = match
|
102 |
+
|
103 |
+
def __str__(self) -> str:
|
104 |
+
return f"Python {self.specifier}"
|
105 |
+
|
106 |
+
def __repr__(self) -> str:
|
107 |
+
return "{class_name}({specifier!r})".format(
|
108 |
+
class_name=self.__class__.__name__,
|
109 |
+
specifier=str(self.specifier),
|
110 |
+
)
|
111 |
+
|
112 |
+
@property
|
113 |
+
def project_name(self) -> NormalizedName:
|
114 |
+
return self._candidate.project_name
|
115 |
+
|
116 |
+
@property
|
117 |
+
def name(self) -> str:
|
118 |
+
return self._candidate.name
|
119 |
+
|
120 |
+
def format_for_error(self) -> str:
|
121 |
+
return str(self)
|
122 |
+
|
123 |
+
def get_candidate_lookup(self) -> CandidateLookup:
|
124 |
+
if self.specifier.contains(self._candidate.version, prereleases=True):
|
125 |
+
return self._candidate, None
|
126 |
+
return None, None
|
127 |
+
|
128 |
+
def is_satisfied_by(self, candidate: Candidate) -> bool:
|
129 |
+
assert candidate.name == self._candidate.name, "Not Python candidate"
|
130 |
+
# We can safely always allow prereleases here since PackageFinder
|
131 |
+
# already implements the prerelease logic, and would have filtered out
|
132 |
+
# prerelease candidates if the user does not expect them.
|
133 |
+
return self.specifier.contains(candidate.version, prereleases=True)
|
134 |
+
|
135 |
+
|
136 |
+
class UnsatisfiableRequirement(Requirement):
|
137 |
+
"""A requirement that cannot be satisfied."""
|
138 |
+
|
139 |
+
def __init__(self, name: NormalizedName) -> None:
|
140 |
+
self._name = name
|
141 |
+
|
142 |
+
def __str__(self) -> str:
|
143 |
+
return f"{self._name} (unavailable)"
|
144 |
+
|
145 |
+
def __repr__(self) -> str:
|
146 |
+
return "{class_name}({name!r})".format(
|
147 |
+
class_name=self.__class__.__name__,
|
148 |
+
name=str(self._name),
|
149 |
+
)
|
150 |
+
|
151 |
+
@property
|
152 |
+
def project_name(self) -> NormalizedName:
|
153 |
+
return self._name
|
154 |
+
|
155 |
+
@property
|
156 |
+
def name(self) -> str:
|
157 |
+
return self._name
|
158 |
+
|
159 |
+
def format_for_error(self) -> str:
|
160 |
+
return str(self)
|
161 |
+
|
162 |
+
def get_candidate_lookup(self) -> CandidateLookup:
|
163 |
+
return None, None
|
164 |
+
|
165 |
+
def is_satisfied_by(self, candidate: Candidate) -> bool:
|
166 |
+
return False
|