Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- ckpts/universal/global_step80/zero/10.attention.dense.weight/exp_avg_sq.pt +3 -0
- ckpts/universal/global_step80/zero/13.input_layernorm.weight/exp_avg.pt +3 -0
- ckpts/universal/global_step80/zero/13.input_layernorm.weight/fp32.pt +3 -0
- ckpts/universal/global_step80/zero/24.attention.dense.weight/exp_avg.pt +3 -0
- ckpts/universal/global_step80/zero/24.post_attention_layernorm.weight/exp_avg.pt +3 -0
- ckpts/universal/global_step80/zero/24.post_attention_layernorm.weight/fp32.pt +3 -0
- ckpts/universal/global_step80/zero/7.attention.dense.weight/exp_avg.pt +3 -0
- ckpts/universal/global_step80/zero/7.post_attention_layernorm.weight/exp_avg_sq.pt +3 -0
- ckpts/universal/global_step80/zero/7.post_attention_layernorm.weight/fp32.pt +3 -0
- venv/lib/python3.10/site-packages/pip/__init__.py +13 -0
- venv/lib/python3.10/site-packages/pip/__main__.py +31 -0
- venv/lib/python3.10/site-packages/pip/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/__pycache__/__main__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__init__.py +19 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/build_env.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/cache.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/configuration.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/exceptions.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/main.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/pyproject.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/self_outdated_check.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/__pycache__/wheel_builder.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/build_env.py +296 -0
- venv/lib/python3.10/site-packages/pip/_internal/cache.py +264 -0
- venv/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/wheel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/configuration.py +366 -0
- venv/lib/python3.10/site-packages/pip/_internal/exceptions.py +658 -0
- venv/lib/python3.10/site-packages/pip/_internal/locations/__init__.py +520 -0
- venv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_distutils.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/base.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/locations/_distutils.py +169 -0
- venv/lib/python3.10/site-packages/pip/_internal/locations/_sysconfig.py +219 -0
- venv/lib/python3.10/site-packages/pip/_internal/locations/base.py +52 -0
- venv/lib/python3.10/site-packages/pip/_internal/main.py +12 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__init__.py +2 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/__init__.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/candidate.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/direct_url.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/format_control.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/index.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/link.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/scheme.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/search_scope.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/selection_prefs.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/target_python.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/wheel.cpython-310.pyc +0 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/candidate.py +34 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/direct_url.py +220 -0
- venv/lib/python3.10/site-packages/pip/_internal/models/format_control.py +80 -0
ckpts/universal/global_step80/zero/10.attention.dense.weight/exp_avg_sq.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b6b11fd443f43daad55a3d6250cda1eef79d0c648c1f389693015e6ff37aee64
|
3 |
+
size 16778411
|
ckpts/universal/global_step80/zero/13.input_layernorm.weight/exp_avg.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f6a2eb91e2c5178a0cc5f5d27fb6f8e69b7bcd615e029e03a99170857a4515eb
|
3 |
+
size 9372
|
ckpts/universal/global_step80/zero/13.input_layernorm.weight/fp32.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1f09c5745caee0844ac91d954157aebf441c113cfcd0928a2120dacb0a3b6334
|
3 |
+
size 9293
|
ckpts/universal/global_step80/zero/24.attention.dense.weight/exp_avg.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a1e830331b81cf52e0f24c12bc0b79ee9a13c3f249faa23cd4d71c25d074cbe4
|
3 |
+
size 16778396
|
ckpts/universal/global_step80/zero/24.post_attention_layernorm.weight/exp_avg.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:db2618faec1f00350f27c33ecc1651f85afa90a892ca0df3c4ccf9f04533fc52
|
3 |
+
size 9372
|
ckpts/universal/global_step80/zero/24.post_attention_layernorm.weight/fp32.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:96d7ac8f07154e64bf3abfa22be028b27eb2b91da9f622e3b5d2b8b6d5faca27
|
3 |
+
size 9293
|
ckpts/universal/global_step80/zero/7.attention.dense.weight/exp_avg.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8404e5d60df37351b714f5c8736f0af6f541af74603fe286fc77922dc8f71b73
|
3 |
+
size 16778396
|
ckpts/universal/global_step80/zero/7.post_attention_layernorm.weight/exp_avg_sq.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e60584f58e3eb74770f16c85e1f6896802907b5414cfffa4dac54c2c9d024bd6
|
3 |
+
size 9387
|
ckpts/universal/global_step80/zero/7.post_attention_layernorm.weight/fp32.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f182428d014f1e29382645b615f18170b19ea36ff8351fc52bb92fb8b10015d4
|
3 |
+
size 9293
|
venv/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)
|
venv/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())
|
venv/lib/python3.10/site-packages/pip/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (627 Bytes). View file
|
|
venv/lib/python3.10/site-packages/pip/__pycache__/__main__.cpython-310.pyc
ADDED
Binary file (589 Bytes). View file
|
|
venv/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)
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (748 Bytes). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/build_env.cpython-310.pyc
ADDED
Binary file (9.59 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/cache.cpython-310.pyc
ADDED
Binary file (8.38 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/configuration.cpython-310.pyc
ADDED
Binary file (11.1 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/exceptions.cpython-310.pyc
ADDED
Binary file (23.1 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/main.cpython-310.pyc
ADDED
Binary file (613 Bytes). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/pyproject.cpython-310.pyc
ADDED
Binary file (3.53 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/self_outdated_check.cpython-310.pyc
ADDED
Binary file (4.57 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/__pycache__/wheel_builder.cpython-310.pyc
ADDED
Binary file (9.13 kB). View file
|
|
venv/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()
|
venv/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
|
venv/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/wheel.cpython-310.pyc
ADDED
Binary file (4.83 kB). View file
|
|
venv/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})"
|
venv/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}"
|
venv/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
|
venv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_distutils.cpython-310.pyc
ADDED
Binary file (4.65 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/base.cpython-310.pyc
ADDED
Binary file (1.53 kB). View file
|
|
venv/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 |
+
)
|
venv/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"])
|
venv/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"))
|
venv/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)
|
venv/lib/python3.10/site-packages/pip/_internal/models/__init__.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
"""A package that contains models that represent entities.
|
2 |
+
"""
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (256 Bytes). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/candidate.cpython-310.pyc
ADDED
Binary file (1.41 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/direct_url.cpython-310.pyc
ADDED
Binary file (7.28 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/format_control.cpython-310.pyc
ADDED
Binary file (2.73 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/index.cpython-310.pyc
ADDED
Binary file (1.23 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/link.cpython-310.pyc
ADDED
Binary file (10.2 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/scheme.cpython-310.pyc
ADDED
Binary file (1.02 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/search_scope.cpython-310.pyc
ADDED
Binary file (3.48 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/selection_prefs.cpython-310.pyc
ADDED
Binary file (1.69 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/target_python.cpython-310.pyc
ADDED
Binary file (3.44 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/__pycache__/wheel.cpython-310.pyc
ADDED
Binary file (4.35 kB). View file
|
|
venv/lib/python3.10/site-packages/pip/_internal/models/candidate.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pip._vendor.packaging.version import parse as parse_version
|
2 |
+
|
3 |
+
from pip._internal.models.link import Link
|
4 |
+
from pip._internal.utils.models import KeyBasedCompareMixin
|
5 |
+
|
6 |
+
|
7 |
+
class InstallationCandidate(KeyBasedCompareMixin):
|
8 |
+
"""Represents a potential "candidate" for installation."""
|
9 |
+
|
10 |
+
__slots__ = ["name", "version", "link"]
|
11 |
+
|
12 |
+
def __init__(self, name: str, version: str, link: Link) -> None:
|
13 |
+
self.name = name
|
14 |
+
self.version = parse_version(version)
|
15 |
+
self.link = link
|
16 |
+
|
17 |
+
super().__init__(
|
18 |
+
key=(self.name, self.version, self.link),
|
19 |
+
defining_class=InstallationCandidate,
|
20 |
+
)
|
21 |
+
|
22 |
+
def __repr__(self) -> str:
|
23 |
+
return "<InstallationCandidate({!r}, {!r}, {!r})>".format(
|
24 |
+
self.name,
|
25 |
+
self.version,
|
26 |
+
self.link,
|
27 |
+
)
|
28 |
+
|
29 |
+
def __str__(self) -> str:
|
30 |
+
return "{!r} candidate (version {} at {})".format(
|
31 |
+
self.name,
|
32 |
+
self.version,
|
33 |
+
self.link,
|
34 |
+
)
|
venv/lib/python3.10/site-packages/pip/_internal/models/direct_url.py
ADDED
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
""" PEP 610 """
|
2 |
+
import json
|
3 |
+
import re
|
4 |
+
import urllib.parse
|
5 |
+
from typing import Any, Dict, Iterable, Optional, Type, TypeVar, Union
|
6 |
+
|
7 |
+
__all__ = [
|
8 |
+
"DirectUrl",
|
9 |
+
"DirectUrlValidationError",
|
10 |
+
"DirInfo",
|
11 |
+
"ArchiveInfo",
|
12 |
+
"VcsInfo",
|
13 |
+
]
|
14 |
+
|
15 |
+
T = TypeVar("T")
|
16 |
+
|
17 |
+
DIRECT_URL_METADATA_NAME = "direct_url.json"
|
18 |
+
ENV_VAR_RE = re.compile(r"^\$\{[A-Za-z0-9-_]+\}(:\$\{[A-Za-z0-9-_]+\})?$")
|
19 |
+
|
20 |
+
|
21 |
+
class DirectUrlValidationError(Exception):
|
22 |
+
pass
|
23 |
+
|
24 |
+
|
25 |
+
def _get(
|
26 |
+
d: Dict[str, Any], expected_type: Type[T], key: str, default: Optional[T] = None
|
27 |
+
) -> Optional[T]:
|
28 |
+
"""Get value from dictionary and verify expected type."""
|
29 |
+
if key not in d:
|
30 |
+
return default
|
31 |
+
value = d[key]
|
32 |
+
if not isinstance(value, expected_type):
|
33 |
+
raise DirectUrlValidationError(
|
34 |
+
"{!r} has unexpected type for {} (expected {})".format(
|
35 |
+
value, key, expected_type
|
36 |
+
)
|
37 |
+
)
|
38 |
+
return value
|
39 |
+
|
40 |
+
|
41 |
+
def _get_required(
|
42 |
+
d: Dict[str, Any], expected_type: Type[T], key: str, default: Optional[T] = None
|
43 |
+
) -> T:
|
44 |
+
value = _get(d, expected_type, key, default)
|
45 |
+
if value is None:
|
46 |
+
raise DirectUrlValidationError(f"{key} must have a value")
|
47 |
+
return value
|
48 |
+
|
49 |
+
|
50 |
+
def _exactly_one_of(infos: Iterable[Optional["InfoType"]]) -> "InfoType":
|
51 |
+
infos = [info for info in infos if info is not None]
|
52 |
+
if not infos:
|
53 |
+
raise DirectUrlValidationError(
|
54 |
+
"missing one of archive_info, dir_info, vcs_info"
|
55 |
+
)
|
56 |
+
if len(infos) > 1:
|
57 |
+
raise DirectUrlValidationError(
|
58 |
+
"more than one of archive_info, dir_info, vcs_info"
|
59 |
+
)
|
60 |
+
assert infos[0] is not None
|
61 |
+
return infos[0]
|
62 |
+
|
63 |
+
|
64 |
+
def _filter_none(**kwargs: Any) -> Dict[str, Any]:
|
65 |
+
"""Make dict excluding None values."""
|
66 |
+
return {k: v for k, v in kwargs.items() if v is not None}
|
67 |
+
|
68 |
+
|
69 |
+
class VcsInfo:
|
70 |
+
name = "vcs_info"
|
71 |
+
|
72 |
+
def __init__(
|
73 |
+
self,
|
74 |
+
vcs: str,
|
75 |
+
commit_id: str,
|
76 |
+
requested_revision: Optional[str] = None,
|
77 |
+
resolved_revision: Optional[str] = None,
|
78 |
+
resolved_revision_type: Optional[str] = None,
|
79 |
+
) -> None:
|
80 |
+
self.vcs = vcs
|
81 |
+
self.requested_revision = requested_revision
|
82 |
+
self.commit_id = commit_id
|
83 |
+
self.resolved_revision = resolved_revision
|
84 |
+
self.resolved_revision_type = resolved_revision_type
|
85 |
+
|
86 |
+
@classmethod
|
87 |
+
def _from_dict(cls, d: Optional[Dict[str, Any]]) -> Optional["VcsInfo"]:
|
88 |
+
if d is None:
|
89 |
+
return None
|
90 |
+
return cls(
|
91 |
+
vcs=_get_required(d, str, "vcs"),
|
92 |
+
commit_id=_get_required(d, str, "commit_id"),
|
93 |
+
requested_revision=_get(d, str, "requested_revision"),
|
94 |
+
resolved_revision=_get(d, str, "resolved_revision"),
|
95 |
+
resolved_revision_type=_get(d, str, "resolved_revision_type"),
|
96 |
+
)
|
97 |
+
|
98 |
+
def _to_dict(self) -> Dict[str, Any]:
|
99 |
+
return _filter_none(
|
100 |
+
vcs=self.vcs,
|
101 |
+
requested_revision=self.requested_revision,
|
102 |
+
commit_id=self.commit_id,
|
103 |
+
resolved_revision=self.resolved_revision,
|
104 |
+
resolved_revision_type=self.resolved_revision_type,
|
105 |
+
)
|
106 |
+
|
107 |
+
|
108 |
+
class ArchiveInfo:
|
109 |
+
name = "archive_info"
|
110 |
+
|
111 |
+
def __init__(
|
112 |
+
self,
|
113 |
+
hash: Optional[str] = None,
|
114 |
+
) -> None:
|
115 |
+
self.hash = hash
|
116 |
+
|
117 |
+
@classmethod
|
118 |
+
def _from_dict(cls, d: Optional[Dict[str, Any]]) -> Optional["ArchiveInfo"]:
|
119 |
+
if d is None:
|
120 |
+
return None
|
121 |
+
return cls(hash=_get(d, str, "hash"))
|
122 |
+
|
123 |
+
def _to_dict(self) -> Dict[str, Any]:
|
124 |
+
return _filter_none(hash=self.hash)
|
125 |
+
|
126 |
+
|
127 |
+
class DirInfo:
|
128 |
+
name = "dir_info"
|
129 |
+
|
130 |
+
def __init__(
|
131 |
+
self,
|
132 |
+
editable: bool = False,
|
133 |
+
) -> None:
|
134 |
+
self.editable = editable
|
135 |
+
|
136 |
+
@classmethod
|
137 |
+
def _from_dict(cls, d: Optional[Dict[str, Any]]) -> Optional["DirInfo"]:
|
138 |
+
if d is None:
|
139 |
+
return None
|
140 |
+
return cls(editable=_get_required(d, bool, "editable", default=False))
|
141 |
+
|
142 |
+
def _to_dict(self) -> Dict[str, Any]:
|
143 |
+
return _filter_none(editable=self.editable or None)
|
144 |
+
|
145 |
+
|
146 |
+
InfoType = Union[ArchiveInfo, DirInfo, VcsInfo]
|
147 |
+
|
148 |
+
|
149 |
+
class DirectUrl:
|
150 |
+
def __init__(
|
151 |
+
self,
|
152 |
+
url: str,
|
153 |
+
info: InfoType,
|
154 |
+
subdirectory: Optional[str] = None,
|
155 |
+
) -> None:
|
156 |
+
self.url = url
|
157 |
+
self.info = info
|
158 |
+
self.subdirectory = subdirectory
|
159 |
+
|
160 |
+
def _remove_auth_from_netloc(self, netloc: str) -> str:
|
161 |
+
if "@" not in netloc:
|
162 |
+
return netloc
|
163 |
+
user_pass, netloc_no_user_pass = netloc.split("@", 1)
|
164 |
+
if (
|
165 |
+
isinstance(self.info, VcsInfo)
|
166 |
+
and self.info.vcs == "git"
|
167 |
+
and user_pass == "git"
|
168 |
+
):
|
169 |
+
return netloc
|
170 |
+
if ENV_VAR_RE.match(user_pass):
|
171 |
+
return netloc
|
172 |
+
return netloc_no_user_pass
|
173 |
+
|
174 |
+
@property
|
175 |
+
def redacted_url(self) -> str:
|
176 |
+
"""url with user:password part removed unless it is formed with
|
177 |
+
environment variables as specified in PEP 610, or it is ``git``
|
178 |
+
in the case of a git URL.
|
179 |
+
"""
|
180 |
+
purl = urllib.parse.urlsplit(self.url)
|
181 |
+
netloc = self._remove_auth_from_netloc(purl.netloc)
|
182 |
+
surl = urllib.parse.urlunsplit(
|
183 |
+
(purl.scheme, netloc, purl.path, purl.query, purl.fragment)
|
184 |
+
)
|
185 |
+
return surl
|
186 |
+
|
187 |
+
def validate(self) -> None:
|
188 |
+
self.from_dict(self.to_dict())
|
189 |
+
|
190 |
+
@classmethod
|
191 |
+
def from_dict(cls, d: Dict[str, Any]) -> "DirectUrl":
|
192 |
+
return DirectUrl(
|
193 |
+
url=_get_required(d, str, "url"),
|
194 |
+
subdirectory=_get(d, str, "subdirectory"),
|
195 |
+
info=_exactly_one_of(
|
196 |
+
[
|
197 |
+
ArchiveInfo._from_dict(_get(d, dict, "archive_info")),
|
198 |
+
DirInfo._from_dict(_get(d, dict, "dir_info")),
|
199 |
+
VcsInfo._from_dict(_get(d, dict, "vcs_info")),
|
200 |
+
]
|
201 |
+
),
|
202 |
+
)
|
203 |
+
|
204 |
+
def to_dict(self) -> Dict[str, Any]:
|
205 |
+
res = _filter_none(
|
206 |
+
url=self.redacted_url,
|
207 |
+
subdirectory=self.subdirectory,
|
208 |
+
)
|
209 |
+
res[self.info.name] = self.info._to_dict()
|
210 |
+
return res
|
211 |
+
|
212 |
+
@classmethod
|
213 |
+
def from_json(cls, s: str) -> "DirectUrl":
|
214 |
+
return cls.from_dict(json.loads(s))
|
215 |
+
|
216 |
+
def to_json(self) -> str:
|
217 |
+
return json.dumps(self.to_dict(), sort_keys=True)
|
218 |
+
|
219 |
+
def is_local_editable(self) -> bool:
|
220 |
+
return isinstance(self.info, DirInfo) and self.info.editable
|
venv/lib/python3.10/site-packages/pip/_internal/models/format_control.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import FrozenSet, Optional, Set
|
2 |
+
|
3 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
4 |
+
|
5 |
+
from pip._internal.exceptions import CommandError
|
6 |
+
|
7 |
+
|
8 |
+
class FormatControl:
|
9 |
+
"""Helper for managing formats from which a package can be installed."""
|
10 |
+
|
11 |
+
__slots__ = ["no_binary", "only_binary"]
|
12 |
+
|
13 |
+
def __init__(
|
14 |
+
self,
|
15 |
+
no_binary: Optional[Set[str]] = None,
|
16 |
+
only_binary: Optional[Set[str]] = None,
|
17 |
+
) -> None:
|
18 |
+
if no_binary is None:
|
19 |
+
no_binary = set()
|
20 |
+
if only_binary is None:
|
21 |
+
only_binary = set()
|
22 |
+
|
23 |
+
self.no_binary = no_binary
|
24 |
+
self.only_binary = only_binary
|
25 |
+
|
26 |
+
def __eq__(self, other: object) -> bool:
|
27 |
+
if not isinstance(other, self.__class__):
|
28 |
+
return NotImplemented
|
29 |
+
|
30 |
+
if self.__slots__ != other.__slots__:
|
31 |
+
return False
|
32 |
+
|
33 |
+
return all(getattr(self, k) == getattr(other, k) for k in self.__slots__)
|
34 |
+
|
35 |
+
def __repr__(self) -> str:
|
36 |
+
return "{}({}, {})".format(
|
37 |
+
self.__class__.__name__, self.no_binary, self.only_binary
|
38 |
+
)
|
39 |
+
|
40 |
+
@staticmethod
|
41 |
+
def handle_mutual_excludes(value: str, target: Set[str], other: Set[str]) -> None:
|
42 |
+
if value.startswith("-"):
|
43 |
+
raise CommandError(
|
44 |
+
"--no-binary / --only-binary option requires 1 argument."
|
45 |
+
)
|
46 |
+
new = value.split(",")
|
47 |
+
while ":all:" in new:
|
48 |
+
other.clear()
|
49 |
+
target.clear()
|
50 |
+
target.add(":all:")
|
51 |
+
del new[: new.index(":all:") + 1]
|
52 |
+
# Without a none, we want to discard everything as :all: covers it
|
53 |
+
if ":none:" not in new:
|
54 |
+
return
|
55 |
+
for name in new:
|
56 |
+
if name == ":none:":
|
57 |
+
target.clear()
|
58 |
+
continue
|
59 |
+
name = canonicalize_name(name)
|
60 |
+
other.discard(name)
|
61 |
+
target.add(name)
|
62 |
+
|
63 |
+
def get_allowed_formats(self, canonical_name: str) -> FrozenSet[str]:
|
64 |
+
result = {"binary", "source"}
|
65 |
+
if canonical_name in self.only_binary:
|
66 |
+
result.discard("source")
|
67 |
+
elif canonical_name in self.no_binary:
|
68 |
+
result.discard("binary")
|
69 |
+
elif ":all:" in self.only_binary:
|
70 |
+
result.discard("source")
|
71 |
+
elif ":all:" in self.no_binary:
|
72 |
+
result.discard("binary")
|
73 |
+
return frozenset(result)
|
74 |
+
|
75 |
+
def disallow_binaries(self) -> None:
|
76 |
+
self.handle_mutual_excludes(
|
77 |
+
":all:",
|
78 |
+
self.no_binary,
|
79 |
+
self.only_binary,
|
80 |
+
)
|