Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- videollama2/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/top_level.txt +1 -0
- videollama2/lib/python3.10/site-packages/setuptools/_vendor/jaraco/collections/__pycache__/__init__.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/_vendor/zipp/__pycache__/__init__.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/_vendor/zipp/__pycache__/glob.cpython-310.pyc +0 -0
- videollama2/lib/python3.10/site-packages/setuptools/_vendor/zipp/compat/__init__.py +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/build_env.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/cache.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/configuration.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/exceptions.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/main.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/pyproject.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/self_outdated_check.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/wheel_builder.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/locations/__init__.py +456 -0
- vllm/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_distutils.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_sysconfig.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/base.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/locations/_distutils.py +172 -0
- vllm/lib/python3.10/site-packages/pip/_internal/locations/_sysconfig.py +214 -0
- vllm/lib/python3.10/site-packages/pip/_internal/locations/base.py +81 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/__init__.py +2 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/__pycache__/index.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/__pycache__/installation_report.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/candidate.py +25 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/format_control.py +78 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/index.py +28 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/installation_report.py +56 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/scheme.py +25 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/search_scope.py +127 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/selection_prefs.py +53 -0
- vllm/lib/python3.10/site-packages/pip/_internal/models/wheel.py +118 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/__init__.py +2 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/__pycache__/lazy_wheel.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/auth.py +566 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/cache.py +118 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/download.py +187 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/lazy_wheel.py +210 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/session.py +523 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/utils.py +98 -0
- vllm/lib/python3.10/site-packages/pip/_internal/network/xmlrpc.py +62 -0
- vllm/lib/python3.10/site-packages/pip/_internal/operations/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/_jaraco_text.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/_log.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/appdirs.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/compat.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/compatibility_tags.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/datetime.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -918,3 +918,4 @@ parrot/lib/python3.10/site-packages/scipy/interpolate/_bspl.cpython-310-x86_64-l
|
|
| 918 |
videollama2/lib/python3.10/site-packages/sklearn/linear_model/_sgd_fast.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 919 |
videollama2/lib/python3.10/site-packages/setuptools/_vendor/__pycache__/typing_extensions.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 920 |
vllm/lib/python3.10/site-packages/blake3/blake3.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 918 |
videollama2/lib/python3.10/site-packages/sklearn/linear_model/_sgd_fast.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 919 |
videollama2/lib/python3.10/site-packages/setuptools/_vendor/__pycache__/typing_extensions.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 920 |
vllm/lib/python3.10/site-packages/blake3/blake3.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 921 |
+
vllm/lib/python3.10/site-packages/pyglet/input/__pycache__/controller_db.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
videollama2/lib/python3.10/site-packages/setuptools/_vendor/jaraco.context-5.3.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
jaraco
|
videollama2/lib/python3.10/site-packages/setuptools/_vendor/jaraco/collections/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (32.2 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/_vendor/zipp/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (16.2 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/_vendor/zipp/__pycache__/glob.cpython-310.pyc
ADDED
|
Binary file (3.94 kB). View file
|
|
|
videollama2/lib/python3.10/site-packages/setuptools/_vendor/zipp/compat/__init__.py
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (671 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/build_env.cpython-310.pyc
ADDED
|
Binary file (9.87 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/cache.cpython-310.pyc
ADDED
|
Binary file (9.02 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/configuration.cpython-310.pyc
ADDED
|
Binary file (11.6 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/exceptions.cpython-310.pyc
ADDED
|
Binary file (28.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/main.cpython-310.pyc
ADDED
|
Binary file (595 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/pyproject.cpython-310.pyc
ADDED
|
Binary file (3.74 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/self_outdated_check.cpython-310.pyc
ADDED
|
Binary file (6.84 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/__pycache__/wheel_builder.cpython-310.pyc
ADDED
|
Binary file (8.62 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/locations/__init__.py
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
import pathlib
|
| 5 |
+
import sys
|
| 6 |
+
import sysconfig
|
| 7 |
+
from typing import Any, Dict, Generator, 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 _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_purelib",
|
| 31 |
+
"get_scheme",
|
| 32 |
+
"get_src_prefix",
|
| 33 |
+
"site_packages",
|
| 34 |
+
"user_site",
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
logger = logging.getLogger(__name__)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
_PLATLIBDIR: str = getattr(sys, "platlibdir", "lib")
|
| 42 |
+
|
| 43 |
+
_USE_SYSCONFIG_DEFAULT = sys.version_info >= (3, 10)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _should_use_sysconfig() -> bool:
|
| 47 |
+
"""This function determines the value of _USE_SYSCONFIG.
|
| 48 |
+
|
| 49 |
+
By default, pip uses sysconfig on Python 3.10+.
|
| 50 |
+
But Python distributors can override this decision by setting:
|
| 51 |
+
sysconfig._PIP_USE_SYSCONFIG = True / False
|
| 52 |
+
Rationale in https://github.com/pypa/pip/issues/10647
|
| 53 |
+
|
| 54 |
+
This is a function for testability, but should be constant during any one
|
| 55 |
+
run.
|
| 56 |
+
"""
|
| 57 |
+
return bool(getattr(sysconfig, "_PIP_USE_SYSCONFIG", _USE_SYSCONFIG_DEFAULT))
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
_USE_SYSCONFIG = _should_use_sysconfig()
|
| 61 |
+
|
| 62 |
+
if not _USE_SYSCONFIG:
|
| 63 |
+
# Import distutils lazily to avoid deprecation warnings,
|
| 64 |
+
# but import it soon enough that it is in memory and available during
|
| 65 |
+
# a pip reinstall.
|
| 66 |
+
from . import _distutils
|
| 67 |
+
|
| 68 |
+
# Be noisy about incompatibilities if this platforms "should" be using
|
| 69 |
+
# sysconfig, but is explicitly opting out and using distutils instead.
|
| 70 |
+
if _USE_SYSCONFIG_DEFAULT and not _USE_SYSCONFIG:
|
| 71 |
+
_MISMATCH_LEVEL = logging.WARNING
|
| 72 |
+
else:
|
| 73 |
+
_MISMATCH_LEVEL = logging.DEBUG
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _looks_like_bpo_44860() -> bool:
|
| 77 |
+
"""The resolution to bpo-44860 will change this incorrect platlib.
|
| 78 |
+
|
| 79 |
+
See <https://bugs.python.org/issue44860>.
|
| 80 |
+
"""
|
| 81 |
+
from distutils.command.install import INSTALL_SCHEMES
|
| 82 |
+
|
| 83 |
+
try:
|
| 84 |
+
unix_user_platlib = INSTALL_SCHEMES["unix_user"]["platlib"]
|
| 85 |
+
except KeyError:
|
| 86 |
+
return False
|
| 87 |
+
return unix_user_platlib == "$usersite"
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _looks_like_red_hat_patched_platlib_purelib(scheme: Dict[str, str]) -> bool:
|
| 91 |
+
platlib = scheme["platlib"]
|
| 92 |
+
if "/$platlibdir/" in platlib:
|
| 93 |
+
platlib = platlib.replace("/$platlibdir/", f"/{_PLATLIBDIR}/")
|
| 94 |
+
if "/lib64/" not in platlib:
|
| 95 |
+
return False
|
| 96 |
+
unpatched = platlib.replace("/lib64/", "/lib/")
|
| 97 |
+
return unpatched.replace("$platbase/", "$base/") == scheme["purelib"]
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
@functools.lru_cache(maxsize=None)
|
| 101 |
+
def _looks_like_red_hat_lib() -> bool:
|
| 102 |
+
"""Red Hat patches platlib in unix_prefix and unix_home, but not purelib.
|
| 103 |
+
|
| 104 |
+
This is the only way I can see to tell a Red Hat-patched Python.
|
| 105 |
+
"""
|
| 106 |
+
from distutils.command.install import INSTALL_SCHEMES
|
| 107 |
+
|
| 108 |
+
return all(
|
| 109 |
+
k in INSTALL_SCHEMES
|
| 110 |
+
and _looks_like_red_hat_patched_platlib_purelib(INSTALL_SCHEMES[k])
|
| 111 |
+
for k in ("unix_prefix", "unix_home")
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
@functools.lru_cache(maxsize=None)
|
| 116 |
+
def _looks_like_debian_scheme() -> bool:
|
| 117 |
+
"""Debian adds two additional schemes."""
|
| 118 |
+
from distutils.command.install import INSTALL_SCHEMES
|
| 119 |
+
|
| 120 |
+
return "deb_system" in INSTALL_SCHEMES and "unix_local" in INSTALL_SCHEMES
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
@functools.lru_cache(maxsize=None)
|
| 124 |
+
def _looks_like_red_hat_scheme() -> bool:
|
| 125 |
+
"""Red Hat patches ``sys.prefix`` and ``sys.exec_prefix``.
|
| 126 |
+
|
| 127 |
+
Red Hat's ``00251-change-user-install-location.patch`` changes the install
|
| 128 |
+
command's ``prefix`` and ``exec_prefix`` to append ``"/local"``. This is
|
| 129 |
+
(fortunately?) done quite unconditionally, so we create a default command
|
| 130 |
+
object without any configuration to detect this.
|
| 131 |
+
"""
|
| 132 |
+
from distutils.command.install import install
|
| 133 |
+
from distutils.dist import Distribution
|
| 134 |
+
|
| 135 |
+
cmd: Any = install(Distribution())
|
| 136 |
+
cmd.finalize_options()
|
| 137 |
+
return (
|
| 138 |
+
cmd.exec_prefix == f"{os.path.normpath(sys.exec_prefix)}/local"
|
| 139 |
+
and cmd.prefix == f"{os.path.normpath(sys.prefix)}/local"
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
@functools.lru_cache(maxsize=None)
|
| 144 |
+
def _looks_like_slackware_scheme() -> bool:
|
| 145 |
+
"""Slackware patches sysconfig but fails to patch distutils and site.
|
| 146 |
+
|
| 147 |
+
Slackware changes sysconfig's user scheme to use ``"lib64"`` for the lib
|
| 148 |
+
path, but does not do the same to the site module.
|
| 149 |
+
"""
|
| 150 |
+
if user_site is None: # User-site not available.
|
| 151 |
+
return False
|
| 152 |
+
try:
|
| 153 |
+
paths = sysconfig.get_paths(scheme="posix_user", expand=False)
|
| 154 |
+
except KeyError: # User-site not available.
|
| 155 |
+
return False
|
| 156 |
+
return "/lib64/" in paths["purelib"] and "/lib64/" not in user_site
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
@functools.lru_cache(maxsize=None)
|
| 160 |
+
def _looks_like_msys2_mingw_scheme() -> bool:
|
| 161 |
+
"""MSYS2 patches distutils and sysconfig to use a UNIX-like scheme.
|
| 162 |
+
|
| 163 |
+
However, MSYS2 incorrectly patches sysconfig ``nt`` scheme. The fix is
|
| 164 |
+
likely going to be included in their 3.10 release, so we ignore the warning.
|
| 165 |
+
See msys2/MINGW-packages#9319.
|
| 166 |
+
|
| 167 |
+
MSYS2 MINGW's patch uses lowercase ``"lib"`` instead of the usual uppercase,
|
| 168 |
+
and is missing the final ``"site-packages"``.
|
| 169 |
+
"""
|
| 170 |
+
paths = sysconfig.get_paths("nt", expand=False)
|
| 171 |
+
return all(
|
| 172 |
+
"Lib" not in p and "lib" in p and not p.endswith("site-packages")
|
| 173 |
+
for p in (paths[key] for key in ("platlib", "purelib"))
|
| 174 |
+
)
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def _fix_abiflags(parts: Tuple[str]) -> Generator[str, None, None]:
|
| 178 |
+
ldversion = sysconfig.get_config_var("LDVERSION")
|
| 179 |
+
abiflags = getattr(sys, "abiflags", None)
|
| 180 |
+
|
| 181 |
+
# LDVERSION does not end with sys.abiflags. Just return the path unchanged.
|
| 182 |
+
if not ldversion or not abiflags or not ldversion.endswith(abiflags):
|
| 183 |
+
yield from parts
|
| 184 |
+
return
|
| 185 |
+
|
| 186 |
+
# Strip sys.abiflags from LDVERSION-based path components.
|
| 187 |
+
for part in parts:
|
| 188 |
+
if part.endswith(ldversion):
|
| 189 |
+
part = part[: (0 - len(abiflags))]
|
| 190 |
+
yield part
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
@functools.lru_cache(maxsize=None)
|
| 194 |
+
def _warn_mismatched(old: pathlib.Path, new: pathlib.Path, *, key: str) -> None:
|
| 195 |
+
issue_url = "https://github.com/pypa/pip/issues/10151"
|
| 196 |
+
message = (
|
| 197 |
+
"Value for %s does not match. Please report this to <%s>"
|
| 198 |
+
"\ndistutils: %s"
|
| 199 |
+
"\nsysconfig: %s"
|
| 200 |
+
)
|
| 201 |
+
logger.log(_MISMATCH_LEVEL, message, key, issue_url, old, new)
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def _warn_if_mismatch(old: pathlib.Path, new: pathlib.Path, *, key: str) -> bool:
|
| 205 |
+
if old == new:
|
| 206 |
+
return False
|
| 207 |
+
_warn_mismatched(old, new, key=key)
|
| 208 |
+
return True
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
@functools.lru_cache(maxsize=None)
|
| 212 |
+
def _log_context(
|
| 213 |
+
*,
|
| 214 |
+
user: bool = False,
|
| 215 |
+
home: Optional[str] = None,
|
| 216 |
+
root: Optional[str] = None,
|
| 217 |
+
prefix: Optional[str] = None,
|
| 218 |
+
) -> None:
|
| 219 |
+
parts = [
|
| 220 |
+
"Additional context:",
|
| 221 |
+
"user = %r",
|
| 222 |
+
"home = %r",
|
| 223 |
+
"root = %r",
|
| 224 |
+
"prefix = %r",
|
| 225 |
+
]
|
| 226 |
+
|
| 227 |
+
logger.log(_MISMATCH_LEVEL, "\n".join(parts), user, home, root, prefix)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def get_scheme(
|
| 231 |
+
dist_name: str,
|
| 232 |
+
user: bool = False,
|
| 233 |
+
home: Optional[str] = None,
|
| 234 |
+
root: Optional[str] = None,
|
| 235 |
+
isolated: bool = False,
|
| 236 |
+
prefix: Optional[str] = None,
|
| 237 |
+
) -> Scheme:
|
| 238 |
+
new = _sysconfig.get_scheme(
|
| 239 |
+
dist_name,
|
| 240 |
+
user=user,
|
| 241 |
+
home=home,
|
| 242 |
+
root=root,
|
| 243 |
+
isolated=isolated,
|
| 244 |
+
prefix=prefix,
|
| 245 |
+
)
|
| 246 |
+
if _USE_SYSCONFIG:
|
| 247 |
+
return new
|
| 248 |
+
|
| 249 |
+
old = _distutils.get_scheme(
|
| 250 |
+
dist_name,
|
| 251 |
+
user=user,
|
| 252 |
+
home=home,
|
| 253 |
+
root=root,
|
| 254 |
+
isolated=isolated,
|
| 255 |
+
prefix=prefix,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
warning_contexts = []
|
| 259 |
+
for k in SCHEME_KEYS:
|
| 260 |
+
old_v = pathlib.Path(getattr(old, k))
|
| 261 |
+
new_v = pathlib.Path(getattr(new, k))
|
| 262 |
+
|
| 263 |
+
if old_v == new_v:
|
| 264 |
+
continue
|
| 265 |
+
|
| 266 |
+
# distutils incorrectly put PyPy packages under ``site-packages/python``
|
| 267 |
+
# in the ``posix_home`` scheme, but PyPy devs said they expect the
|
| 268 |
+
# directory name to be ``pypy`` instead. So we treat this as a bug fix
|
| 269 |
+
# and not warn about it. See bpo-43307 and python/cpython#24628.
|
| 270 |
+
skip_pypy_special_case = (
|
| 271 |
+
sys.implementation.name == "pypy"
|
| 272 |
+
and home is not None
|
| 273 |
+
and k in ("platlib", "purelib")
|
| 274 |
+
and old_v.parent == new_v.parent
|
| 275 |
+
and old_v.name.startswith("python")
|
| 276 |
+
and new_v.name.startswith("pypy")
|
| 277 |
+
)
|
| 278 |
+
if skip_pypy_special_case:
|
| 279 |
+
continue
|
| 280 |
+
|
| 281 |
+
# sysconfig's ``osx_framework_user`` does not include ``pythonX.Y`` in
|
| 282 |
+
# the ``include`` value, but distutils's ``headers`` does. We'll let
|
| 283 |
+
# CPython decide whether this is a bug or feature. See bpo-43948.
|
| 284 |
+
skip_osx_framework_user_special_case = (
|
| 285 |
+
user
|
| 286 |
+
and is_osx_framework()
|
| 287 |
+
and k == "headers"
|
| 288 |
+
and old_v.parent.parent == new_v.parent
|
| 289 |
+
and old_v.parent.name.startswith("python")
|
| 290 |
+
)
|
| 291 |
+
if skip_osx_framework_user_special_case:
|
| 292 |
+
continue
|
| 293 |
+
|
| 294 |
+
# On Red Hat and derived Linux distributions, distutils is patched to
|
| 295 |
+
# use "lib64" instead of "lib" for platlib.
|
| 296 |
+
if k == "platlib" and _looks_like_red_hat_lib():
|
| 297 |
+
continue
|
| 298 |
+
|
| 299 |
+
# On Python 3.9+, sysconfig's posix_user scheme sets platlib against
|
| 300 |
+
# sys.platlibdir, but distutils's unix_user incorrectly coninutes
|
| 301 |
+
# using the same $usersite for both platlib and purelib. This creates a
|
| 302 |
+
# mismatch when sys.platlibdir is not "lib".
|
| 303 |
+
skip_bpo_44860 = (
|
| 304 |
+
user
|
| 305 |
+
and k == "platlib"
|
| 306 |
+
and not WINDOWS
|
| 307 |
+
and sys.version_info >= (3, 9)
|
| 308 |
+
and _PLATLIBDIR != "lib"
|
| 309 |
+
and _looks_like_bpo_44860()
|
| 310 |
+
)
|
| 311 |
+
if skip_bpo_44860:
|
| 312 |
+
continue
|
| 313 |
+
|
| 314 |
+
# Slackware incorrectly patches posix_user to use lib64 instead of lib,
|
| 315 |
+
# but not usersite to match the location.
|
| 316 |
+
skip_slackware_user_scheme = (
|
| 317 |
+
user
|
| 318 |
+
and k in ("platlib", "purelib")
|
| 319 |
+
and not WINDOWS
|
| 320 |
+
and _looks_like_slackware_scheme()
|
| 321 |
+
)
|
| 322 |
+
if skip_slackware_user_scheme:
|
| 323 |
+
continue
|
| 324 |
+
|
| 325 |
+
# Both Debian and Red Hat patch Python to place the system site under
|
| 326 |
+
# /usr/local instead of /usr. Debian also places lib in dist-packages
|
| 327 |
+
# instead of site-packages, but the /usr/local check should cover it.
|
| 328 |
+
skip_linux_system_special_case = (
|
| 329 |
+
not (user or home or prefix or running_under_virtualenv())
|
| 330 |
+
and old_v.parts[1:3] == ("usr", "local")
|
| 331 |
+
and len(new_v.parts) > 1
|
| 332 |
+
and new_v.parts[1] == "usr"
|
| 333 |
+
and (len(new_v.parts) < 3 or new_v.parts[2] != "local")
|
| 334 |
+
and (_looks_like_red_hat_scheme() or _looks_like_debian_scheme())
|
| 335 |
+
)
|
| 336 |
+
if skip_linux_system_special_case:
|
| 337 |
+
continue
|
| 338 |
+
|
| 339 |
+
# MSYS2 MINGW's sysconfig patch does not include the "site-packages"
|
| 340 |
+
# part of the path. This is incorrect and will be fixed in MSYS.
|
| 341 |
+
skip_msys2_mingw_bug = (
|
| 342 |
+
WINDOWS and k in ("platlib", "purelib") and _looks_like_msys2_mingw_scheme()
|
| 343 |
+
)
|
| 344 |
+
if skip_msys2_mingw_bug:
|
| 345 |
+
continue
|
| 346 |
+
|
| 347 |
+
# CPython's POSIX install script invokes pip (via ensurepip) against the
|
| 348 |
+
# interpreter located in the source tree, not the install site. This
|
| 349 |
+
# triggers special logic in sysconfig that's not present in distutils.
|
| 350 |
+
# https://github.com/python/cpython/blob/8c21941ddaf/Lib/sysconfig.py#L178-L194
|
| 351 |
+
skip_cpython_build = (
|
| 352 |
+
sysconfig.is_python_build(check_home=True)
|
| 353 |
+
and not WINDOWS
|
| 354 |
+
and k in ("headers", "include", "platinclude")
|
| 355 |
+
)
|
| 356 |
+
if skip_cpython_build:
|
| 357 |
+
continue
|
| 358 |
+
|
| 359 |
+
warning_contexts.append((old_v, new_v, f"scheme.{k}"))
|
| 360 |
+
|
| 361 |
+
if not warning_contexts:
|
| 362 |
+
return old
|
| 363 |
+
|
| 364 |
+
# Check if this path mismatch is caused by distutils config files. Those
|
| 365 |
+
# files will no longer work once we switch to sysconfig, so this raises a
|
| 366 |
+
# deprecation message for them.
|
| 367 |
+
default_old = _distutils.distutils_scheme(
|
| 368 |
+
dist_name,
|
| 369 |
+
user,
|
| 370 |
+
home,
|
| 371 |
+
root,
|
| 372 |
+
isolated,
|
| 373 |
+
prefix,
|
| 374 |
+
ignore_config_files=True,
|
| 375 |
+
)
|
| 376 |
+
if any(default_old[k] != getattr(old, k) for k in SCHEME_KEYS):
|
| 377 |
+
deprecated(
|
| 378 |
+
reason=(
|
| 379 |
+
"Configuring installation scheme with distutils config files "
|
| 380 |
+
"is deprecated and will no longer work in the near future. If you "
|
| 381 |
+
"are using a Homebrew or Linuxbrew Python, please see discussion "
|
| 382 |
+
"at https://github.com/Homebrew/homebrew-core/issues/76621"
|
| 383 |
+
),
|
| 384 |
+
replacement=None,
|
| 385 |
+
gone_in=None,
|
| 386 |
+
)
|
| 387 |
+
return old
|
| 388 |
+
|
| 389 |
+
# Post warnings about this mismatch so user can report them back.
|
| 390 |
+
for old_v, new_v, key in warning_contexts:
|
| 391 |
+
_warn_mismatched(old_v, new_v, key=key)
|
| 392 |
+
_log_context(user=user, home=home, root=root, prefix=prefix)
|
| 393 |
+
|
| 394 |
+
return old
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def get_bin_prefix() -> str:
|
| 398 |
+
new = _sysconfig.get_bin_prefix()
|
| 399 |
+
if _USE_SYSCONFIG:
|
| 400 |
+
return new
|
| 401 |
+
|
| 402 |
+
old = _distutils.get_bin_prefix()
|
| 403 |
+
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="bin_prefix"):
|
| 404 |
+
_log_context()
|
| 405 |
+
return old
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def get_bin_user() -> str:
|
| 409 |
+
return _sysconfig.get_scheme("", user=True).scripts
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
def _looks_like_deb_system_dist_packages(value: str) -> bool:
|
| 413 |
+
"""Check if the value is Debian's APT-controlled dist-packages.
|
| 414 |
+
|
| 415 |
+
Debian's ``distutils.sysconfig.get_python_lib()`` implementation returns the
|
| 416 |
+
default package path controlled by APT, but does not patch ``sysconfig`` to
|
| 417 |
+
do the same. This is similar to the bug worked around in ``get_scheme()``,
|
| 418 |
+
but here the default is ``deb_system`` instead of ``unix_local``. Ultimately
|
| 419 |
+
we can't do anything about this Debian bug, and this detection allows us to
|
| 420 |
+
skip the warning when needed.
|
| 421 |
+
"""
|
| 422 |
+
if not _looks_like_debian_scheme():
|
| 423 |
+
return False
|
| 424 |
+
if value == "/usr/lib/python3/dist-packages":
|
| 425 |
+
return True
|
| 426 |
+
return False
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
def get_purelib() -> str:
|
| 430 |
+
"""Return the default pure-Python lib location."""
|
| 431 |
+
new = _sysconfig.get_purelib()
|
| 432 |
+
if _USE_SYSCONFIG:
|
| 433 |
+
return new
|
| 434 |
+
|
| 435 |
+
old = _distutils.get_purelib()
|
| 436 |
+
if _looks_like_deb_system_dist_packages(old):
|
| 437 |
+
return old
|
| 438 |
+
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="purelib"):
|
| 439 |
+
_log_context()
|
| 440 |
+
return old
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
def get_platlib() -> str:
|
| 444 |
+
"""Return the default platform-shared lib location."""
|
| 445 |
+
new = _sysconfig.get_platlib()
|
| 446 |
+
if _USE_SYSCONFIG:
|
| 447 |
+
return new
|
| 448 |
+
|
| 449 |
+
from . import _distutils
|
| 450 |
+
|
| 451 |
+
old = _distutils.get_platlib()
|
| 452 |
+
if _looks_like_deb_system_dist_packages(old):
|
| 453 |
+
return old
|
| 454 |
+
if _warn_if_mismatch(pathlib.Path(old), pathlib.Path(new), key="platlib"):
|
| 455 |
+
_log_context()
|
| 456 |
+
return old
|
vllm/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_distutils.cpython-310.pyc
ADDED
|
Binary file (4.54 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/_sysconfig.cpython-310.pyc
ADDED
|
Binary file (5.99 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/locations/__pycache__/base.cpython-310.pyc
ADDED
|
Binary file (2.37 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/locations/_distutils.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
# If pip's going to use distutils, it should not be using the copy that setuptools
|
| 7 |
+
# might have injected into the environment. This is done by removing the injected
|
| 8 |
+
# shim, if it's injected.
|
| 9 |
+
#
|
| 10 |
+
# See https://github.com/pypa/pip/issues/8761 for the original discussion and
|
| 11 |
+
# rationale for why this is done within pip.
|
| 12 |
+
try:
|
| 13 |
+
__import__("_distutils_hack").remove_shim()
|
| 14 |
+
except (ImportError, AttributeError):
|
| 15 |
+
pass
|
| 16 |
+
|
| 17 |
+
import logging
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
from distutils.cmd import Command as DistutilsCommand
|
| 21 |
+
from distutils.command.install import SCHEME_KEYS
|
| 22 |
+
from distutils.command.install import install as distutils_install_command
|
| 23 |
+
from distutils.sysconfig import get_python_lib
|
| 24 |
+
from typing import Dict, List, Optional, Union
|
| 25 |
+
|
| 26 |
+
from pip._internal.models.scheme import Scheme
|
| 27 |
+
from pip._internal.utils.compat import WINDOWS
|
| 28 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
| 29 |
+
|
| 30 |
+
from .base import get_major_minor_version
|
| 31 |
+
|
| 32 |
+
logger = logging.getLogger(__name__)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def distutils_scheme(
|
| 36 |
+
dist_name: str,
|
| 37 |
+
user: bool = False,
|
| 38 |
+
home: Optional[str] = None,
|
| 39 |
+
root: Optional[str] = None,
|
| 40 |
+
isolated: bool = False,
|
| 41 |
+
prefix: Optional[str] = None,
|
| 42 |
+
*,
|
| 43 |
+
ignore_config_files: bool = False,
|
| 44 |
+
) -> Dict[str, str]:
|
| 45 |
+
"""
|
| 46 |
+
Return a distutils install scheme
|
| 47 |
+
"""
|
| 48 |
+
from distutils.dist import Distribution
|
| 49 |
+
|
| 50 |
+
dist_args: Dict[str, Union[str, List[str]]] = {"name": dist_name}
|
| 51 |
+
if isolated:
|
| 52 |
+
dist_args["script_args"] = ["--no-user-cfg"]
|
| 53 |
+
|
| 54 |
+
d = Distribution(dist_args)
|
| 55 |
+
if not ignore_config_files:
|
| 56 |
+
try:
|
| 57 |
+
d.parse_config_files()
|
| 58 |
+
except UnicodeDecodeError:
|
| 59 |
+
paths = d.find_config_files()
|
| 60 |
+
logger.warning(
|
| 61 |
+
"Ignore distutils configs in %s due to encoding errors.",
|
| 62 |
+
", ".join(os.path.basename(p) for p in paths),
|
| 63 |
+
)
|
| 64 |
+
obj: Optional[DistutilsCommand] = None
|
| 65 |
+
obj = d.get_command_obj("install", create=True)
|
| 66 |
+
assert obj is not None
|
| 67 |
+
i: distutils_install_command = obj
|
| 68 |
+
# NOTE: setting user or home has the side-effect of creating the home dir
|
| 69 |
+
# or user base for installations during finalize_options()
|
| 70 |
+
# ideally, we'd prefer a scheme class that has no side-effects.
|
| 71 |
+
assert not (user and prefix), f"user={user} prefix={prefix}"
|
| 72 |
+
assert not (home and prefix), f"home={home} prefix={prefix}"
|
| 73 |
+
i.user = user or i.user
|
| 74 |
+
if user or home:
|
| 75 |
+
i.prefix = ""
|
| 76 |
+
i.prefix = prefix or i.prefix
|
| 77 |
+
i.home = home or i.home
|
| 78 |
+
i.root = root or i.root
|
| 79 |
+
i.finalize_options()
|
| 80 |
+
|
| 81 |
+
scheme: Dict[str, str] = {}
|
| 82 |
+
for key in SCHEME_KEYS:
|
| 83 |
+
scheme[key] = getattr(i, "install_" + key)
|
| 84 |
+
|
| 85 |
+
# install_lib specified in setup.cfg should install *everything*
|
| 86 |
+
# into there (i.e. it takes precedence over both purelib and
|
| 87 |
+
# platlib). Note, i.install_lib is *always* set after
|
| 88 |
+
# finalize_options(); we only want to override here if the user
|
| 89 |
+
# has explicitly requested it hence going back to the config
|
| 90 |
+
if "install_lib" in d.get_option_dict("install"):
|
| 91 |
+
scheme.update({"purelib": i.install_lib, "platlib": i.install_lib})
|
| 92 |
+
|
| 93 |
+
if running_under_virtualenv():
|
| 94 |
+
if home:
|
| 95 |
+
prefix = home
|
| 96 |
+
elif user:
|
| 97 |
+
prefix = i.install_userbase
|
| 98 |
+
else:
|
| 99 |
+
prefix = i.prefix
|
| 100 |
+
scheme["headers"] = os.path.join(
|
| 101 |
+
prefix,
|
| 102 |
+
"include",
|
| 103 |
+
"site",
|
| 104 |
+
f"python{get_major_minor_version()}",
|
| 105 |
+
dist_name,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
if root is not None:
|
| 109 |
+
path_no_drive = os.path.splitdrive(os.path.abspath(scheme["headers"]))[1]
|
| 110 |
+
scheme["headers"] = os.path.join(root, path_no_drive[1:])
|
| 111 |
+
|
| 112 |
+
return scheme
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def get_scheme(
|
| 116 |
+
dist_name: str,
|
| 117 |
+
user: bool = False,
|
| 118 |
+
home: Optional[str] = None,
|
| 119 |
+
root: Optional[str] = None,
|
| 120 |
+
isolated: bool = False,
|
| 121 |
+
prefix: Optional[str] = None,
|
| 122 |
+
) -> Scheme:
|
| 123 |
+
"""
|
| 124 |
+
Get the "scheme" corresponding to the input parameters. The distutils
|
| 125 |
+
documentation provides the context for the available schemes:
|
| 126 |
+
https://docs.python.org/3/install/index.html#alternate-installation
|
| 127 |
+
|
| 128 |
+
:param dist_name: the name of the package to retrieve the scheme for, used
|
| 129 |
+
in the headers scheme path
|
| 130 |
+
:param user: indicates to use the "user" scheme
|
| 131 |
+
:param home: indicates to use the "home" scheme and provides the base
|
| 132 |
+
directory for the same
|
| 133 |
+
:param root: root under which other directories are re-based
|
| 134 |
+
:param isolated: equivalent to --no-user-cfg, i.e. do not consider
|
| 135 |
+
~/.pydistutils.cfg (posix) or ~/pydistutils.cfg (non-posix) for
|
| 136 |
+
scheme paths
|
| 137 |
+
:param prefix: indicates to use the "prefix" scheme and provides the
|
| 138 |
+
base directory for the same
|
| 139 |
+
"""
|
| 140 |
+
scheme = distutils_scheme(dist_name, user, home, root, isolated, prefix)
|
| 141 |
+
return Scheme(
|
| 142 |
+
platlib=scheme["platlib"],
|
| 143 |
+
purelib=scheme["purelib"],
|
| 144 |
+
headers=scheme["headers"],
|
| 145 |
+
scripts=scheme["scripts"],
|
| 146 |
+
data=scheme["data"],
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def get_bin_prefix() -> str:
|
| 151 |
+
# XXX: In old virtualenv versions, sys.prefix can contain '..' components,
|
| 152 |
+
# so we need to call normpath to eliminate them.
|
| 153 |
+
prefix = os.path.normpath(sys.prefix)
|
| 154 |
+
if WINDOWS:
|
| 155 |
+
bin_py = os.path.join(prefix, "Scripts")
|
| 156 |
+
# buildout uses 'bin' on Windows too?
|
| 157 |
+
if not os.path.exists(bin_py):
|
| 158 |
+
bin_py = os.path.join(prefix, "bin")
|
| 159 |
+
return bin_py
|
| 160 |
+
# Forcing to use /usr/local/bin for standard macOS framework installs
|
| 161 |
+
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
|
| 162 |
+
if sys.platform[:6] == "darwin" and prefix[:16] == "/System/Library/":
|
| 163 |
+
return "/usr/local/bin"
|
| 164 |
+
return os.path.join(prefix, "bin")
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def get_purelib() -> str:
|
| 168 |
+
return get_python_lib(plat_specific=False)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def get_platlib() -> str:
|
| 172 |
+
return get_python_lib(plat_specific=True)
|
vllm/lib/python3.10/site-packages/pip/_internal/locations/_sysconfig.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
import sysconfig
|
| 5 |
+
import typing
|
| 6 |
+
|
| 7 |
+
from pip._internal.exceptions import InvalidSchemeCombination, UserInstallationInvalid
|
| 8 |
+
from pip._internal.models.scheme import SCHEME_KEYS, Scheme
|
| 9 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
| 10 |
+
|
| 11 |
+
from .base import change_root, get_major_minor_version, is_osx_framework
|
| 12 |
+
|
| 13 |
+
logger = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# Notes on _infer_* functions.
|
| 17 |
+
# Unfortunately ``get_default_scheme()`` didn't exist before 3.10, so there's no
|
| 18 |
+
# way to ask things like "what is the '_prefix' scheme on this platform". These
|
| 19 |
+
# functions try to answer that with some heuristics while accounting for ad-hoc
|
| 20 |
+
# platforms not covered by CPython's default sysconfig implementation. If the
|
| 21 |
+
# ad-hoc implementation does not fully implement sysconfig, we'll fall back to
|
| 22 |
+
# a POSIX scheme.
|
| 23 |
+
|
| 24 |
+
_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names())
|
| 25 |
+
|
| 26 |
+
_PREFERRED_SCHEME_API = getattr(sysconfig, "get_preferred_scheme", None)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _should_use_osx_framework_prefix() -> bool:
|
| 30 |
+
"""Check for Apple's ``osx_framework_library`` scheme.
|
| 31 |
+
|
| 32 |
+
Python distributed by Apple's Command Line Tools has this special scheme
|
| 33 |
+
that's used when:
|
| 34 |
+
|
| 35 |
+
* This is a framework build.
|
| 36 |
+
* We are installing into the system prefix.
|
| 37 |
+
|
| 38 |
+
This does not account for ``pip install --prefix`` (also means we're not
|
| 39 |
+
installing to the system prefix), which should use ``posix_prefix``, but
|
| 40 |
+
logic here means ``_infer_prefix()`` outputs ``osx_framework_library``. But
|
| 41 |
+
since ``prefix`` is not available for ``sysconfig.get_default_scheme()``,
|
| 42 |
+
which is the stdlib replacement for ``_infer_prefix()``, presumably Apple
|
| 43 |
+
wouldn't be able to magically switch between ``osx_framework_library`` and
|
| 44 |
+
``posix_prefix``. ``_infer_prefix()`` returning ``osx_framework_library``
|
| 45 |
+
means its behavior is consistent whether we use the stdlib implementation
|
| 46 |
+
or our own, and we deal with this special case in ``get_scheme()`` instead.
|
| 47 |
+
"""
|
| 48 |
+
return (
|
| 49 |
+
"osx_framework_library" in _AVAILABLE_SCHEMES
|
| 50 |
+
and not running_under_virtualenv()
|
| 51 |
+
and is_osx_framework()
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _infer_prefix() -> str:
|
| 56 |
+
"""Try to find a prefix scheme for the current platform.
|
| 57 |
+
|
| 58 |
+
This tries:
|
| 59 |
+
|
| 60 |
+
* A special ``osx_framework_library`` for Python distributed by Apple's
|
| 61 |
+
Command Line Tools, when not running in a virtual environment.
|
| 62 |
+
* Implementation + OS, used by PyPy on Windows (``pypy_nt``).
|
| 63 |
+
* Implementation without OS, used by PyPy on POSIX (``pypy``).
|
| 64 |
+
* OS + "prefix", used by CPython on POSIX (``posix_prefix``).
|
| 65 |
+
* Just the OS name, used by CPython on Windows (``nt``).
|
| 66 |
+
|
| 67 |
+
If none of the above works, fall back to ``posix_prefix``.
|
| 68 |
+
"""
|
| 69 |
+
if _PREFERRED_SCHEME_API:
|
| 70 |
+
return _PREFERRED_SCHEME_API("prefix")
|
| 71 |
+
if _should_use_osx_framework_prefix():
|
| 72 |
+
return "osx_framework_library"
|
| 73 |
+
implementation_suffixed = f"{sys.implementation.name}_{os.name}"
|
| 74 |
+
if implementation_suffixed in _AVAILABLE_SCHEMES:
|
| 75 |
+
return implementation_suffixed
|
| 76 |
+
if sys.implementation.name in _AVAILABLE_SCHEMES:
|
| 77 |
+
return sys.implementation.name
|
| 78 |
+
suffixed = f"{os.name}_prefix"
|
| 79 |
+
if suffixed in _AVAILABLE_SCHEMES:
|
| 80 |
+
return suffixed
|
| 81 |
+
if os.name in _AVAILABLE_SCHEMES: # On Windows, prefx is just called "nt".
|
| 82 |
+
return os.name
|
| 83 |
+
return "posix_prefix"
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _infer_user() -> str:
|
| 87 |
+
"""Try to find a user scheme for the current platform."""
|
| 88 |
+
if _PREFERRED_SCHEME_API:
|
| 89 |
+
return _PREFERRED_SCHEME_API("user")
|
| 90 |
+
if is_osx_framework() and not running_under_virtualenv():
|
| 91 |
+
suffixed = "osx_framework_user"
|
| 92 |
+
else:
|
| 93 |
+
suffixed = f"{os.name}_user"
|
| 94 |
+
if suffixed in _AVAILABLE_SCHEMES:
|
| 95 |
+
return suffixed
|
| 96 |
+
if "posix_user" not in _AVAILABLE_SCHEMES: # User scheme unavailable.
|
| 97 |
+
raise UserInstallationInvalid()
|
| 98 |
+
return "posix_user"
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def _infer_home() -> str:
|
| 102 |
+
"""Try to find a home for the current platform."""
|
| 103 |
+
if _PREFERRED_SCHEME_API:
|
| 104 |
+
return _PREFERRED_SCHEME_API("home")
|
| 105 |
+
suffixed = f"{os.name}_home"
|
| 106 |
+
if suffixed in _AVAILABLE_SCHEMES:
|
| 107 |
+
return suffixed
|
| 108 |
+
return "posix_home"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# Update these keys if the user sets a custom home.
|
| 112 |
+
_HOME_KEYS = [
|
| 113 |
+
"installed_base",
|
| 114 |
+
"base",
|
| 115 |
+
"installed_platbase",
|
| 116 |
+
"platbase",
|
| 117 |
+
"prefix",
|
| 118 |
+
"exec_prefix",
|
| 119 |
+
]
|
| 120 |
+
if sysconfig.get_config_var("userbase") is not None:
|
| 121 |
+
_HOME_KEYS.append("userbase")
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def get_scheme(
|
| 125 |
+
dist_name: str,
|
| 126 |
+
user: bool = False,
|
| 127 |
+
home: typing.Optional[str] = None,
|
| 128 |
+
root: typing.Optional[str] = None,
|
| 129 |
+
isolated: bool = False,
|
| 130 |
+
prefix: typing.Optional[str] = None,
|
| 131 |
+
) -> Scheme:
|
| 132 |
+
"""
|
| 133 |
+
Get the "scheme" corresponding to the input parameters.
|
| 134 |
+
|
| 135 |
+
:param dist_name: the name of the package to retrieve the scheme for, used
|
| 136 |
+
in the headers scheme path
|
| 137 |
+
:param user: indicates to use the "user" scheme
|
| 138 |
+
:param home: indicates to use the "home" scheme
|
| 139 |
+
:param root: root under which other directories are re-based
|
| 140 |
+
:param isolated: ignored, but kept for distutils compatibility (where
|
| 141 |
+
this controls whether the user-site pydistutils.cfg is honored)
|
| 142 |
+
:param prefix: indicates to use the "prefix" scheme and provides the
|
| 143 |
+
base directory for the same
|
| 144 |
+
"""
|
| 145 |
+
if user and prefix:
|
| 146 |
+
raise InvalidSchemeCombination("--user", "--prefix")
|
| 147 |
+
if home and prefix:
|
| 148 |
+
raise InvalidSchemeCombination("--home", "--prefix")
|
| 149 |
+
|
| 150 |
+
if home is not None:
|
| 151 |
+
scheme_name = _infer_home()
|
| 152 |
+
elif user:
|
| 153 |
+
scheme_name = _infer_user()
|
| 154 |
+
else:
|
| 155 |
+
scheme_name = _infer_prefix()
|
| 156 |
+
|
| 157 |
+
# Special case: When installing into a custom prefix, use posix_prefix
|
| 158 |
+
# instead of osx_framework_library. See _should_use_osx_framework_prefix()
|
| 159 |
+
# docstring for details.
|
| 160 |
+
if prefix is not None and scheme_name == "osx_framework_library":
|
| 161 |
+
scheme_name = "posix_prefix"
|
| 162 |
+
|
| 163 |
+
if home is not None:
|
| 164 |
+
variables = {k: home for k in _HOME_KEYS}
|
| 165 |
+
elif prefix is not None:
|
| 166 |
+
variables = {k: prefix for k in _HOME_KEYS}
|
| 167 |
+
else:
|
| 168 |
+
variables = {}
|
| 169 |
+
|
| 170 |
+
paths = sysconfig.get_paths(scheme=scheme_name, vars=variables)
|
| 171 |
+
|
| 172 |
+
# Logic here is very arbitrary, we're doing it for compatibility, don't ask.
|
| 173 |
+
# 1. Pip historically uses a special header path in virtual environments.
|
| 174 |
+
# 2. If the distribution name is not known, distutils uses 'UNKNOWN'. We
|
| 175 |
+
# only do the same when not running in a virtual environment because
|
| 176 |
+
# pip's historical header path logic (see point 1) did not do this.
|
| 177 |
+
if running_under_virtualenv():
|
| 178 |
+
if user:
|
| 179 |
+
base = variables.get("userbase", sys.prefix)
|
| 180 |
+
else:
|
| 181 |
+
base = variables.get("base", sys.prefix)
|
| 182 |
+
python_xy = f"python{get_major_minor_version()}"
|
| 183 |
+
paths["include"] = os.path.join(base, "include", "site", python_xy)
|
| 184 |
+
elif not dist_name:
|
| 185 |
+
dist_name = "UNKNOWN"
|
| 186 |
+
|
| 187 |
+
scheme = Scheme(
|
| 188 |
+
platlib=paths["platlib"],
|
| 189 |
+
purelib=paths["purelib"],
|
| 190 |
+
headers=os.path.join(paths["include"], dist_name),
|
| 191 |
+
scripts=paths["scripts"],
|
| 192 |
+
data=paths["data"],
|
| 193 |
+
)
|
| 194 |
+
if root is not None:
|
| 195 |
+
converted_keys = {}
|
| 196 |
+
for key in SCHEME_KEYS:
|
| 197 |
+
converted_keys[key] = change_root(root, getattr(scheme, key))
|
| 198 |
+
scheme = Scheme(**converted_keys)
|
| 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"]
|
vllm/lib/python3.10/site-packages/pip/_internal/locations/base.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import os
|
| 3 |
+
import site
|
| 4 |
+
import sys
|
| 5 |
+
import sysconfig
|
| 6 |
+
import typing
|
| 7 |
+
|
| 8 |
+
from pip._internal.exceptions import InstallationError
|
| 9 |
+
from pip._internal.utils import appdirs
|
| 10 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
| 11 |
+
|
| 12 |
+
# Application Directories
|
| 13 |
+
USER_CACHE_DIR = appdirs.user_cache_dir("pip")
|
| 14 |
+
|
| 15 |
+
# FIXME doesn't account for venv linked to global site-packages
|
| 16 |
+
site_packages: str = sysconfig.get_path("purelib")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def get_major_minor_version() -> str:
|
| 20 |
+
"""
|
| 21 |
+
Return the major-minor version of the current Python as a string, e.g.
|
| 22 |
+
"3.7" or "3.10".
|
| 23 |
+
"""
|
| 24 |
+
return "{}.{}".format(*sys.version_info)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def change_root(new_root: str, pathname: str) -> str:
|
| 28 |
+
"""Return 'pathname' with 'new_root' prepended.
|
| 29 |
+
|
| 30 |
+
If 'pathname' is relative, this is equivalent to os.path.join(new_root, pathname).
|
| 31 |
+
Otherwise, it requires making 'pathname' relative and then joining the
|
| 32 |
+
two, which is tricky on DOS/Windows and Mac OS.
|
| 33 |
+
|
| 34 |
+
This is borrowed from Python's standard library's distutils module.
|
| 35 |
+
"""
|
| 36 |
+
if os.name == "posix":
|
| 37 |
+
if not os.path.isabs(pathname):
|
| 38 |
+
return os.path.join(new_root, pathname)
|
| 39 |
+
else:
|
| 40 |
+
return os.path.join(new_root, pathname[1:])
|
| 41 |
+
|
| 42 |
+
elif os.name == "nt":
|
| 43 |
+
(drive, path) = os.path.splitdrive(pathname)
|
| 44 |
+
if path[0] == "\\":
|
| 45 |
+
path = path[1:]
|
| 46 |
+
return os.path.join(new_root, path)
|
| 47 |
+
|
| 48 |
+
else:
|
| 49 |
+
raise InstallationError(
|
| 50 |
+
f"Unknown platform: {os.name}\n"
|
| 51 |
+
"Can not change root path prefix on unknown platform."
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def get_src_prefix() -> str:
|
| 56 |
+
if running_under_virtualenv():
|
| 57 |
+
src_prefix = os.path.join(sys.prefix, "src")
|
| 58 |
+
else:
|
| 59 |
+
# FIXME: keep src in cwd for now (it is not a temporary folder)
|
| 60 |
+
try:
|
| 61 |
+
src_prefix = os.path.join(os.getcwd(), "src")
|
| 62 |
+
except OSError:
|
| 63 |
+
# In case the current working directory has been renamed or deleted
|
| 64 |
+
sys.exit("The folder you are executing pip from can no longer be found.")
|
| 65 |
+
|
| 66 |
+
# under macOS + virtualenv sys.prefix is not properly resolved
|
| 67 |
+
# it is something like /path/to/python/bin/..
|
| 68 |
+
return os.path.abspath(src_prefix)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
try:
|
| 72 |
+
# Use getusersitepackages if this is present, as it ensures that the
|
| 73 |
+
# value is initialised properly.
|
| 74 |
+
user_site: typing.Optional[str] = site.getusersitepackages()
|
| 75 |
+
except AttributeError:
|
| 76 |
+
user_site = site.USER_SITE
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
@functools.lru_cache(maxsize=None)
|
| 80 |
+
def is_osx_framework() -> bool:
|
| 81 |
+
return bool(sysconfig.get_config_var("PYTHONFRAMEWORK"))
|
vllm/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 |
+
"""
|
vllm/lib/python3.10/site-packages/pip/_internal/models/__pycache__/index.cpython-310.pyc
ADDED
|
Binary file (1.21 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/models/__pycache__/installation_report.cpython-310.pyc
ADDED
|
Binary file (1.73 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/models/candidate.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from dataclasses import dataclass
|
| 2 |
+
|
| 3 |
+
from pip._vendor.packaging.version import Version
|
| 4 |
+
from pip._vendor.packaging.version import parse as parse_version
|
| 5 |
+
|
| 6 |
+
from pip._internal.models.link import Link
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@dataclass(frozen=True)
|
| 10 |
+
class InstallationCandidate:
|
| 11 |
+
"""Represents a potential "candidate" for installation."""
|
| 12 |
+
|
| 13 |
+
__slots__ = ["name", "version", "link"]
|
| 14 |
+
|
| 15 |
+
name: str
|
| 16 |
+
version: Version
|
| 17 |
+
link: Link
|
| 18 |
+
|
| 19 |
+
def __init__(self, name: str, version: str, link: Link) -> None:
|
| 20 |
+
object.__setattr__(self, "name", name)
|
| 21 |
+
object.__setattr__(self, "version", parse_version(version))
|
| 22 |
+
object.__setattr__(self, "link", link)
|
| 23 |
+
|
| 24 |
+
def __str__(self) -> str:
|
| 25 |
+
return f"{self.name!r} candidate (version {self.version} at {self.link})"
|
vllm/lib/python3.10/site-packages/pip/_internal/models/format_control.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 f"{self.__class__.__name__}({self.no_binary}, {self.only_binary})"
|
| 37 |
+
|
| 38 |
+
@staticmethod
|
| 39 |
+
def handle_mutual_excludes(value: str, target: Set[str], other: Set[str]) -> None:
|
| 40 |
+
if value.startswith("-"):
|
| 41 |
+
raise CommandError(
|
| 42 |
+
"--no-binary / --only-binary option requires 1 argument."
|
| 43 |
+
)
|
| 44 |
+
new = value.split(",")
|
| 45 |
+
while ":all:" in new:
|
| 46 |
+
other.clear()
|
| 47 |
+
target.clear()
|
| 48 |
+
target.add(":all:")
|
| 49 |
+
del new[: new.index(":all:") + 1]
|
| 50 |
+
# Without a none, we want to discard everything as :all: covers it
|
| 51 |
+
if ":none:" not in new:
|
| 52 |
+
return
|
| 53 |
+
for name in new:
|
| 54 |
+
if name == ":none:":
|
| 55 |
+
target.clear()
|
| 56 |
+
continue
|
| 57 |
+
name = canonicalize_name(name)
|
| 58 |
+
other.discard(name)
|
| 59 |
+
target.add(name)
|
| 60 |
+
|
| 61 |
+
def get_allowed_formats(self, canonical_name: str) -> FrozenSet[str]:
|
| 62 |
+
result = {"binary", "source"}
|
| 63 |
+
if canonical_name in self.only_binary:
|
| 64 |
+
result.discard("source")
|
| 65 |
+
elif canonical_name in self.no_binary:
|
| 66 |
+
result.discard("binary")
|
| 67 |
+
elif ":all:" in self.only_binary:
|
| 68 |
+
result.discard("source")
|
| 69 |
+
elif ":all:" in self.no_binary:
|
| 70 |
+
result.discard("binary")
|
| 71 |
+
return frozenset(result)
|
| 72 |
+
|
| 73 |
+
def disallow_binaries(self) -> None:
|
| 74 |
+
self.handle_mutual_excludes(
|
| 75 |
+
":all:",
|
| 76 |
+
self.no_binary,
|
| 77 |
+
self.only_binary,
|
| 78 |
+
)
|
vllm/lib/python3.10/site-packages/pip/_internal/models/index.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import urllib.parse
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class PackageIndex:
|
| 5 |
+
"""Represents a Package Index and provides easier access to endpoints"""
|
| 6 |
+
|
| 7 |
+
__slots__ = ["url", "netloc", "simple_url", "pypi_url", "file_storage_domain"]
|
| 8 |
+
|
| 9 |
+
def __init__(self, url: str, file_storage_domain: str) -> None:
|
| 10 |
+
super().__init__()
|
| 11 |
+
self.url = url
|
| 12 |
+
self.netloc = urllib.parse.urlsplit(url).netloc
|
| 13 |
+
self.simple_url = self._url_for_path("simple")
|
| 14 |
+
self.pypi_url = self._url_for_path("pypi")
|
| 15 |
+
|
| 16 |
+
# This is part of a temporary hack used to block installs of PyPI
|
| 17 |
+
# packages which depend on external urls only necessary until PyPI can
|
| 18 |
+
# block such packages themselves
|
| 19 |
+
self.file_storage_domain = file_storage_domain
|
| 20 |
+
|
| 21 |
+
def _url_for_path(self, path: str) -> str:
|
| 22 |
+
return urllib.parse.urljoin(self.url, path)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
PyPI = PackageIndex("https://pypi.org/", file_storage_domain="files.pythonhosted.org")
|
| 26 |
+
TestPyPI = PackageIndex(
|
| 27 |
+
"https://test.pypi.org/", file_storage_domain="test-files.pythonhosted.org"
|
| 28 |
+
)
|
vllm/lib/python3.10/site-packages/pip/_internal/models/installation_report.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, Dict, Sequence
|
| 2 |
+
|
| 3 |
+
from pip._vendor.packaging.markers import default_environment
|
| 4 |
+
|
| 5 |
+
from pip import __version__
|
| 6 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class InstallationReport:
|
| 10 |
+
def __init__(self, install_requirements: Sequence[InstallRequirement]):
|
| 11 |
+
self._install_requirements = install_requirements
|
| 12 |
+
|
| 13 |
+
@classmethod
|
| 14 |
+
def _install_req_to_dict(cls, ireq: InstallRequirement) -> Dict[str, Any]:
|
| 15 |
+
assert ireq.download_info, f"No download_info for {ireq}"
|
| 16 |
+
res = {
|
| 17 |
+
# PEP 610 json for the download URL. download_info.archive_info.hashes may
|
| 18 |
+
# be absent when the requirement was installed from the wheel cache
|
| 19 |
+
# and the cache entry was populated by an older pip version that did not
|
| 20 |
+
# record origin.json.
|
| 21 |
+
"download_info": ireq.download_info.to_dict(),
|
| 22 |
+
# is_direct is true if the requirement was a direct URL reference (which
|
| 23 |
+
# includes editable requirements), and false if the requirement was
|
| 24 |
+
# downloaded from a PEP 503 index or --find-links.
|
| 25 |
+
"is_direct": ireq.is_direct,
|
| 26 |
+
# is_yanked is true if the requirement was yanked from the index, but
|
| 27 |
+
# was still selected by pip to conform to PEP 592.
|
| 28 |
+
"is_yanked": ireq.link.is_yanked if ireq.link else False,
|
| 29 |
+
# requested is true if the requirement was specified by the user (aka
|
| 30 |
+
# top level requirement), and false if it was installed as a dependency of a
|
| 31 |
+
# requirement. https://peps.python.org/pep-0376/#requested
|
| 32 |
+
"requested": ireq.user_supplied,
|
| 33 |
+
# PEP 566 json encoding for metadata
|
| 34 |
+
# https://www.python.org/dev/peps/pep-0566/#json-compatible-metadata
|
| 35 |
+
"metadata": ireq.get_dist().metadata_dict,
|
| 36 |
+
}
|
| 37 |
+
if ireq.user_supplied and ireq.extras:
|
| 38 |
+
# For top level requirements, the list of requested extras, if any.
|
| 39 |
+
res["requested_extras"] = sorted(ireq.extras)
|
| 40 |
+
return res
|
| 41 |
+
|
| 42 |
+
def to_dict(self) -> Dict[str, Any]:
|
| 43 |
+
return {
|
| 44 |
+
"version": "1",
|
| 45 |
+
"pip_version": __version__,
|
| 46 |
+
"install": [
|
| 47 |
+
self._install_req_to_dict(ireq) for ireq in self._install_requirements
|
| 48 |
+
],
|
| 49 |
+
# https://peps.python.org/pep-0508/#environment-markers
|
| 50 |
+
# TODO: currently, the resolver uses the default environment to evaluate
|
| 51 |
+
# environment markers, so that is what we report here. In the future, it
|
| 52 |
+
# should also take into account options such as --python-version or
|
| 53 |
+
# --platform, perhaps under the form of an environment_override field?
|
| 54 |
+
# https://github.com/pypa/pip/issues/11198
|
| 55 |
+
"environment": default_environment(),
|
| 56 |
+
}
|
vllm/lib/python3.10/site-packages/pip/_internal/models/scheme.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
For types associated with installation schemes.
|
| 3 |
+
|
| 4 |
+
For a general overview of available schemes and their context, see
|
| 5 |
+
https://docs.python.org/3/install/index.html#alternate-installation.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
|
| 10 |
+
SCHEME_KEYS = ["platlib", "purelib", "headers", "scripts", "data"]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@dataclass(frozen=True)
|
| 14 |
+
class Scheme:
|
| 15 |
+
"""A Scheme holds paths which are used as the base directories for
|
| 16 |
+
artifacts associated with a Python package.
|
| 17 |
+
"""
|
| 18 |
+
|
| 19 |
+
__slots__ = SCHEME_KEYS
|
| 20 |
+
|
| 21 |
+
platlib: str
|
| 22 |
+
purelib: str
|
| 23 |
+
headers: str
|
| 24 |
+
scripts: str
|
| 25 |
+
data: str
|
vllm/lib/python3.10/site-packages/pip/_internal/models/search_scope.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import itertools
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
import posixpath
|
| 5 |
+
import urllib.parse
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
from typing import List
|
| 8 |
+
|
| 9 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 10 |
+
|
| 11 |
+
from pip._internal.models.index import PyPI
|
| 12 |
+
from pip._internal.utils.compat import has_tls
|
| 13 |
+
from pip._internal.utils.misc import normalize_path, redact_auth_from_url
|
| 14 |
+
|
| 15 |
+
logger = logging.getLogger(__name__)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
@dataclass(frozen=True)
|
| 19 |
+
class SearchScope:
|
| 20 |
+
"""
|
| 21 |
+
Encapsulates the locations that pip is configured to search.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
__slots__ = ["find_links", "index_urls", "no_index"]
|
| 25 |
+
|
| 26 |
+
find_links: List[str]
|
| 27 |
+
index_urls: List[str]
|
| 28 |
+
no_index: bool
|
| 29 |
+
|
| 30 |
+
@classmethod
|
| 31 |
+
def create(
|
| 32 |
+
cls,
|
| 33 |
+
find_links: List[str],
|
| 34 |
+
index_urls: List[str],
|
| 35 |
+
no_index: bool,
|
| 36 |
+
) -> "SearchScope":
|
| 37 |
+
"""
|
| 38 |
+
Create a SearchScope object after normalizing the `find_links`.
|
| 39 |
+
"""
|
| 40 |
+
# Build find_links. If an argument starts with ~, it may be
|
| 41 |
+
# a local file relative to a home directory. So try normalizing
|
| 42 |
+
# it and if it exists, use the normalized version.
|
| 43 |
+
# This is deliberately conservative - it might be fine just to
|
| 44 |
+
# blindly normalize anything starting with a ~...
|
| 45 |
+
built_find_links: List[str] = []
|
| 46 |
+
for link in find_links:
|
| 47 |
+
if link.startswith("~"):
|
| 48 |
+
new_link = normalize_path(link)
|
| 49 |
+
if os.path.exists(new_link):
|
| 50 |
+
link = new_link
|
| 51 |
+
built_find_links.append(link)
|
| 52 |
+
|
| 53 |
+
# If we don't have TLS enabled, then WARN if anyplace we're looking
|
| 54 |
+
# relies on TLS.
|
| 55 |
+
if not has_tls():
|
| 56 |
+
for link in itertools.chain(index_urls, built_find_links):
|
| 57 |
+
parsed = urllib.parse.urlparse(link)
|
| 58 |
+
if parsed.scheme == "https":
|
| 59 |
+
logger.warning(
|
| 60 |
+
"pip is configured with locations that require "
|
| 61 |
+
"TLS/SSL, however the ssl module in Python is not "
|
| 62 |
+
"available."
|
| 63 |
+
)
|
| 64 |
+
break
|
| 65 |
+
|
| 66 |
+
return cls(
|
| 67 |
+
find_links=built_find_links,
|
| 68 |
+
index_urls=index_urls,
|
| 69 |
+
no_index=no_index,
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
def get_formatted_locations(self) -> str:
|
| 73 |
+
lines = []
|
| 74 |
+
redacted_index_urls = []
|
| 75 |
+
if self.index_urls and self.index_urls != [PyPI.simple_url]:
|
| 76 |
+
for url in self.index_urls:
|
| 77 |
+
redacted_index_url = redact_auth_from_url(url)
|
| 78 |
+
|
| 79 |
+
# Parse the URL
|
| 80 |
+
purl = urllib.parse.urlsplit(redacted_index_url)
|
| 81 |
+
|
| 82 |
+
# URL is generally invalid if scheme and netloc is missing
|
| 83 |
+
# there are issues with Python and URL parsing, so this test
|
| 84 |
+
# is a bit crude. See bpo-20271, bpo-23505. Python doesn't
|
| 85 |
+
# always parse invalid URLs correctly - it should raise
|
| 86 |
+
# exceptions for malformed URLs
|
| 87 |
+
if not purl.scheme and not purl.netloc:
|
| 88 |
+
logger.warning(
|
| 89 |
+
'The index url "%s" seems invalid, please provide a scheme.',
|
| 90 |
+
redacted_index_url,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
redacted_index_urls.append(redacted_index_url)
|
| 94 |
+
|
| 95 |
+
lines.append(
|
| 96 |
+
"Looking in indexes: {}".format(", ".join(redacted_index_urls))
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
if self.find_links:
|
| 100 |
+
lines.append(
|
| 101 |
+
"Looking in links: {}".format(
|
| 102 |
+
", ".join(redact_auth_from_url(url) for url in self.find_links)
|
| 103 |
+
)
|
| 104 |
+
)
|
| 105 |
+
return "\n".join(lines)
|
| 106 |
+
|
| 107 |
+
def get_index_urls_locations(self, project_name: str) -> List[str]:
|
| 108 |
+
"""Returns the locations found via self.index_urls
|
| 109 |
+
|
| 110 |
+
Checks the url_name on the main (first in the list) index and
|
| 111 |
+
use this url_name to produce all locations
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
def mkurl_pypi_url(url: str) -> str:
|
| 115 |
+
loc = posixpath.join(
|
| 116 |
+
url, urllib.parse.quote(canonicalize_name(project_name))
|
| 117 |
+
)
|
| 118 |
+
# For maximum compatibility with easy_install, ensure the path
|
| 119 |
+
# ends in a trailing slash. Although this isn't in the spec
|
| 120 |
+
# (and PyPI can handle it without the slash) some other index
|
| 121 |
+
# implementations might break if they relied on easy_install's
|
| 122 |
+
# behavior.
|
| 123 |
+
if not loc.endswith("/"):
|
| 124 |
+
loc = loc + "/"
|
| 125 |
+
return loc
|
| 126 |
+
|
| 127 |
+
return [mkurl_pypi_url(url) for url in self.index_urls]
|
vllm/lib/python3.10/site-packages/pip/_internal/models/selection_prefs.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
|
| 3 |
+
from pip._internal.models.format_control import FormatControl
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# TODO: This needs Python 3.10's improved slots support for dataclasses
|
| 7 |
+
# to be converted into a dataclass.
|
| 8 |
+
class SelectionPreferences:
|
| 9 |
+
"""
|
| 10 |
+
Encapsulates the candidate selection preferences for downloading
|
| 11 |
+
and installing files.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
__slots__ = [
|
| 15 |
+
"allow_yanked",
|
| 16 |
+
"allow_all_prereleases",
|
| 17 |
+
"format_control",
|
| 18 |
+
"prefer_binary",
|
| 19 |
+
"ignore_requires_python",
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
# Don't include an allow_yanked default value to make sure each call
|
| 23 |
+
# site considers whether yanked releases are allowed. This also causes
|
| 24 |
+
# that decision to be made explicit in the calling code, which helps
|
| 25 |
+
# people when reading the code.
|
| 26 |
+
def __init__(
|
| 27 |
+
self,
|
| 28 |
+
allow_yanked: bool,
|
| 29 |
+
allow_all_prereleases: bool = False,
|
| 30 |
+
format_control: Optional[FormatControl] = None,
|
| 31 |
+
prefer_binary: bool = False,
|
| 32 |
+
ignore_requires_python: Optional[bool] = None,
|
| 33 |
+
) -> None:
|
| 34 |
+
"""Create a SelectionPreferences object.
|
| 35 |
+
|
| 36 |
+
:param allow_yanked: Whether files marked as yanked (in the sense
|
| 37 |
+
of PEP 592) are permitted to be candidates for install.
|
| 38 |
+
:param format_control: A FormatControl object or None. Used to control
|
| 39 |
+
the selection of source packages / binary packages when consulting
|
| 40 |
+
the index and links.
|
| 41 |
+
:param prefer_binary: Whether to prefer an old, but valid, binary
|
| 42 |
+
dist over a new source dist.
|
| 43 |
+
:param ignore_requires_python: Whether to ignore incompatible
|
| 44 |
+
"Requires-Python" values in links. Defaults to False.
|
| 45 |
+
"""
|
| 46 |
+
if ignore_requires_python is None:
|
| 47 |
+
ignore_requires_python = False
|
| 48 |
+
|
| 49 |
+
self.allow_yanked = allow_yanked
|
| 50 |
+
self.allow_all_prereleases = allow_all_prereleases
|
| 51 |
+
self.format_control = format_control
|
| 52 |
+
self.prefer_binary = prefer_binary
|
| 53 |
+
self.ignore_requires_python = ignore_requires_python
|
vllm/lib/python3.10/site-packages/pip/_internal/models/wheel.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Represents a wheel file and provides access to the various parts of the
|
| 2 |
+
name that have meaning.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import re
|
| 6 |
+
from typing import Dict, Iterable, List
|
| 7 |
+
|
| 8 |
+
from pip._vendor.packaging.tags import Tag
|
| 9 |
+
from pip._vendor.packaging.utils import (
|
| 10 |
+
InvalidWheelFilename as PackagingInvalidWheelName,
|
| 11 |
+
)
|
| 12 |
+
from pip._vendor.packaging.utils import parse_wheel_filename
|
| 13 |
+
|
| 14 |
+
from pip._internal.exceptions import InvalidWheelFilename
|
| 15 |
+
from pip._internal.utils.deprecation import deprecated
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class Wheel:
|
| 19 |
+
"""A wheel file"""
|
| 20 |
+
|
| 21 |
+
wheel_file_re = re.compile(
|
| 22 |
+
r"""^(?P<namever>(?P<name>[^\s-]+?)-(?P<ver>[^\s-]*?))
|
| 23 |
+
((-(?P<build>\d[^-]*?))?-(?P<pyver>[^\s-]+?)-(?P<abi>[^\s-]+?)-(?P<plat>[^\s-]+?)
|
| 24 |
+
\.whl|\.dist-info)$""",
|
| 25 |
+
re.VERBOSE,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
def __init__(self, filename: str) -> None:
|
| 29 |
+
"""
|
| 30 |
+
:raises InvalidWheelFilename: when the filename is invalid for a wheel
|
| 31 |
+
"""
|
| 32 |
+
wheel_info = self.wheel_file_re.match(filename)
|
| 33 |
+
if not wheel_info:
|
| 34 |
+
raise InvalidWheelFilename(f"{filename} is not a valid wheel filename.")
|
| 35 |
+
self.filename = filename
|
| 36 |
+
self.name = wheel_info.group("name").replace("_", "-")
|
| 37 |
+
_version = wheel_info.group("ver")
|
| 38 |
+
if "_" in _version:
|
| 39 |
+
try:
|
| 40 |
+
parse_wheel_filename(filename)
|
| 41 |
+
except PackagingInvalidWheelName as e:
|
| 42 |
+
deprecated(
|
| 43 |
+
reason=(
|
| 44 |
+
f"Wheel filename {filename!r} is not correctly normalised. "
|
| 45 |
+
"Future versions of pip will raise the following error:\n"
|
| 46 |
+
f"{e.args[0]}\n\n"
|
| 47 |
+
),
|
| 48 |
+
replacement=(
|
| 49 |
+
"to rename the wheel to use a correctly normalised "
|
| 50 |
+
"name (this may require updating the version in "
|
| 51 |
+
"the project metadata)"
|
| 52 |
+
),
|
| 53 |
+
gone_in="25.1",
|
| 54 |
+
issue=12938,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
_version = _version.replace("_", "-")
|
| 58 |
+
|
| 59 |
+
self.version = _version
|
| 60 |
+
self.build_tag = wheel_info.group("build")
|
| 61 |
+
self.pyversions = wheel_info.group("pyver").split(".")
|
| 62 |
+
self.abis = wheel_info.group("abi").split(".")
|
| 63 |
+
self.plats = wheel_info.group("plat").split(".")
|
| 64 |
+
|
| 65 |
+
# All the tag combinations from this file
|
| 66 |
+
self.file_tags = {
|
| 67 |
+
Tag(x, y, z) for x in self.pyversions for y in self.abis for z in self.plats
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
def get_formatted_file_tags(self) -> List[str]:
|
| 71 |
+
"""Return the wheel's tags as a sorted list of strings."""
|
| 72 |
+
return sorted(str(tag) for tag in self.file_tags)
|
| 73 |
+
|
| 74 |
+
def support_index_min(self, tags: List[Tag]) -> int:
|
| 75 |
+
"""Return the lowest index that one of the wheel's file_tag combinations
|
| 76 |
+
achieves in the given list of supported tags.
|
| 77 |
+
|
| 78 |
+
For example, if there are 8 supported tags and one of the file tags
|
| 79 |
+
is first in the list, then return 0.
|
| 80 |
+
|
| 81 |
+
:param tags: the PEP 425 tags to check the wheel against, in order
|
| 82 |
+
with most preferred first.
|
| 83 |
+
|
| 84 |
+
:raises ValueError: If none of the wheel's file tags match one of
|
| 85 |
+
the supported tags.
|
| 86 |
+
"""
|
| 87 |
+
try:
|
| 88 |
+
return next(i for i, t in enumerate(tags) if t in self.file_tags)
|
| 89 |
+
except StopIteration:
|
| 90 |
+
raise ValueError()
|
| 91 |
+
|
| 92 |
+
def find_most_preferred_tag(
|
| 93 |
+
self, tags: List[Tag], tag_to_priority: Dict[Tag, int]
|
| 94 |
+
) -> int:
|
| 95 |
+
"""Return the priority of the most preferred tag that one of the wheel's file
|
| 96 |
+
tag combinations achieves in the given list of supported tags using the given
|
| 97 |
+
tag_to_priority mapping, where lower priorities are more-preferred.
|
| 98 |
+
|
| 99 |
+
This is used in place of support_index_min in some cases in order to avoid
|
| 100 |
+
an expensive linear scan of a large list of tags.
|
| 101 |
+
|
| 102 |
+
:param tags: the PEP 425 tags to check the wheel against.
|
| 103 |
+
:param tag_to_priority: a mapping from tag to priority of that tag, where
|
| 104 |
+
lower is more preferred.
|
| 105 |
+
|
| 106 |
+
:raises ValueError: If none of the wheel's file tags match one of
|
| 107 |
+
the supported tags.
|
| 108 |
+
"""
|
| 109 |
+
return min(
|
| 110 |
+
tag_to_priority[tag] for tag in self.file_tags if tag in tag_to_priority
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
def supported(self, tags: Iterable[Tag]) -> bool:
|
| 114 |
+
"""Return whether the wheel is compatible with one of the given tags.
|
| 115 |
+
|
| 116 |
+
:param tags: the PEP 425 tags to check the wheel against.
|
| 117 |
+
"""
|
| 118 |
+
return not self.file_tags.isdisjoint(tags)
|
vllm/lib/python3.10/site-packages/pip/_internal/network/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contains purely network-related utilities.
|
| 2 |
+
"""
|
vllm/lib/python3.10/site-packages/pip/_internal/network/__pycache__/lazy_wheel.cpython-310.pyc
ADDED
|
Binary file (8.39 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/network/auth.py
ADDED
|
@@ -0,0 +1,566 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Network Authentication Helpers
|
| 2 |
+
|
| 3 |
+
Contains interface (MultiDomainBasicAuth) and associated glue code for
|
| 4 |
+
providing credentials in the context of network requests.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
import shutil
|
| 10 |
+
import subprocess
|
| 11 |
+
import sysconfig
|
| 12 |
+
import typing
|
| 13 |
+
import urllib.parse
|
| 14 |
+
from abc import ABC, abstractmethod
|
| 15 |
+
from functools import lru_cache
|
| 16 |
+
from os.path import commonprefix
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
from typing import Any, Dict, List, NamedTuple, Optional, Tuple
|
| 19 |
+
|
| 20 |
+
from pip._vendor.requests.auth import AuthBase, HTTPBasicAuth
|
| 21 |
+
from pip._vendor.requests.models import Request, Response
|
| 22 |
+
from pip._vendor.requests.utils import get_netrc_auth
|
| 23 |
+
|
| 24 |
+
from pip._internal.utils.logging import getLogger
|
| 25 |
+
from pip._internal.utils.misc import (
|
| 26 |
+
ask,
|
| 27 |
+
ask_input,
|
| 28 |
+
ask_password,
|
| 29 |
+
remove_auth_from_url,
|
| 30 |
+
split_auth_netloc_from_url,
|
| 31 |
+
)
|
| 32 |
+
from pip._internal.vcs.versioncontrol import AuthInfo
|
| 33 |
+
|
| 34 |
+
logger = getLogger(__name__)
|
| 35 |
+
|
| 36 |
+
KEYRING_DISABLED = False
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class Credentials(NamedTuple):
|
| 40 |
+
url: str
|
| 41 |
+
username: str
|
| 42 |
+
password: str
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class KeyRingBaseProvider(ABC):
|
| 46 |
+
"""Keyring base provider interface"""
|
| 47 |
+
|
| 48 |
+
has_keyring: bool
|
| 49 |
+
|
| 50 |
+
@abstractmethod
|
| 51 |
+
def get_auth_info(
|
| 52 |
+
self, url: str, username: Optional[str]
|
| 53 |
+
) -> Optional[AuthInfo]: ...
|
| 54 |
+
|
| 55 |
+
@abstractmethod
|
| 56 |
+
def save_auth_info(self, url: str, username: str, password: str) -> None: ...
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class KeyRingNullProvider(KeyRingBaseProvider):
|
| 60 |
+
"""Keyring null provider"""
|
| 61 |
+
|
| 62 |
+
has_keyring = False
|
| 63 |
+
|
| 64 |
+
def get_auth_info(self, url: str, username: Optional[str]) -> Optional[AuthInfo]:
|
| 65 |
+
return None
|
| 66 |
+
|
| 67 |
+
def save_auth_info(self, url: str, username: str, password: str) -> None:
|
| 68 |
+
return None
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class KeyRingPythonProvider(KeyRingBaseProvider):
|
| 72 |
+
"""Keyring interface which uses locally imported `keyring`"""
|
| 73 |
+
|
| 74 |
+
has_keyring = True
|
| 75 |
+
|
| 76 |
+
def __init__(self) -> None:
|
| 77 |
+
import keyring
|
| 78 |
+
|
| 79 |
+
self.keyring = keyring
|
| 80 |
+
|
| 81 |
+
def get_auth_info(self, url: str, username: Optional[str]) -> Optional[AuthInfo]:
|
| 82 |
+
# Support keyring's get_credential interface which supports getting
|
| 83 |
+
# credentials without a username. This is only available for
|
| 84 |
+
# keyring>=15.2.0.
|
| 85 |
+
if hasattr(self.keyring, "get_credential"):
|
| 86 |
+
logger.debug("Getting credentials from keyring for %s", url)
|
| 87 |
+
cred = self.keyring.get_credential(url, username)
|
| 88 |
+
if cred is not None:
|
| 89 |
+
return cred.username, cred.password
|
| 90 |
+
return None
|
| 91 |
+
|
| 92 |
+
if username is not None:
|
| 93 |
+
logger.debug("Getting password from keyring for %s", url)
|
| 94 |
+
password = self.keyring.get_password(url, username)
|
| 95 |
+
if password:
|
| 96 |
+
return username, password
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
def save_auth_info(self, url: str, username: str, password: str) -> None:
|
| 100 |
+
self.keyring.set_password(url, username, password)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
class KeyRingCliProvider(KeyRingBaseProvider):
|
| 104 |
+
"""Provider which uses `keyring` cli
|
| 105 |
+
|
| 106 |
+
Instead of calling the keyring package installed alongside pip
|
| 107 |
+
we call keyring on the command line which will enable pip to
|
| 108 |
+
use which ever installation of keyring is available first in
|
| 109 |
+
PATH.
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
has_keyring = True
|
| 113 |
+
|
| 114 |
+
def __init__(self, cmd: str) -> None:
|
| 115 |
+
self.keyring = cmd
|
| 116 |
+
|
| 117 |
+
def get_auth_info(self, url: str, username: Optional[str]) -> Optional[AuthInfo]:
|
| 118 |
+
# This is the default implementation of keyring.get_credential
|
| 119 |
+
# https://github.com/jaraco/keyring/blob/97689324abcf01bd1793d49063e7ca01e03d7d07/keyring/backend.py#L134-L139
|
| 120 |
+
if username is not None:
|
| 121 |
+
password = self._get_password(url, username)
|
| 122 |
+
if password is not None:
|
| 123 |
+
return username, password
|
| 124 |
+
return None
|
| 125 |
+
|
| 126 |
+
def save_auth_info(self, url: str, username: str, password: str) -> None:
|
| 127 |
+
return self._set_password(url, username, password)
|
| 128 |
+
|
| 129 |
+
def _get_password(self, service_name: str, username: str) -> Optional[str]:
|
| 130 |
+
"""Mirror the implementation of keyring.get_password using cli"""
|
| 131 |
+
if self.keyring is None:
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
cmd = [self.keyring, "get", service_name, username]
|
| 135 |
+
env = os.environ.copy()
|
| 136 |
+
env["PYTHONIOENCODING"] = "utf-8"
|
| 137 |
+
res = subprocess.run(
|
| 138 |
+
cmd,
|
| 139 |
+
stdin=subprocess.DEVNULL,
|
| 140 |
+
stdout=subprocess.PIPE,
|
| 141 |
+
env=env,
|
| 142 |
+
)
|
| 143 |
+
if res.returncode:
|
| 144 |
+
return None
|
| 145 |
+
return res.stdout.decode("utf-8").strip(os.linesep)
|
| 146 |
+
|
| 147 |
+
def _set_password(self, service_name: str, username: str, password: str) -> None:
|
| 148 |
+
"""Mirror the implementation of keyring.set_password using cli"""
|
| 149 |
+
if self.keyring is None:
|
| 150 |
+
return None
|
| 151 |
+
env = os.environ.copy()
|
| 152 |
+
env["PYTHONIOENCODING"] = "utf-8"
|
| 153 |
+
subprocess.run(
|
| 154 |
+
[self.keyring, "set", service_name, username],
|
| 155 |
+
input=f"{password}{os.linesep}".encode(),
|
| 156 |
+
env=env,
|
| 157 |
+
check=True,
|
| 158 |
+
)
|
| 159 |
+
return None
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
@lru_cache(maxsize=None)
|
| 163 |
+
def get_keyring_provider(provider: str) -> KeyRingBaseProvider:
|
| 164 |
+
logger.verbose("Keyring provider requested: %s", provider)
|
| 165 |
+
|
| 166 |
+
# keyring has previously failed and been disabled
|
| 167 |
+
if KEYRING_DISABLED:
|
| 168 |
+
provider = "disabled"
|
| 169 |
+
if provider in ["import", "auto"]:
|
| 170 |
+
try:
|
| 171 |
+
impl = KeyRingPythonProvider()
|
| 172 |
+
logger.verbose("Keyring provider set: import")
|
| 173 |
+
return impl
|
| 174 |
+
except ImportError:
|
| 175 |
+
pass
|
| 176 |
+
except Exception as exc:
|
| 177 |
+
# In the event of an unexpected exception
|
| 178 |
+
# we should warn the user
|
| 179 |
+
msg = "Installed copy of keyring fails with exception %s"
|
| 180 |
+
if provider == "auto":
|
| 181 |
+
msg = msg + ", trying to find a keyring executable as a fallback"
|
| 182 |
+
logger.warning(msg, exc, exc_info=logger.isEnabledFor(logging.DEBUG))
|
| 183 |
+
if provider in ["subprocess", "auto"]:
|
| 184 |
+
cli = shutil.which("keyring")
|
| 185 |
+
if cli and cli.startswith(sysconfig.get_path("scripts")):
|
| 186 |
+
# all code within this function is stolen from shutil.which implementation
|
| 187 |
+
@typing.no_type_check
|
| 188 |
+
def PATH_as_shutil_which_determines_it() -> str:
|
| 189 |
+
path = os.environ.get("PATH", None)
|
| 190 |
+
if path is None:
|
| 191 |
+
try:
|
| 192 |
+
path = os.confstr("CS_PATH")
|
| 193 |
+
except (AttributeError, ValueError):
|
| 194 |
+
# os.confstr() or CS_PATH is not available
|
| 195 |
+
path = os.defpath
|
| 196 |
+
# bpo-35755: Don't use os.defpath if the PATH environment variable is
|
| 197 |
+
# set to an empty string
|
| 198 |
+
|
| 199 |
+
return path
|
| 200 |
+
|
| 201 |
+
scripts = Path(sysconfig.get_path("scripts"))
|
| 202 |
+
|
| 203 |
+
paths = []
|
| 204 |
+
for path in PATH_as_shutil_which_determines_it().split(os.pathsep):
|
| 205 |
+
p = Path(path)
|
| 206 |
+
try:
|
| 207 |
+
if not p.samefile(scripts):
|
| 208 |
+
paths.append(path)
|
| 209 |
+
except FileNotFoundError:
|
| 210 |
+
pass
|
| 211 |
+
|
| 212 |
+
path = os.pathsep.join(paths)
|
| 213 |
+
|
| 214 |
+
cli = shutil.which("keyring", path=path)
|
| 215 |
+
|
| 216 |
+
if cli:
|
| 217 |
+
logger.verbose("Keyring provider set: subprocess with executable %s", cli)
|
| 218 |
+
return KeyRingCliProvider(cli)
|
| 219 |
+
|
| 220 |
+
logger.verbose("Keyring provider set: disabled")
|
| 221 |
+
return KeyRingNullProvider()
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
class MultiDomainBasicAuth(AuthBase):
|
| 225 |
+
def __init__(
|
| 226 |
+
self,
|
| 227 |
+
prompting: bool = True,
|
| 228 |
+
index_urls: Optional[List[str]] = None,
|
| 229 |
+
keyring_provider: str = "auto",
|
| 230 |
+
) -> None:
|
| 231 |
+
self.prompting = prompting
|
| 232 |
+
self.index_urls = index_urls
|
| 233 |
+
self.keyring_provider = keyring_provider # type: ignore[assignment]
|
| 234 |
+
self.passwords: Dict[str, AuthInfo] = {}
|
| 235 |
+
# When the user is prompted to enter credentials and keyring is
|
| 236 |
+
# available, we will offer to save them. If the user accepts,
|
| 237 |
+
# this value is set to the credentials they entered. After the
|
| 238 |
+
# request authenticates, the caller should call
|
| 239 |
+
# ``save_credentials`` to save these.
|
| 240 |
+
self._credentials_to_save: Optional[Credentials] = None
|
| 241 |
+
|
| 242 |
+
@property
|
| 243 |
+
def keyring_provider(self) -> KeyRingBaseProvider:
|
| 244 |
+
return get_keyring_provider(self._keyring_provider)
|
| 245 |
+
|
| 246 |
+
@keyring_provider.setter
|
| 247 |
+
def keyring_provider(self, provider: str) -> None:
|
| 248 |
+
# The free function get_keyring_provider has been decorated with
|
| 249 |
+
# functools.cache. If an exception occurs in get_keyring_auth that
|
| 250 |
+
# cache will be cleared and keyring disabled, take that into account
|
| 251 |
+
# if you want to remove this indirection.
|
| 252 |
+
self._keyring_provider = provider
|
| 253 |
+
|
| 254 |
+
@property
|
| 255 |
+
def use_keyring(self) -> bool:
|
| 256 |
+
# We won't use keyring when --no-input is passed unless
|
| 257 |
+
# a specific provider is requested because it might require
|
| 258 |
+
# user interaction
|
| 259 |
+
return self.prompting or self._keyring_provider not in ["auto", "disabled"]
|
| 260 |
+
|
| 261 |
+
def _get_keyring_auth(
|
| 262 |
+
self,
|
| 263 |
+
url: Optional[str],
|
| 264 |
+
username: Optional[str],
|
| 265 |
+
) -> Optional[AuthInfo]:
|
| 266 |
+
"""Return the tuple auth for a given url from keyring."""
|
| 267 |
+
# Do nothing if no url was provided
|
| 268 |
+
if not url:
|
| 269 |
+
return None
|
| 270 |
+
|
| 271 |
+
try:
|
| 272 |
+
return self.keyring_provider.get_auth_info(url, username)
|
| 273 |
+
except Exception as exc:
|
| 274 |
+
# Log the full exception (with stacktrace) at debug, so it'll only
|
| 275 |
+
# show up when running in verbose mode.
|
| 276 |
+
logger.debug("Keyring is skipped due to an exception", exc_info=True)
|
| 277 |
+
# Always log a shortened version of the exception.
|
| 278 |
+
logger.warning(
|
| 279 |
+
"Keyring is skipped due to an exception: %s",
|
| 280 |
+
str(exc),
|
| 281 |
+
)
|
| 282 |
+
global KEYRING_DISABLED
|
| 283 |
+
KEYRING_DISABLED = True
|
| 284 |
+
get_keyring_provider.cache_clear()
|
| 285 |
+
return None
|
| 286 |
+
|
| 287 |
+
def _get_index_url(self, url: str) -> Optional[str]:
|
| 288 |
+
"""Return the original index URL matching the requested URL.
|
| 289 |
+
|
| 290 |
+
Cached or dynamically generated credentials may work against
|
| 291 |
+
the original index URL rather than just the netloc.
|
| 292 |
+
|
| 293 |
+
The provided url should have had its username and password
|
| 294 |
+
removed already. If the original index url had credentials then
|
| 295 |
+
they will be included in the return value.
|
| 296 |
+
|
| 297 |
+
Returns None if no matching index was found, or if --no-index
|
| 298 |
+
was specified by the user.
|
| 299 |
+
"""
|
| 300 |
+
if not url or not self.index_urls:
|
| 301 |
+
return None
|
| 302 |
+
|
| 303 |
+
url = remove_auth_from_url(url).rstrip("/") + "/"
|
| 304 |
+
parsed_url = urllib.parse.urlsplit(url)
|
| 305 |
+
|
| 306 |
+
candidates = []
|
| 307 |
+
|
| 308 |
+
for index in self.index_urls:
|
| 309 |
+
index = index.rstrip("/") + "/"
|
| 310 |
+
parsed_index = urllib.parse.urlsplit(remove_auth_from_url(index))
|
| 311 |
+
if parsed_url == parsed_index:
|
| 312 |
+
return index
|
| 313 |
+
|
| 314 |
+
if parsed_url.netloc != parsed_index.netloc:
|
| 315 |
+
continue
|
| 316 |
+
|
| 317 |
+
candidate = urllib.parse.urlsplit(index)
|
| 318 |
+
candidates.append(candidate)
|
| 319 |
+
|
| 320 |
+
if not candidates:
|
| 321 |
+
return None
|
| 322 |
+
|
| 323 |
+
candidates.sort(
|
| 324 |
+
reverse=True,
|
| 325 |
+
key=lambda candidate: commonprefix(
|
| 326 |
+
[
|
| 327 |
+
parsed_url.path,
|
| 328 |
+
candidate.path,
|
| 329 |
+
]
|
| 330 |
+
).rfind("/"),
|
| 331 |
+
)
|
| 332 |
+
|
| 333 |
+
return urllib.parse.urlunsplit(candidates[0])
|
| 334 |
+
|
| 335 |
+
def _get_new_credentials(
|
| 336 |
+
self,
|
| 337 |
+
original_url: str,
|
| 338 |
+
*,
|
| 339 |
+
allow_netrc: bool = True,
|
| 340 |
+
allow_keyring: bool = False,
|
| 341 |
+
) -> AuthInfo:
|
| 342 |
+
"""Find and return credentials for the specified URL."""
|
| 343 |
+
# Split the credentials and netloc from the url.
|
| 344 |
+
url, netloc, url_user_password = split_auth_netloc_from_url(
|
| 345 |
+
original_url,
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
# Start with the credentials embedded in the url
|
| 349 |
+
username, password = url_user_password
|
| 350 |
+
if username is not None and password is not None:
|
| 351 |
+
logger.debug("Found credentials in url for %s", netloc)
|
| 352 |
+
return url_user_password
|
| 353 |
+
|
| 354 |
+
# Find a matching index url for this request
|
| 355 |
+
index_url = self._get_index_url(url)
|
| 356 |
+
if index_url:
|
| 357 |
+
# Split the credentials from the url.
|
| 358 |
+
index_info = split_auth_netloc_from_url(index_url)
|
| 359 |
+
if index_info:
|
| 360 |
+
index_url, _, index_url_user_password = index_info
|
| 361 |
+
logger.debug("Found index url %s", index_url)
|
| 362 |
+
|
| 363 |
+
# If an index URL was found, try its embedded credentials
|
| 364 |
+
if index_url and index_url_user_password[0] is not None:
|
| 365 |
+
username, password = index_url_user_password
|
| 366 |
+
if username is not None and password is not None:
|
| 367 |
+
logger.debug("Found credentials in index url for %s", netloc)
|
| 368 |
+
return index_url_user_password
|
| 369 |
+
|
| 370 |
+
# Get creds from netrc if we still don't have them
|
| 371 |
+
if allow_netrc:
|
| 372 |
+
netrc_auth = get_netrc_auth(original_url)
|
| 373 |
+
if netrc_auth:
|
| 374 |
+
logger.debug("Found credentials in netrc for %s", netloc)
|
| 375 |
+
return netrc_auth
|
| 376 |
+
|
| 377 |
+
# If we don't have a password and keyring is available, use it.
|
| 378 |
+
if allow_keyring:
|
| 379 |
+
# The index url is more specific than the netloc, so try it first
|
| 380 |
+
# fmt: off
|
| 381 |
+
kr_auth = (
|
| 382 |
+
self._get_keyring_auth(index_url, username) or
|
| 383 |
+
self._get_keyring_auth(netloc, username)
|
| 384 |
+
)
|
| 385 |
+
# fmt: on
|
| 386 |
+
if kr_auth:
|
| 387 |
+
logger.debug("Found credentials in keyring for %s", netloc)
|
| 388 |
+
return kr_auth
|
| 389 |
+
|
| 390 |
+
return username, password
|
| 391 |
+
|
| 392 |
+
def _get_url_and_credentials(
|
| 393 |
+
self, original_url: str
|
| 394 |
+
) -> Tuple[str, Optional[str], Optional[str]]:
|
| 395 |
+
"""Return the credentials to use for the provided URL.
|
| 396 |
+
|
| 397 |
+
If allowed, netrc and keyring may be used to obtain the
|
| 398 |
+
correct credentials.
|
| 399 |
+
|
| 400 |
+
Returns (url_without_credentials, username, password). Note
|
| 401 |
+
that even if the original URL contains credentials, this
|
| 402 |
+
function may return a different username and password.
|
| 403 |
+
"""
|
| 404 |
+
url, netloc, _ = split_auth_netloc_from_url(original_url)
|
| 405 |
+
|
| 406 |
+
# Try to get credentials from original url
|
| 407 |
+
username, password = self._get_new_credentials(original_url)
|
| 408 |
+
|
| 409 |
+
# If credentials not found, use any stored credentials for this netloc.
|
| 410 |
+
# Do this if either the username or the password is missing.
|
| 411 |
+
# This accounts for the situation in which the user has specified
|
| 412 |
+
# the username in the index url, but the password comes from keyring.
|
| 413 |
+
if (username is None or password is None) and netloc in self.passwords:
|
| 414 |
+
un, pw = self.passwords[netloc]
|
| 415 |
+
# It is possible that the cached credentials are for a different username,
|
| 416 |
+
# in which case the cache should be ignored.
|
| 417 |
+
if username is None or username == un:
|
| 418 |
+
username, password = un, pw
|
| 419 |
+
|
| 420 |
+
if username is not None or password is not None:
|
| 421 |
+
# Convert the username and password if they're None, so that
|
| 422 |
+
# this netloc will show up as "cached" in the conditional above.
|
| 423 |
+
# Further, HTTPBasicAuth doesn't accept None, so it makes sense to
|
| 424 |
+
# cache the value that is going to be used.
|
| 425 |
+
username = username or ""
|
| 426 |
+
password = password or ""
|
| 427 |
+
|
| 428 |
+
# Store any acquired credentials.
|
| 429 |
+
self.passwords[netloc] = (username, password)
|
| 430 |
+
|
| 431 |
+
assert (
|
| 432 |
+
# Credentials were found
|
| 433 |
+
(username is not None and password is not None)
|
| 434 |
+
# Credentials were not found
|
| 435 |
+
or (username is None and password is None)
|
| 436 |
+
), f"Could not load credentials from url: {original_url}"
|
| 437 |
+
|
| 438 |
+
return url, username, password
|
| 439 |
+
|
| 440 |
+
def __call__(self, req: Request) -> Request:
|
| 441 |
+
# Get credentials for this request
|
| 442 |
+
url, username, password = self._get_url_and_credentials(req.url)
|
| 443 |
+
|
| 444 |
+
# Set the url of the request to the url without any credentials
|
| 445 |
+
req.url = url
|
| 446 |
+
|
| 447 |
+
if username is not None and password is not None:
|
| 448 |
+
# Send the basic auth with this request
|
| 449 |
+
req = HTTPBasicAuth(username, password)(req)
|
| 450 |
+
|
| 451 |
+
# Attach a hook to handle 401 responses
|
| 452 |
+
req.register_hook("response", self.handle_401)
|
| 453 |
+
|
| 454 |
+
return req
|
| 455 |
+
|
| 456 |
+
# Factored out to allow for easy patching in tests
|
| 457 |
+
def _prompt_for_password(
|
| 458 |
+
self, netloc: str
|
| 459 |
+
) -> Tuple[Optional[str], Optional[str], bool]:
|
| 460 |
+
username = ask_input(f"User for {netloc}: ") if self.prompting else None
|
| 461 |
+
if not username:
|
| 462 |
+
return None, None, False
|
| 463 |
+
if self.use_keyring:
|
| 464 |
+
auth = self._get_keyring_auth(netloc, username)
|
| 465 |
+
if auth and auth[0] is not None and auth[1] is not None:
|
| 466 |
+
return auth[0], auth[1], False
|
| 467 |
+
password = ask_password("Password: ")
|
| 468 |
+
return username, password, True
|
| 469 |
+
|
| 470 |
+
# Factored out to allow for easy patching in tests
|
| 471 |
+
def _should_save_password_to_keyring(self) -> bool:
|
| 472 |
+
if (
|
| 473 |
+
not self.prompting
|
| 474 |
+
or not self.use_keyring
|
| 475 |
+
or not self.keyring_provider.has_keyring
|
| 476 |
+
):
|
| 477 |
+
return False
|
| 478 |
+
return ask("Save credentials to keyring [y/N]: ", ["y", "n"]) == "y"
|
| 479 |
+
|
| 480 |
+
def handle_401(self, resp: Response, **kwargs: Any) -> Response:
|
| 481 |
+
# We only care about 401 responses, anything else we want to just
|
| 482 |
+
# pass through the actual response
|
| 483 |
+
if resp.status_code != 401:
|
| 484 |
+
return resp
|
| 485 |
+
|
| 486 |
+
username, password = None, None
|
| 487 |
+
|
| 488 |
+
# Query the keyring for credentials:
|
| 489 |
+
if self.use_keyring:
|
| 490 |
+
username, password = self._get_new_credentials(
|
| 491 |
+
resp.url,
|
| 492 |
+
allow_netrc=False,
|
| 493 |
+
allow_keyring=True,
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
# We are not able to prompt the user so simply return the response
|
| 497 |
+
if not self.prompting and not username and not password:
|
| 498 |
+
return resp
|
| 499 |
+
|
| 500 |
+
parsed = urllib.parse.urlparse(resp.url)
|
| 501 |
+
|
| 502 |
+
# Prompt the user for a new username and password
|
| 503 |
+
save = False
|
| 504 |
+
if not username and not password:
|
| 505 |
+
username, password, save = self._prompt_for_password(parsed.netloc)
|
| 506 |
+
|
| 507 |
+
# Store the new username and password to use for future requests
|
| 508 |
+
self._credentials_to_save = None
|
| 509 |
+
if username is not None and password is not None:
|
| 510 |
+
self.passwords[parsed.netloc] = (username, password)
|
| 511 |
+
|
| 512 |
+
# Prompt to save the password to keyring
|
| 513 |
+
if save and self._should_save_password_to_keyring():
|
| 514 |
+
self._credentials_to_save = Credentials(
|
| 515 |
+
url=parsed.netloc,
|
| 516 |
+
username=username,
|
| 517 |
+
password=password,
|
| 518 |
+
)
|
| 519 |
+
|
| 520 |
+
# Consume content and release the original connection to allow our new
|
| 521 |
+
# request to reuse the same one.
|
| 522 |
+
# The result of the assignment isn't used, it's just needed to consume
|
| 523 |
+
# the content.
|
| 524 |
+
_ = resp.content
|
| 525 |
+
resp.raw.release_conn()
|
| 526 |
+
|
| 527 |
+
# Add our new username and password to the request
|
| 528 |
+
req = HTTPBasicAuth(username or "", password or "")(resp.request)
|
| 529 |
+
req.register_hook("response", self.warn_on_401)
|
| 530 |
+
|
| 531 |
+
# On successful request, save the credentials that were used to
|
| 532 |
+
# keyring. (Note that if the user responded "no" above, this member
|
| 533 |
+
# is not set and nothing will be saved.)
|
| 534 |
+
if self._credentials_to_save:
|
| 535 |
+
req.register_hook("response", self.save_credentials)
|
| 536 |
+
|
| 537 |
+
# Send our new request
|
| 538 |
+
new_resp = resp.connection.send(req, **kwargs)
|
| 539 |
+
new_resp.history.append(resp)
|
| 540 |
+
|
| 541 |
+
return new_resp
|
| 542 |
+
|
| 543 |
+
def warn_on_401(self, resp: Response, **kwargs: Any) -> None:
|
| 544 |
+
"""Response callback to warn about incorrect credentials."""
|
| 545 |
+
if resp.status_code == 401:
|
| 546 |
+
logger.warning(
|
| 547 |
+
"401 Error, Credentials not correct for %s",
|
| 548 |
+
resp.request.url,
|
| 549 |
+
)
|
| 550 |
+
|
| 551 |
+
def save_credentials(self, resp: Response, **kwargs: Any) -> None:
|
| 552 |
+
"""Response callback to save credentials on success."""
|
| 553 |
+
assert (
|
| 554 |
+
self.keyring_provider.has_keyring
|
| 555 |
+
), "should never reach here without keyring"
|
| 556 |
+
|
| 557 |
+
creds = self._credentials_to_save
|
| 558 |
+
self._credentials_to_save = None
|
| 559 |
+
if creds and resp.status_code < 400:
|
| 560 |
+
try:
|
| 561 |
+
logger.info("Saving credentials to keyring")
|
| 562 |
+
self.keyring_provider.save_auth_info(
|
| 563 |
+
creds.url, creds.username, creds.password
|
| 564 |
+
)
|
| 565 |
+
except Exception:
|
| 566 |
+
logger.exception("Failed to save credentials")
|
vllm/lib/python3.10/site-packages/pip/_internal/network/cache.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""HTTP cache implementation.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from contextlib import contextmanager
|
| 6 |
+
from datetime import datetime
|
| 7 |
+
from typing import BinaryIO, Generator, Optional, Union
|
| 8 |
+
|
| 9 |
+
from pip._vendor.cachecontrol.cache import SeparateBodyBaseCache
|
| 10 |
+
from pip._vendor.cachecontrol.caches import SeparateBodyFileCache
|
| 11 |
+
from pip._vendor.requests.models import Response
|
| 12 |
+
|
| 13 |
+
from pip._internal.utils.filesystem import adjacent_tmp_file, replace
|
| 14 |
+
from pip._internal.utils.misc import ensure_dir
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def is_from_cache(response: Response) -> bool:
|
| 18 |
+
return getattr(response, "from_cache", False)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@contextmanager
|
| 22 |
+
def suppressed_cache_errors() -> Generator[None, None, None]:
|
| 23 |
+
"""If we can't access the cache then we can just skip caching and process
|
| 24 |
+
requests as if caching wasn't enabled.
|
| 25 |
+
"""
|
| 26 |
+
try:
|
| 27 |
+
yield
|
| 28 |
+
except OSError:
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class SafeFileCache(SeparateBodyBaseCache):
|
| 33 |
+
"""
|
| 34 |
+
A file based cache which is safe to use even when the target directory may
|
| 35 |
+
not be accessible or writable.
|
| 36 |
+
|
| 37 |
+
There is a race condition when two processes try to write and/or read the
|
| 38 |
+
same entry at the same time, since each entry consists of two separate
|
| 39 |
+
files (https://github.com/psf/cachecontrol/issues/324). We therefore have
|
| 40 |
+
additional logic that makes sure that both files to be present before
|
| 41 |
+
returning an entry; this fixes the read side of the race condition.
|
| 42 |
+
|
| 43 |
+
For the write side, we assume that the server will only ever return the
|
| 44 |
+
same data for the same URL, which ought to be the case for files pip is
|
| 45 |
+
downloading. PyPI does not have a mechanism to swap out a wheel for
|
| 46 |
+
another wheel, for example. If this assumption is not true, the
|
| 47 |
+
CacheControl issue will need to be fixed.
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
def __init__(self, directory: str) -> None:
|
| 51 |
+
assert directory is not None, "Cache directory must not be None."
|
| 52 |
+
super().__init__()
|
| 53 |
+
self.directory = directory
|
| 54 |
+
|
| 55 |
+
def _get_cache_path(self, name: str) -> str:
|
| 56 |
+
# From cachecontrol.caches.file_cache.FileCache._fn, brought into our
|
| 57 |
+
# class for backwards-compatibility and to avoid using a non-public
|
| 58 |
+
# method.
|
| 59 |
+
hashed = SeparateBodyFileCache.encode(name)
|
| 60 |
+
parts = list(hashed[:5]) + [hashed]
|
| 61 |
+
return os.path.join(self.directory, *parts)
|
| 62 |
+
|
| 63 |
+
def get(self, key: str) -> Optional[bytes]:
|
| 64 |
+
# The cache entry is only valid if both metadata and body exist.
|
| 65 |
+
metadata_path = self._get_cache_path(key)
|
| 66 |
+
body_path = metadata_path + ".body"
|
| 67 |
+
if not (os.path.exists(metadata_path) and os.path.exists(body_path)):
|
| 68 |
+
return None
|
| 69 |
+
with suppressed_cache_errors():
|
| 70 |
+
with open(metadata_path, "rb") as f:
|
| 71 |
+
return f.read()
|
| 72 |
+
|
| 73 |
+
def _write(self, path: str, data: bytes) -> None:
|
| 74 |
+
with suppressed_cache_errors():
|
| 75 |
+
ensure_dir(os.path.dirname(path))
|
| 76 |
+
|
| 77 |
+
with adjacent_tmp_file(path) as f:
|
| 78 |
+
f.write(data)
|
| 79 |
+
# Inherit the read/write permissions of the cache directory
|
| 80 |
+
# to enable multi-user cache use-cases.
|
| 81 |
+
mode = (
|
| 82 |
+
os.stat(self.directory).st_mode
|
| 83 |
+
& 0o666 # select read/write permissions of cache directory
|
| 84 |
+
| 0o600 # set owner read/write permissions
|
| 85 |
+
)
|
| 86 |
+
# Change permissions only if there is no risk of following a symlink.
|
| 87 |
+
if os.chmod in os.supports_fd:
|
| 88 |
+
os.chmod(f.fileno(), mode)
|
| 89 |
+
elif os.chmod in os.supports_follow_symlinks:
|
| 90 |
+
os.chmod(f.name, mode, follow_symlinks=False)
|
| 91 |
+
|
| 92 |
+
replace(f.name, path)
|
| 93 |
+
|
| 94 |
+
def set(
|
| 95 |
+
self, key: str, value: bytes, expires: Union[int, datetime, None] = None
|
| 96 |
+
) -> None:
|
| 97 |
+
path = self._get_cache_path(key)
|
| 98 |
+
self._write(path, value)
|
| 99 |
+
|
| 100 |
+
def delete(self, key: str) -> None:
|
| 101 |
+
path = self._get_cache_path(key)
|
| 102 |
+
with suppressed_cache_errors():
|
| 103 |
+
os.remove(path)
|
| 104 |
+
with suppressed_cache_errors():
|
| 105 |
+
os.remove(path + ".body")
|
| 106 |
+
|
| 107 |
+
def get_body(self, key: str) -> Optional[BinaryIO]:
|
| 108 |
+
# The cache entry is only valid if both metadata and body exist.
|
| 109 |
+
metadata_path = self._get_cache_path(key)
|
| 110 |
+
body_path = metadata_path + ".body"
|
| 111 |
+
if not (os.path.exists(metadata_path) and os.path.exists(body_path)):
|
| 112 |
+
return None
|
| 113 |
+
with suppressed_cache_errors():
|
| 114 |
+
return open(body_path, "rb")
|
| 115 |
+
|
| 116 |
+
def set_body(self, key: str, body: bytes) -> None:
|
| 117 |
+
path = self._get_cache_path(key) + ".body"
|
| 118 |
+
self._write(path, body)
|
vllm/lib/python3.10/site-packages/pip/_internal/network/download.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Download files with progress indicators.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import email.message
|
| 5 |
+
import logging
|
| 6 |
+
import mimetypes
|
| 7 |
+
import os
|
| 8 |
+
from typing import Iterable, Optional, Tuple
|
| 9 |
+
|
| 10 |
+
from pip._vendor.requests.models import Response
|
| 11 |
+
|
| 12 |
+
from pip._internal.cli.progress_bars import get_download_progress_renderer
|
| 13 |
+
from pip._internal.exceptions import NetworkConnectionError
|
| 14 |
+
from pip._internal.models.index import PyPI
|
| 15 |
+
from pip._internal.models.link import Link
|
| 16 |
+
from pip._internal.network.cache import is_from_cache
|
| 17 |
+
from pip._internal.network.session import PipSession
|
| 18 |
+
from pip._internal.network.utils import HEADERS, raise_for_status, response_chunks
|
| 19 |
+
from pip._internal.utils.misc import format_size, redact_auth_from_url, splitext
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _get_http_response_size(resp: Response) -> Optional[int]:
|
| 25 |
+
try:
|
| 26 |
+
return int(resp.headers["content-length"])
|
| 27 |
+
except (ValueError, KeyError, TypeError):
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _prepare_download(
|
| 32 |
+
resp: Response,
|
| 33 |
+
link: Link,
|
| 34 |
+
progress_bar: str,
|
| 35 |
+
) -> Iterable[bytes]:
|
| 36 |
+
total_length = _get_http_response_size(resp)
|
| 37 |
+
|
| 38 |
+
if link.netloc == PyPI.file_storage_domain:
|
| 39 |
+
url = link.show_url
|
| 40 |
+
else:
|
| 41 |
+
url = link.url_without_fragment
|
| 42 |
+
|
| 43 |
+
logged_url = redact_auth_from_url(url)
|
| 44 |
+
|
| 45 |
+
if total_length:
|
| 46 |
+
logged_url = f"{logged_url} ({format_size(total_length)})"
|
| 47 |
+
|
| 48 |
+
if is_from_cache(resp):
|
| 49 |
+
logger.info("Using cached %s", logged_url)
|
| 50 |
+
else:
|
| 51 |
+
logger.info("Downloading %s", logged_url)
|
| 52 |
+
|
| 53 |
+
if logger.getEffectiveLevel() > logging.INFO:
|
| 54 |
+
show_progress = False
|
| 55 |
+
elif is_from_cache(resp):
|
| 56 |
+
show_progress = False
|
| 57 |
+
elif not total_length:
|
| 58 |
+
show_progress = True
|
| 59 |
+
elif total_length > (512 * 1024):
|
| 60 |
+
show_progress = True
|
| 61 |
+
else:
|
| 62 |
+
show_progress = False
|
| 63 |
+
|
| 64 |
+
chunks = response_chunks(resp)
|
| 65 |
+
|
| 66 |
+
if not show_progress:
|
| 67 |
+
return chunks
|
| 68 |
+
|
| 69 |
+
renderer = get_download_progress_renderer(bar_type=progress_bar, size=total_length)
|
| 70 |
+
return renderer(chunks)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def sanitize_content_filename(filename: str) -> str:
|
| 74 |
+
"""
|
| 75 |
+
Sanitize the "filename" value from a Content-Disposition header.
|
| 76 |
+
"""
|
| 77 |
+
return os.path.basename(filename)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def parse_content_disposition(content_disposition: str, default_filename: str) -> str:
|
| 81 |
+
"""
|
| 82 |
+
Parse the "filename" value from a Content-Disposition header, and
|
| 83 |
+
return the default filename if the result is empty.
|
| 84 |
+
"""
|
| 85 |
+
m = email.message.Message()
|
| 86 |
+
m["content-type"] = content_disposition
|
| 87 |
+
filename = m.get_param("filename")
|
| 88 |
+
if filename:
|
| 89 |
+
# We need to sanitize the filename to prevent directory traversal
|
| 90 |
+
# in case the filename contains ".." path parts.
|
| 91 |
+
filename = sanitize_content_filename(str(filename))
|
| 92 |
+
return filename or default_filename
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def _get_http_response_filename(resp: Response, link: Link) -> str:
|
| 96 |
+
"""Get an ideal filename from the given HTTP response, falling back to
|
| 97 |
+
the link filename if not provided.
|
| 98 |
+
"""
|
| 99 |
+
filename = link.filename # fallback
|
| 100 |
+
# Have a look at the Content-Disposition header for a better guess
|
| 101 |
+
content_disposition = resp.headers.get("content-disposition")
|
| 102 |
+
if content_disposition:
|
| 103 |
+
filename = parse_content_disposition(content_disposition, filename)
|
| 104 |
+
ext: Optional[str] = splitext(filename)[1]
|
| 105 |
+
if not ext:
|
| 106 |
+
ext = mimetypes.guess_extension(resp.headers.get("content-type", ""))
|
| 107 |
+
if ext:
|
| 108 |
+
filename += ext
|
| 109 |
+
if not ext and link.url != resp.url:
|
| 110 |
+
ext = os.path.splitext(resp.url)[1]
|
| 111 |
+
if ext:
|
| 112 |
+
filename += ext
|
| 113 |
+
return filename
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _http_get_download(session: PipSession, link: Link) -> Response:
|
| 117 |
+
target_url = link.url.split("#", 1)[0]
|
| 118 |
+
resp = session.get(target_url, headers=HEADERS, stream=True)
|
| 119 |
+
raise_for_status(resp)
|
| 120 |
+
return resp
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
class Downloader:
|
| 124 |
+
def __init__(
|
| 125 |
+
self,
|
| 126 |
+
session: PipSession,
|
| 127 |
+
progress_bar: str,
|
| 128 |
+
) -> None:
|
| 129 |
+
self._session = session
|
| 130 |
+
self._progress_bar = progress_bar
|
| 131 |
+
|
| 132 |
+
def __call__(self, link: Link, location: str) -> Tuple[str, str]:
|
| 133 |
+
"""Download the file given by link into location."""
|
| 134 |
+
try:
|
| 135 |
+
resp = _http_get_download(self._session, link)
|
| 136 |
+
except NetworkConnectionError as e:
|
| 137 |
+
assert e.response is not None
|
| 138 |
+
logger.critical(
|
| 139 |
+
"HTTP error %s while getting %s", e.response.status_code, link
|
| 140 |
+
)
|
| 141 |
+
raise
|
| 142 |
+
|
| 143 |
+
filename = _get_http_response_filename(resp, link)
|
| 144 |
+
filepath = os.path.join(location, filename)
|
| 145 |
+
|
| 146 |
+
chunks = _prepare_download(resp, link, self._progress_bar)
|
| 147 |
+
with open(filepath, "wb") as content_file:
|
| 148 |
+
for chunk in chunks:
|
| 149 |
+
content_file.write(chunk)
|
| 150 |
+
content_type = resp.headers.get("Content-Type", "")
|
| 151 |
+
return filepath, content_type
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
class BatchDownloader:
|
| 155 |
+
def __init__(
|
| 156 |
+
self,
|
| 157 |
+
session: PipSession,
|
| 158 |
+
progress_bar: str,
|
| 159 |
+
) -> None:
|
| 160 |
+
self._session = session
|
| 161 |
+
self._progress_bar = progress_bar
|
| 162 |
+
|
| 163 |
+
def __call__(
|
| 164 |
+
self, links: Iterable[Link], location: str
|
| 165 |
+
) -> Iterable[Tuple[Link, Tuple[str, str]]]:
|
| 166 |
+
"""Download the files given by links into location."""
|
| 167 |
+
for link in links:
|
| 168 |
+
try:
|
| 169 |
+
resp = _http_get_download(self._session, link)
|
| 170 |
+
except NetworkConnectionError as e:
|
| 171 |
+
assert e.response is not None
|
| 172 |
+
logger.critical(
|
| 173 |
+
"HTTP error %s while getting %s",
|
| 174 |
+
e.response.status_code,
|
| 175 |
+
link,
|
| 176 |
+
)
|
| 177 |
+
raise
|
| 178 |
+
|
| 179 |
+
filename = _get_http_response_filename(resp, link)
|
| 180 |
+
filepath = os.path.join(location, filename)
|
| 181 |
+
|
| 182 |
+
chunks = _prepare_download(resp, link, self._progress_bar)
|
| 183 |
+
with open(filepath, "wb") as content_file:
|
| 184 |
+
for chunk in chunks:
|
| 185 |
+
content_file.write(chunk)
|
| 186 |
+
content_type = resp.headers.get("Content-Type", "")
|
| 187 |
+
yield link, (filepath, content_type)
|
vllm/lib/python3.10/site-packages/pip/_internal/network/lazy_wheel.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Lazy ZIP over HTTP"""
|
| 2 |
+
|
| 3 |
+
__all__ = ["HTTPRangeRequestUnsupported", "dist_from_wheel_url"]
|
| 4 |
+
|
| 5 |
+
from bisect import bisect_left, bisect_right
|
| 6 |
+
from contextlib import contextmanager
|
| 7 |
+
from tempfile import NamedTemporaryFile
|
| 8 |
+
from typing import Any, Dict, Generator, List, Optional, Tuple
|
| 9 |
+
from zipfile import BadZipFile, ZipFile
|
| 10 |
+
|
| 11 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 12 |
+
from pip._vendor.requests.models import CONTENT_CHUNK_SIZE, Response
|
| 13 |
+
|
| 14 |
+
from pip._internal.metadata import BaseDistribution, MemoryWheel, get_wheel_distribution
|
| 15 |
+
from pip._internal.network.session import PipSession
|
| 16 |
+
from pip._internal.network.utils import HEADERS, raise_for_status, response_chunks
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class HTTPRangeRequestUnsupported(Exception):
|
| 20 |
+
pass
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def dist_from_wheel_url(name: str, url: str, session: PipSession) -> BaseDistribution:
|
| 24 |
+
"""Return a distribution object from the given wheel URL.
|
| 25 |
+
|
| 26 |
+
This uses HTTP range requests to only fetch the portion of the wheel
|
| 27 |
+
containing metadata, just enough for the object to be constructed.
|
| 28 |
+
If such requests are not supported, HTTPRangeRequestUnsupported
|
| 29 |
+
is raised.
|
| 30 |
+
"""
|
| 31 |
+
with LazyZipOverHTTP(url, session) as zf:
|
| 32 |
+
# For read-only ZIP files, ZipFile only needs methods read,
|
| 33 |
+
# seek, seekable and tell, not the whole IO protocol.
|
| 34 |
+
wheel = MemoryWheel(zf.name, zf) # type: ignore
|
| 35 |
+
# After context manager exit, wheel.name
|
| 36 |
+
# is an invalid file by intention.
|
| 37 |
+
return get_wheel_distribution(wheel, canonicalize_name(name))
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class LazyZipOverHTTP:
|
| 41 |
+
"""File-like object mapped to a ZIP file over HTTP.
|
| 42 |
+
|
| 43 |
+
This uses HTTP range requests to lazily fetch the file's content,
|
| 44 |
+
which is supposed to be fed to ZipFile. If such requests are not
|
| 45 |
+
supported by the server, raise HTTPRangeRequestUnsupported
|
| 46 |
+
during initialization.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
def __init__(
|
| 50 |
+
self, url: str, session: PipSession, chunk_size: int = CONTENT_CHUNK_SIZE
|
| 51 |
+
) -> None:
|
| 52 |
+
head = session.head(url, headers=HEADERS)
|
| 53 |
+
raise_for_status(head)
|
| 54 |
+
assert head.status_code == 200
|
| 55 |
+
self._session, self._url, self._chunk_size = session, url, chunk_size
|
| 56 |
+
self._length = int(head.headers["Content-Length"])
|
| 57 |
+
self._file = NamedTemporaryFile()
|
| 58 |
+
self.truncate(self._length)
|
| 59 |
+
self._left: List[int] = []
|
| 60 |
+
self._right: List[int] = []
|
| 61 |
+
if "bytes" not in head.headers.get("Accept-Ranges", "none"):
|
| 62 |
+
raise HTTPRangeRequestUnsupported("range request is not supported")
|
| 63 |
+
self._check_zip()
|
| 64 |
+
|
| 65 |
+
@property
|
| 66 |
+
def mode(self) -> str:
|
| 67 |
+
"""Opening mode, which is always rb."""
|
| 68 |
+
return "rb"
|
| 69 |
+
|
| 70 |
+
@property
|
| 71 |
+
def name(self) -> str:
|
| 72 |
+
"""Path to the underlying file."""
|
| 73 |
+
return self._file.name
|
| 74 |
+
|
| 75 |
+
def seekable(self) -> bool:
|
| 76 |
+
"""Return whether random access is supported, which is True."""
|
| 77 |
+
return True
|
| 78 |
+
|
| 79 |
+
def close(self) -> None:
|
| 80 |
+
"""Close the file."""
|
| 81 |
+
self._file.close()
|
| 82 |
+
|
| 83 |
+
@property
|
| 84 |
+
def closed(self) -> bool:
|
| 85 |
+
"""Whether the file is closed."""
|
| 86 |
+
return self._file.closed
|
| 87 |
+
|
| 88 |
+
def read(self, size: int = -1) -> bytes:
|
| 89 |
+
"""Read up to size bytes from the object and return them.
|
| 90 |
+
|
| 91 |
+
As a convenience, if size is unspecified or -1,
|
| 92 |
+
all bytes until EOF are returned. Fewer than
|
| 93 |
+
size bytes may be returned if EOF is reached.
|
| 94 |
+
"""
|
| 95 |
+
download_size = max(size, self._chunk_size)
|
| 96 |
+
start, length = self.tell(), self._length
|
| 97 |
+
stop = length if size < 0 else min(start + download_size, length)
|
| 98 |
+
start = max(0, stop - download_size)
|
| 99 |
+
self._download(start, stop - 1)
|
| 100 |
+
return self._file.read(size)
|
| 101 |
+
|
| 102 |
+
def readable(self) -> bool:
|
| 103 |
+
"""Return whether the file is readable, which is True."""
|
| 104 |
+
return True
|
| 105 |
+
|
| 106 |
+
def seek(self, offset: int, whence: int = 0) -> int:
|
| 107 |
+
"""Change stream position and return the new absolute position.
|
| 108 |
+
|
| 109 |
+
Seek to offset relative position indicated by whence:
|
| 110 |
+
* 0: Start of stream (the default). pos should be >= 0;
|
| 111 |
+
* 1: Current position - pos may be negative;
|
| 112 |
+
* 2: End of stream - pos usually negative.
|
| 113 |
+
"""
|
| 114 |
+
return self._file.seek(offset, whence)
|
| 115 |
+
|
| 116 |
+
def tell(self) -> int:
|
| 117 |
+
"""Return the current position."""
|
| 118 |
+
return self._file.tell()
|
| 119 |
+
|
| 120 |
+
def truncate(self, size: Optional[int] = None) -> int:
|
| 121 |
+
"""Resize the stream to the given size in bytes.
|
| 122 |
+
|
| 123 |
+
If size is unspecified resize to the current position.
|
| 124 |
+
The current stream position isn't changed.
|
| 125 |
+
|
| 126 |
+
Return the new file size.
|
| 127 |
+
"""
|
| 128 |
+
return self._file.truncate(size)
|
| 129 |
+
|
| 130 |
+
def writable(self) -> bool:
|
| 131 |
+
"""Return False."""
|
| 132 |
+
return False
|
| 133 |
+
|
| 134 |
+
def __enter__(self) -> "LazyZipOverHTTP":
|
| 135 |
+
self._file.__enter__()
|
| 136 |
+
return self
|
| 137 |
+
|
| 138 |
+
def __exit__(self, *exc: Any) -> None:
|
| 139 |
+
self._file.__exit__(*exc)
|
| 140 |
+
|
| 141 |
+
@contextmanager
|
| 142 |
+
def _stay(self) -> Generator[None, None, None]:
|
| 143 |
+
"""Return a context manager keeping the position.
|
| 144 |
+
|
| 145 |
+
At the end of the block, seek back to original position.
|
| 146 |
+
"""
|
| 147 |
+
pos = self.tell()
|
| 148 |
+
try:
|
| 149 |
+
yield
|
| 150 |
+
finally:
|
| 151 |
+
self.seek(pos)
|
| 152 |
+
|
| 153 |
+
def _check_zip(self) -> None:
|
| 154 |
+
"""Check and download until the file is a valid ZIP."""
|
| 155 |
+
end = self._length - 1
|
| 156 |
+
for start in reversed(range(0, end, self._chunk_size)):
|
| 157 |
+
self._download(start, end)
|
| 158 |
+
with self._stay():
|
| 159 |
+
try:
|
| 160 |
+
# For read-only ZIP files, ZipFile only needs
|
| 161 |
+
# methods read, seek, seekable and tell.
|
| 162 |
+
ZipFile(self)
|
| 163 |
+
except BadZipFile:
|
| 164 |
+
pass
|
| 165 |
+
else:
|
| 166 |
+
break
|
| 167 |
+
|
| 168 |
+
def _stream_response(
|
| 169 |
+
self, start: int, end: int, base_headers: Dict[str, str] = HEADERS
|
| 170 |
+
) -> Response:
|
| 171 |
+
"""Return HTTP response to a range request from start to end."""
|
| 172 |
+
headers = base_headers.copy()
|
| 173 |
+
headers["Range"] = f"bytes={start}-{end}"
|
| 174 |
+
# TODO: Get range requests to be correctly cached
|
| 175 |
+
headers["Cache-Control"] = "no-cache"
|
| 176 |
+
return self._session.get(self._url, headers=headers, stream=True)
|
| 177 |
+
|
| 178 |
+
def _merge(
|
| 179 |
+
self, start: int, end: int, left: int, right: int
|
| 180 |
+
) -> Generator[Tuple[int, int], None, None]:
|
| 181 |
+
"""Return a generator of intervals to be fetched.
|
| 182 |
+
|
| 183 |
+
Args:
|
| 184 |
+
start (int): Start of needed interval
|
| 185 |
+
end (int): End of needed interval
|
| 186 |
+
left (int): Index of first overlapping downloaded data
|
| 187 |
+
right (int): Index after last overlapping downloaded data
|
| 188 |
+
"""
|
| 189 |
+
lslice, rslice = self._left[left:right], self._right[left:right]
|
| 190 |
+
i = start = min([start] + lslice[:1])
|
| 191 |
+
end = max([end] + rslice[-1:])
|
| 192 |
+
for j, k in zip(lslice, rslice):
|
| 193 |
+
if j > i:
|
| 194 |
+
yield i, j - 1
|
| 195 |
+
i = k + 1
|
| 196 |
+
if i <= end:
|
| 197 |
+
yield i, end
|
| 198 |
+
self._left[left:right], self._right[left:right] = [start], [end]
|
| 199 |
+
|
| 200 |
+
def _download(self, start: int, end: int) -> None:
|
| 201 |
+
"""Download bytes from start to end inclusively."""
|
| 202 |
+
with self._stay():
|
| 203 |
+
left = bisect_left(self._right, start)
|
| 204 |
+
right = bisect_right(self._left, end)
|
| 205 |
+
for start, end in self._merge(start, end, left, right):
|
| 206 |
+
response = self._stream_response(start, end)
|
| 207 |
+
response.raise_for_status()
|
| 208 |
+
self.seek(start)
|
| 209 |
+
for chunk in response_chunks(response, self._chunk_size):
|
| 210 |
+
self._file.write(chunk)
|
vllm/lib/python3.10/site-packages/pip/_internal/network/session.py
ADDED
|
@@ -0,0 +1,523 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""PipSession and supporting code, containing all pip-specific
|
| 2 |
+
network request configuration and behavior.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import email.utils
|
| 6 |
+
import functools
|
| 7 |
+
import io
|
| 8 |
+
import ipaddress
|
| 9 |
+
import json
|
| 10 |
+
import logging
|
| 11 |
+
import mimetypes
|
| 12 |
+
import os
|
| 13 |
+
import platform
|
| 14 |
+
import shutil
|
| 15 |
+
import subprocess
|
| 16 |
+
import sys
|
| 17 |
+
import urllib.parse
|
| 18 |
+
import warnings
|
| 19 |
+
from typing import (
|
| 20 |
+
TYPE_CHECKING,
|
| 21 |
+
Any,
|
| 22 |
+
Dict,
|
| 23 |
+
Generator,
|
| 24 |
+
List,
|
| 25 |
+
Mapping,
|
| 26 |
+
Optional,
|
| 27 |
+
Sequence,
|
| 28 |
+
Tuple,
|
| 29 |
+
Union,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
from pip._vendor import requests, urllib3
|
| 33 |
+
from pip._vendor.cachecontrol import CacheControlAdapter as _BaseCacheControlAdapter
|
| 34 |
+
from pip._vendor.requests.adapters import DEFAULT_POOLBLOCK, BaseAdapter
|
| 35 |
+
from pip._vendor.requests.adapters import HTTPAdapter as _BaseHTTPAdapter
|
| 36 |
+
from pip._vendor.requests.models import PreparedRequest, Response
|
| 37 |
+
from pip._vendor.requests.structures import CaseInsensitiveDict
|
| 38 |
+
from pip._vendor.urllib3.connectionpool import ConnectionPool
|
| 39 |
+
from pip._vendor.urllib3.exceptions import InsecureRequestWarning
|
| 40 |
+
|
| 41 |
+
from pip import __version__
|
| 42 |
+
from pip._internal.metadata import get_default_environment
|
| 43 |
+
from pip._internal.models.link import Link
|
| 44 |
+
from pip._internal.network.auth import MultiDomainBasicAuth
|
| 45 |
+
from pip._internal.network.cache import SafeFileCache
|
| 46 |
+
|
| 47 |
+
# Import ssl from compat so the initial import occurs in only one place.
|
| 48 |
+
from pip._internal.utils.compat import has_tls
|
| 49 |
+
from pip._internal.utils.glibc import libc_ver
|
| 50 |
+
from pip._internal.utils.misc import build_url_from_netloc, parse_netloc
|
| 51 |
+
from pip._internal.utils.urls import url_to_path
|
| 52 |
+
|
| 53 |
+
if TYPE_CHECKING:
|
| 54 |
+
from ssl import SSLContext
|
| 55 |
+
|
| 56 |
+
from pip._vendor.urllib3.poolmanager import PoolManager
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
logger = logging.getLogger(__name__)
|
| 60 |
+
|
| 61 |
+
SecureOrigin = Tuple[str, str, Optional[Union[int, str]]]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# Ignore warning raised when using --trusted-host.
|
| 65 |
+
warnings.filterwarnings("ignore", category=InsecureRequestWarning)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
SECURE_ORIGINS: List[SecureOrigin] = [
|
| 69 |
+
# protocol, hostname, port
|
| 70 |
+
# Taken from Chrome's list of secure origins (See: http://bit.ly/1qrySKC)
|
| 71 |
+
("https", "*", "*"),
|
| 72 |
+
("*", "localhost", "*"),
|
| 73 |
+
("*", "127.0.0.0/8", "*"),
|
| 74 |
+
("*", "::1/128", "*"),
|
| 75 |
+
("file", "*", None),
|
| 76 |
+
# ssh is always secure.
|
| 77 |
+
("ssh", "*", "*"),
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# These are environment variables present when running under various
|
| 82 |
+
# CI systems. For each variable, some CI systems that use the variable
|
| 83 |
+
# are indicated. The collection was chosen so that for each of a number
|
| 84 |
+
# of popular systems, at least one of the environment variables is used.
|
| 85 |
+
# This list is used to provide some indication of and lower bound for
|
| 86 |
+
# CI traffic to PyPI. Thus, it is okay if the list is not comprehensive.
|
| 87 |
+
# For more background, see: https://github.com/pypa/pip/issues/5499
|
| 88 |
+
CI_ENVIRONMENT_VARIABLES = (
|
| 89 |
+
# Azure Pipelines
|
| 90 |
+
"BUILD_BUILDID",
|
| 91 |
+
# Jenkins
|
| 92 |
+
"BUILD_ID",
|
| 93 |
+
# AppVeyor, CircleCI, Codeship, Gitlab CI, Shippable, Travis CI
|
| 94 |
+
"CI",
|
| 95 |
+
# Explicit environment variable.
|
| 96 |
+
"PIP_IS_CI",
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def looks_like_ci() -> bool:
|
| 101 |
+
"""
|
| 102 |
+
Return whether it looks like pip is running under CI.
|
| 103 |
+
"""
|
| 104 |
+
# We don't use the method of checking for a tty (e.g. using isatty())
|
| 105 |
+
# because some CI systems mimic a tty (e.g. Travis CI). Thus that
|
| 106 |
+
# method doesn't provide definitive information in either direction.
|
| 107 |
+
return any(name in os.environ for name in CI_ENVIRONMENT_VARIABLES)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
@functools.lru_cache(maxsize=1)
|
| 111 |
+
def user_agent() -> str:
|
| 112 |
+
"""
|
| 113 |
+
Return a string representing the user agent.
|
| 114 |
+
"""
|
| 115 |
+
data: Dict[str, Any] = {
|
| 116 |
+
"installer": {"name": "pip", "version": __version__},
|
| 117 |
+
"python": platform.python_version(),
|
| 118 |
+
"implementation": {
|
| 119 |
+
"name": platform.python_implementation(),
|
| 120 |
+
},
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
if data["implementation"]["name"] == "CPython":
|
| 124 |
+
data["implementation"]["version"] = platform.python_version()
|
| 125 |
+
elif data["implementation"]["name"] == "PyPy":
|
| 126 |
+
pypy_version_info = sys.pypy_version_info # type: ignore
|
| 127 |
+
if pypy_version_info.releaselevel == "final":
|
| 128 |
+
pypy_version_info = pypy_version_info[:3]
|
| 129 |
+
data["implementation"]["version"] = ".".join(
|
| 130 |
+
[str(x) for x in pypy_version_info]
|
| 131 |
+
)
|
| 132 |
+
elif data["implementation"]["name"] == "Jython":
|
| 133 |
+
# Complete Guess
|
| 134 |
+
data["implementation"]["version"] = platform.python_version()
|
| 135 |
+
elif data["implementation"]["name"] == "IronPython":
|
| 136 |
+
# Complete Guess
|
| 137 |
+
data["implementation"]["version"] = platform.python_version()
|
| 138 |
+
|
| 139 |
+
if sys.platform.startswith("linux"):
|
| 140 |
+
from pip._vendor import distro
|
| 141 |
+
|
| 142 |
+
linux_distribution = distro.name(), distro.version(), distro.codename()
|
| 143 |
+
distro_infos: Dict[str, Any] = dict(
|
| 144 |
+
filter(
|
| 145 |
+
lambda x: x[1],
|
| 146 |
+
zip(["name", "version", "id"], linux_distribution),
|
| 147 |
+
)
|
| 148 |
+
)
|
| 149 |
+
libc = dict(
|
| 150 |
+
filter(
|
| 151 |
+
lambda x: x[1],
|
| 152 |
+
zip(["lib", "version"], libc_ver()),
|
| 153 |
+
)
|
| 154 |
+
)
|
| 155 |
+
if libc:
|
| 156 |
+
distro_infos["libc"] = libc
|
| 157 |
+
if distro_infos:
|
| 158 |
+
data["distro"] = distro_infos
|
| 159 |
+
|
| 160 |
+
if sys.platform.startswith("darwin") and platform.mac_ver()[0]:
|
| 161 |
+
data["distro"] = {"name": "macOS", "version": platform.mac_ver()[0]}
|
| 162 |
+
|
| 163 |
+
if platform.system():
|
| 164 |
+
data.setdefault("system", {})["name"] = platform.system()
|
| 165 |
+
|
| 166 |
+
if platform.release():
|
| 167 |
+
data.setdefault("system", {})["release"] = platform.release()
|
| 168 |
+
|
| 169 |
+
if platform.machine():
|
| 170 |
+
data["cpu"] = platform.machine()
|
| 171 |
+
|
| 172 |
+
if has_tls():
|
| 173 |
+
import _ssl as ssl
|
| 174 |
+
|
| 175 |
+
data["openssl_version"] = ssl.OPENSSL_VERSION
|
| 176 |
+
|
| 177 |
+
setuptools_dist = get_default_environment().get_distribution("setuptools")
|
| 178 |
+
if setuptools_dist is not None:
|
| 179 |
+
data["setuptools_version"] = str(setuptools_dist.version)
|
| 180 |
+
|
| 181 |
+
if shutil.which("rustc") is not None:
|
| 182 |
+
# If for any reason `rustc --version` fails, silently ignore it
|
| 183 |
+
try:
|
| 184 |
+
rustc_output = subprocess.check_output(
|
| 185 |
+
["rustc", "--version"], stderr=subprocess.STDOUT, timeout=0.5
|
| 186 |
+
)
|
| 187 |
+
except Exception:
|
| 188 |
+
pass
|
| 189 |
+
else:
|
| 190 |
+
if rustc_output.startswith(b"rustc "):
|
| 191 |
+
# The format of `rustc --version` is:
|
| 192 |
+
# `b'rustc 1.52.1 (9bc8c42bb 2021-05-09)\n'`
|
| 193 |
+
# We extract just the middle (1.52.1) part
|
| 194 |
+
data["rustc_version"] = rustc_output.split(b" ")[1].decode()
|
| 195 |
+
|
| 196 |
+
# Use None rather than False so as not to give the impression that
|
| 197 |
+
# pip knows it is not being run under CI. Rather, it is a null or
|
| 198 |
+
# inconclusive result. Also, we include some value rather than no
|
| 199 |
+
# value to make it easier to know that the check has been run.
|
| 200 |
+
data["ci"] = True if looks_like_ci() else None
|
| 201 |
+
|
| 202 |
+
user_data = os.environ.get("PIP_USER_AGENT_USER_DATA")
|
| 203 |
+
if user_data is not None:
|
| 204 |
+
data["user_data"] = user_data
|
| 205 |
+
|
| 206 |
+
return "{data[installer][name]}/{data[installer][version]} {json}".format(
|
| 207 |
+
data=data,
|
| 208 |
+
json=json.dumps(data, separators=(",", ":"), sort_keys=True),
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
class LocalFSAdapter(BaseAdapter):
|
| 213 |
+
def send(
|
| 214 |
+
self,
|
| 215 |
+
request: PreparedRequest,
|
| 216 |
+
stream: bool = False,
|
| 217 |
+
timeout: Optional[Union[float, Tuple[float, float]]] = None,
|
| 218 |
+
verify: Union[bool, str] = True,
|
| 219 |
+
cert: Optional[Union[str, Tuple[str, str]]] = None,
|
| 220 |
+
proxies: Optional[Mapping[str, str]] = None,
|
| 221 |
+
) -> Response:
|
| 222 |
+
pathname = url_to_path(request.url)
|
| 223 |
+
|
| 224 |
+
resp = Response()
|
| 225 |
+
resp.status_code = 200
|
| 226 |
+
resp.url = request.url
|
| 227 |
+
|
| 228 |
+
try:
|
| 229 |
+
stats = os.stat(pathname)
|
| 230 |
+
except OSError as exc:
|
| 231 |
+
# format the exception raised as a io.BytesIO object,
|
| 232 |
+
# to return a better error message:
|
| 233 |
+
resp.status_code = 404
|
| 234 |
+
resp.reason = type(exc).__name__
|
| 235 |
+
resp.raw = io.BytesIO(f"{resp.reason}: {exc}".encode())
|
| 236 |
+
else:
|
| 237 |
+
modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
|
| 238 |
+
content_type = mimetypes.guess_type(pathname)[0] or "text/plain"
|
| 239 |
+
resp.headers = CaseInsensitiveDict(
|
| 240 |
+
{
|
| 241 |
+
"Content-Type": content_type,
|
| 242 |
+
"Content-Length": stats.st_size,
|
| 243 |
+
"Last-Modified": modified,
|
| 244 |
+
}
|
| 245 |
+
)
|
| 246 |
+
|
| 247 |
+
resp.raw = open(pathname, "rb")
|
| 248 |
+
resp.close = resp.raw.close
|
| 249 |
+
|
| 250 |
+
return resp
|
| 251 |
+
|
| 252 |
+
def close(self) -> None:
|
| 253 |
+
pass
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
class _SSLContextAdapterMixin:
|
| 257 |
+
"""Mixin to add the ``ssl_context`` constructor argument to HTTP adapters.
|
| 258 |
+
|
| 259 |
+
The additional argument is forwarded directly to the pool manager. This allows us
|
| 260 |
+
to dynamically decide what SSL store to use at runtime, which is used to implement
|
| 261 |
+
the optional ``truststore`` backend.
|
| 262 |
+
"""
|
| 263 |
+
|
| 264 |
+
def __init__(
|
| 265 |
+
self,
|
| 266 |
+
*,
|
| 267 |
+
ssl_context: Optional["SSLContext"] = None,
|
| 268 |
+
**kwargs: Any,
|
| 269 |
+
) -> None:
|
| 270 |
+
self._ssl_context = ssl_context
|
| 271 |
+
super().__init__(**kwargs)
|
| 272 |
+
|
| 273 |
+
def init_poolmanager(
|
| 274 |
+
self,
|
| 275 |
+
connections: int,
|
| 276 |
+
maxsize: int,
|
| 277 |
+
block: bool = DEFAULT_POOLBLOCK,
|
| 278 |
+
**pool_kwargs: Any,
|
| 279 |
+
) -> "PoolManager":
|
| 280 |
+
if self._ssl_context is not None:
|
| 281 |
+
pool_kwargs.setdefault("ssl_context", self._ssl_context)
|
| 282 |
+
return super().init_poolmanager( # type: ignore[misc]
|
| 283 |
+
connections=connections,
|
| 284 |
+
maxsize=maxsize,
|
| 285 |
+
block=block,
|
| 286 |
+
**pool_kwargs,
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
class HTTPAdapter(_SSLContextAdapterMixin, _BaseHTTPAdapter):
|
| 291 |
+
pass
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
class CacheControlAdapter(_SSLContextAdapterMixin, _BaseCacheControlAdapter):
|
| 295 |
+
pass
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
class InsecureHTTPAdapter(HTTPAdapter):
|
| 299 |
+
def cert_verify(
|
| 300 |
+
self,
|
| 301 |
+
conn: ConnectionPool,
|
| 302 |
+
url: str,
|
| 303 |
+
verify: Union[bool, str],
|
| 304 |
+
cert: Optional[Union[str, Tuple[str, str]]],
|
| 305 |
+
) -> None:
|
| 306 |
+
super().cert_verify(conn=conn, url=url, verify=False, cert=cert)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
class InsecureCacheControlAdapter(CacheControlAdapter):
|
| 310 |
+
def cert_verify(
|
| 311 |
+
self,
|
| 312 |
+
conn: ConnectionPool,
|
| 313 |
+
url: str,
|
| 314 |
+
verify: Union[bool, str],
|
| 315 |
+
cert: Optional[Union[str, Tuple[str, str]]],
|
| 316 |
+
) -> None:
|
| 317 |
+
super().cert_verify(conn=conn, url=url, verify=False, cert=cert)
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
class PipSession(requests.Session):
|
| 321 |
+
timeout: Optional[int] = None
|
| 322 |
+
|
| 323 |
+
def __init__(
|
| 324 |
+
self,
|
| 325 |
+
*args: Any,
|
| 326 |
+
retries: int = 0,
|
| 327 |
+
cache: Optional[str] = None,
|
| 328 |
+
trusted_hosts: Sequence[str] = (),
|
| 329 |
+
index_urls: Optional[List[str]] = None,
|
| 330 |
+
ssl_context: Optional["SSLContext"] = None,
|
| 331 |
+
**kwargs: Any,
|
| 332 |
+
) -> None:
|
| 333 |
+
"""
|
| 334 |
+
:param trusted_hosts: Domains not to emit warnings for when not using
|
| 335 |
+
HTTPS.
|
| 336 |
+
"""
|
| 337 |
+
super().__init__(*args, **kwargs)
|
| 338 |
+
|
| 339 |
+
# Namespace the attribute with "pip_" just in case to prevent
|
| 340 |
+
# possible conflicts with the base class.
|
| 341 |
+
self.pip_trusted_origins: List[Tuple[str, Optional[int]]] = []
|
| 342 |
+
self.pip_proxy = None
|
| 343 |
+
|
| 344 |
+
# Attach our User Agent to the request
|
| 345 |
+
self.headers["User-Agent"] = user_agent()
|
| 346 |
+
|
| 347 |
+
# Attach our Authentication handler to the session
|
| 348 |
+
self.auth = MultiDomainBasicAuth(index_urls=index_urls)
|
| 349 |
+
|
| 350 |
+
# Create our urllib3.Retry instance which will allow us to customize
|
| 351 |
+
# how we handle retries.
|
| 352 |
+
retries = urllib3.Retry(
|
| 353 |
+
# Set the total number of retries that a particular request can
|
| 354 |
+
# have.
|
| 355 |
+
total=retries,
|
| 356 |
+
# A 503 error from PyPI typically means that the Fastly -> Origin
|
| 357 |
+
# connection got interrupted in some way. A 503 error in general
|
| 358 |
+
# is typically considered a transient error so we'll go ahead and
|
| 359 |
+
# retry it.
|
| 360 |
+
# A 500 may indicate transient error in Amazon S3
|
| 361 |
+
# A 502 may be a transient error from a CDN like CloudFlare or CloudFront
|
| 362 |
+
# A 520 or 527 - may indicate transient error in CloudFlare
|
| 363 |
+
status_forcelist=[500, 502, 503, 520, 527],
|
| 364 |
+
# Add a small amount of back off between failed requests in
|
| 365 |
+
# order to prevent hammering the service.
|
| 366 |
+
backoff_factor=0.25,
|
| 367 |
+
) # type: ignore
|
| 368 |
+
|
| 369 |
+
# Our Insecure HTTPAdapter disables HTTPS validation. It does not
|
| 370 |
+
# support caching so we'll use it for all http:// URLs.
|
| 371 |
+
# If caching is disabled, we will also use it for
|
| 372 |
+
# https:// hosts that we've marked as ignoring
|
| 373 |
+
# TLS errors for (trusted-hosts).
|
| 374 |
+
insecure_adapter = InsecureHTTPAdapter(max_retries=retries)
|
| 375 |
+
|
| 376 |
+
# We want to _only_ cache responses on securely fetched origins or when
|
| 377 |
+
# the host is specified as trusted. We do this because
|
| 378 |
+
# we can't validate the response of an insecurely/untrusted fetched
|
| 379 |
+
# origin, and we don't want someone to be able to poison the cache and
|
| 380 |
+
# require manual eviction from the cache to fix it.
|
| 381 |
+
if cache:
|
| 382 |
+
secure_adapter = CacheControlAdapter(
|
| 383 |
+
cache=SafeFileCache(cache),
|
| 384 |
+
max_retries=retries,
|
| 385 |
+
ssl_context=ssl_context,
|
| 386 |
+
)
|
| 387 |
+
self._trusted_host_adapter = InsecureCacheControlAdapter(
|
| 388 |
+
cache=SafeFileCache(cache),
|
| 389 |
+
max_retries=retries,
|
| 390 |
+
)
|
| 391 |
+
else:
|
| 392 |
+
secure_adapter = HTTPAdapter(max_retries=retries, ssl_context=ssl_context)
|
| 393 |
+
self._trusted_host_adapter = insecure_adapter
|
| 394 |
+
|
| 395 |
+
self.mount("https://", secure_adapter)
|
| 396 |
+
self.mount("http://", insecure_adapter)
|
| 397 |
+
|
| 398 |
+
# Enable file:// urls
|
| 399 |
+
self.mount("file://", LocalFSAdapter())
|
| 400 |
+
|
| 401 |
+
for host in trusted_hosts:
|
| 402 |
+
self.add_trusted_host(host, suppress_logging=True)
|
| 403 |
+
|
| 404 |
+
def update_index_urls(self, new_index_urls: List[str]) -> None:
|
| 405 |
+
"""
|
| 406 |
+
:param new_index_urls: New index urls to update the authentication
|
| 407 |
+
handler with.
|
| 408 |
+
"""
|
| 409 |
+
self.auth.index_urls = new_index_urls
|
| 410 |
+
|
| 411 |
+
def add_trusted_host(
|
| 412 |
+
self, host: str, source: Optional[str] = None, suppress_logging: bool = False
|
| 413 |
+
) -> None:
|
| 414 |
+
"""
|
| 415 |
+
:param host: It is okay to provide a host that has previously been
|
| 416 |
+
added.
|
| 417 |
+
:param source: An optional source string, for logging where the host
|
| 418 |
+
string came from.
|
| 419 |
+
"""
|
| 420 |
+
if not suppress_logging:
|
| 421 |
+
msg = f"adding trusted host: {host!r}"
|
| 422 |
+
if source is not None:
|
| 423 |
+
msg += f" (from {source})"
|
| 424 |
+
logger.info(msg)
|
| 425 |
+
|
| 426 |
+
parsed_host, parsed_port = parse_netloc(host)
|
| 427 |
+
if parsed_host is None:
|
| 428 |
+
raise ValueError(f"Trusted host URL must include a host part: {host!r}")
|
| 429 |
+
if (parsed_host, parsed_port) not in self.pip_trusted_origins:
|
| 430 |
+
self.pip_trusted_origins.append((parsed_host, parsed_port))
|
| 431 |
+
|
| 432 |
+
self.mount(
|
| 433 |
+
build_url_from_netloc(host, scheme="http") + "/", self._trusted_host_adapter
|
| 434 |
+
)
|
| 435 |
+
self.mount(build_url_from_netloc(host) + "/", self._trusted_host_adapter)
|
| 436 |
+
if not parsed_port:
|
| 437 |
+
self.mount(
|
| 438 |
+
build_url_from_netloc(host, scheme="http") + ":",
|
| 439 |
+
self._trusted_host_adapter,
|
| 440 |
+
)
|
| 441 |
+
# Mount wildcard ports for the same host.
|
| 442 |
+
self.mount(build_url_from_netloc(host) + ":", self._trusted_host_adapter)
|
| 443 |
+
|
| 444 |
+
def iter_secure_origins(self) -> Generator[SecureOrigin, None, None]:
|
| 445 |
+
yield from SECURE_ORIGINS
|
| 446 |
+
for host, port in self.pip_trusted_origins:
|
| 447 |
+
yield ("*", host, "*" if port is None else port)
|
| 448 |
+
|
| 449 |
+
def is_secure_origin(self, location: Link) -> bool:
|
| 450 |
+
# Determine if this url used a secure transport mechanism
|
| 451 |
+
parsed = urllib.parse.urlparse(str(location))
|
| 452 |
+
origin_protocol, origin_host, origin_port = (
|
| 453 |
+
parsed.scheme,
|
| 454 |
+
parsed.hostname,
|
| 455 |
+
parsed.port,
|
| 456 |
+
)
|
| 457 |
+
|
| 458 |
+
# The protocol to use to see if the protocol matches.
|
| 459 |
+
# Don't count the repository type as part of the protocol: in
|
| 460 |
+
# cases such as "git+ssh", only use "ssh". (I.e., Only verify against
|
| 461 |
+
# the last scheme.)
|
| 462 |
+
origin_protocol = origin_protocol.rsplit("+", 1)[-1]
|
| 463 |
+
|
| 464 |
+
# Determine if our origin is a secure origin by looking through our
|
| 465 |
+
# hardcoded list of secure origins, as well as any additional ones
|
| 466 |
+
# configured on this PackageFinder instance.
|
| 467 |
+
for secure_origin in self.iter_secure_origins():
|
| 468 |
+
secure_protocol, secure_host, secure_port = secure_origin
|
| 469 |
+
if origin_protocol != secure_protocol and secure_protocol != "*":
|
| 470 |
+
continue
|
| 471 |
+
|
| 472 |
+
try:
|
| 473 |
+
addr = ipaddress.ip_address(origin_host or "")
|
| 474 |
+
network = ipaddress.ip_network(secure_host)
|
| 475 |
+
except ValueError:
|
| 476 |
+
# We don't have both a valid address or a valid network, so
|
| 477 |
+
# we'll check this origin against hostnames.
|
| 478 |
+
if (
|
| 479 |
+
origin_host
|
| 480 |
+
and origin_host.lower() != secure_host.lower()
|
| 481 |
+
and secure_host != "*"
|
| 482 |
+
):
|
| 483 |
+
continue
|
| 484 |
+
else:
|
| 485 |
+
# We have a valid address and network, so see if the address
|
| 486 |
+
# is contained within the network.
|
| 487 |
+
if addr not in network:
|
| 488 |
+
continue
|
| 489 |
+
|
| 490 |
+
# Check to see if the port matches.
|
| 491 |
+
if (
|
| 492 |
+
origin_port != secure_port
|
| 493 |
+
and secure_port != "*"
|
| 494 |
+
and secure_port is not None
|
| 495 |
+
):
|
| 496 |
+
continue
|
| 497 |
+
|
| 498 |
+
# If we've gotten here, then this origin matches the current
|
| 499 |
+
# secure origin and we should return True
|
| 500 |
+
return True
|
| 501 |
+
|
| 502 |
+
# If we've gotten to this point, then the origin isn't secure and we
|
| 503 |
+
# will not accept it as a valid location to search. We will however
|
| 504 |
+
# log a warning that we are ignoring it.
|
| 505 |
+
logger.warning(
|
| 506 |
+
"The repository located at %s is not a trusted or secure host and "
|
| 507 |
+
"is being ignored. If this repository is available via HTTPS we "
|
| 508 |
+
"recommend you use HTTPS instead, otherwise you may silence "
|
| 509 |
+
"this warning and allow it anyway with '--trusted-host %s'.",
|
| 510 |
+
origin_host,
|
| 511 |
+
origin_host,
|
| 512 |
+
)
|
| 513 |
+
|
| 514 |
+
return False
|
| 515 |
+
|
| 516 |
+
def request(self, method: str, url: str, *args: Any, **kwargs: Any) -> Response:
|
| 517 |
+
# Allow setting a default timeout on a session
|
| 518 |
+
kwargs.setdefault("timeout", self.timeout)
|
| 519 |
+
# Allow setting a default proxies on a session
|
| 520 |
+
kwargs.setdefault("proxies", self.proxies)
|
| 521 |
+
|
| 522 |
+
# Dispatch the actual request
|
| 523 |
+
return super().request(method, url, *args, **kwargs)
|
vllm/lib/python3.10/site-packages/pip/_internal/network/utils.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Generator
|
| 2 |
+
|
| 3 |
+
from pip._vendor.requests.models import Response
|
| 4 |
+
|
| 5 |
+
from pip._internal.exceptions import NetworkConnectionError
|
| 6 |
+
|
| 7 |
+
# The following comments and HTTP headers were originally added by
|
| 8 |
+
# Donald Stufft in git commit 22c562429a61bb77172039e480873fb239dd8c03.
|
| 9 |
+
#
|
| 10 |
+
# We use Accept-Encoding: identity here because requests defaults to
|
| 11 |
+
# accepting compressed responses. This breaks in a variety of ways
|
| 12 |
+
# depending on how the server is configured.
|
| 13 |
+
# - Some servers will notice that the file isn't a compressible file
|
| 14 |
+
# and will leave the file alone and with an empty Content-Encoding
|
| 15 |
+
# - Some servers will notice that the file is already compressed and
|
| 16 |
+
# will leave the file alone, adding a Content-Encoding: gzip header
|
| 17 |
+
# - Some servers won't notice anything at all and will take a file
|
| 18 |
+
# that's already been compressed and compress it again, and set
|
| 19 |
+
# the Content-Encoding: gzip header
|
| 20 |
+
# By setting this to request only the identity encoding we're hoping
|
| 21 |
+
# to eliminate the third case. Hopefully there does not exist a server
|
| 22 |
+
# which when given a file will notice it is already compressed and that
|
| 23 |
+
# you're not asking for a compressed file and will then decompress it
|
| 24 |
+
# before sending because if that's the case I don't think it'll ever be
|
| 25 |
+
# possible to make this work.
|
| 26 |
+
HEADERS: Dict[str, str] = {"Accept-Encoding": "identity"}
|
| 27 |
+
|
| 28 |
+
DOWNLOAD_CHUNK_SIZE = 256 * 1024
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def raise_for_status(resp: Response) -> None:
|
| 32 |
+
http_error_msg = ""
|
| 33 |
+
if isinstance(resp.reason, bytes):
|
| 34 |
+
# We attempt to decode utf-8 first because some servers
|
| 35 |
+
# choose to localize their reason strings. If the string
|
| 36 |
+
# isn't utf-8, we fall back to iso-8859-1 for all other
|
| 37 |
+
# encodings.
|
| 38 |
+
try:
|
| 39 |
+
reason = resp.reason.decode("utf-8")
|
| 40 |
+
except UnicodeDecodeError:
|
| 41 |
+
reason = resp.reason.decode("iso-8859-1")
|
| 42 |
+
else:
|
| 43 |
+
reason = resp.reason
|
| 44 |
+
|
| 45 |
+
if 400 <= resp.status_code < 500:
|
| 46 |
+
http_error_msg = (
|
| 47 |
+
f"{resp.status_code} Client Error: {reason} for url: {resp.url}"
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
elif 500 <= resp.status_code < 600:
|
| 51 |
+
http_error_msg = (
|
| 52 |
+
f"{resp.status_code} Server Error: {reason} for url: {resp.url}"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
if http_error_msg:
|
| 56 |
+
raise NetworkConnectionError(http_error_msg, response=resp)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def response_chunks(
|
| 60 |
+
response: Response, chunk_size: int = DOWNLOAD_CHUNK_SIZE
|
| 61 |
+
) -> Generator[bytes, None, None]:
|
| 62 |
+
"""Given a requests Response, provide the data chunks."""
|
| 63 |
+
try:
|
| 64 |
+
# Special case for urllib3.
|
| 65 |
+
for chunk in response.raw.stream(
|
| 66 |
+
chunk_size,
|
| 67 |
+
# We use decode_content=False here because we don't
|
| 68 |
+
# want urllib3 to mess with the raw bytes we get
|
| 69 |
+
# from the server. If we decompress inside of
|
| 70 |
+
# urllib3 then we cannot verify the checksum
|
| 71 |
+
# because the checksum will be of the compressed
|
| 72 |
+
# file. This breakage will only occur if the
|
| 73 |
+
# server adds a Content-Encoding header, which
|
| 74 |
+
# depends on how the server was configured:
|
| 75 |
+
# - Some servers will notice that the file isn't a
|
| 76 |
+
# compressible file and will leave the file alone
|
| 77 |
+
# and with an empty Content-Encoding
|
| 78 |
+
# - Some servers will notice that the file is
|
| 79 |
+
# already compressed and will leave the file
|
| 80 |
+
# alone and will add a Content-Encoding: gzip
|
| 81 |
+
# header
|
| 82 |
+
# - Some servers won't notice anything at all and
|
| 83 |
+
# will take a file that's already been compressed
|
| 84 |
+
# and compress it again and set the
|
| 85 |
+
# Content-Encoding: gzip header
|
| 86 |
+
#
|
| 87 |
+
# By setting this not to decode automatically we
|
| 88 |
+
# hope to eliminate problems with the second case.
|
| 89 |
+
decode_content=False,
|
| 90 |
+
):
|
| 91 |
+
yield chunk
|
| 92 |
+
except AttributeError:
|
| 93 |
+
# Standard file-like object.
|
| 94 |
+
while True:
|
| 95 |
+
chunk = response.raw.read(chunk_size)
|
| 96 |
+
if not chunk:
|
| 97 |
+
break
|
| 98 |
+
yield chunk
|
vllm/lib/python3.10/site-packages/pip/_internal/network/xmlrpc.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""xmlrpclib.Transport implementation
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import logging
|
| 5 |
+
import urllib.parse
|
| 6 |
+
import xmlrpc.client
|
| 7 |
+
from typing import TYPE_CHECKING, Tuple
|
| 8 |
+
|
| 9 |
+
from pip._internal.exceptions import NetworkConnectionError
|
| 10 |
+
from pip._internal.network.session import PipSession
|
| 11 |
+
from pip._internal.network.utils import raise_for_status
|
| 12 |
+
|
| 13 |
+
if TYPE_CHECKING:
|
| 14 |
+
from xmlrpc.client import _HostType, _Marshallable
|
| 15 |
+
|
| 16 |
+
from _typeshed import SizedBuffer
|
| 17 |
+
|
| 18 |
+
logger = logging.getLogger(__name__)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class PipXmlrpcTransport(xmlrpc.client.Transport):
|
| 22 |
+
"""Provide a `xmlrpclib.Transport` implementation via a `PipSession`
|
| 23 |
+
object.
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
def __init__(
|
| 27 |
+
self, index_url: str, session: PipSession, use_datetime: bool = False
|
| 28 |
+
) -> None:
|
| 29 |
+
super().__init__(use_datetime)
|
| 30 |
+
index_parts = urllib.parse.urlparse(index_url)
|
| 31 |
+
self._scheme = index_parts.scheme
|
| 32 |
+
self._session = session
|
| 33 |
+
|
| 34 |
+
def request(
|
| 35 |
+
self,
|
| 36 |
+
host: "_HostType",
|
| 37 |
+
handler: str,
|
| 38 |
+
request_body: "SizedBuffer",
|
| 39 |
+
verbose: bool = False,
|
| 40 |
+
) -> Tuple["_Marshallable", ...]:
|
| 41 |
+
assert isinstance(host, str)
|
| 42 |
+
parts = (self._scheme, host, handler, None, None, None)
|
| 43 |
+
url = urllib.parse.urlunparse(parts)
|
| 44 |
+
try:
|
| 45 |
+
headers = {"Content-Type": "text/xml"}
|
| 46 |
+
response = self._session.post(
|
| 47 |
+
url,
|
| 48 |
+
data=request_body,
|
| 49 |
+
headers=headers,
|
| 50 |
+
stream=True,
|
| 51 |
+
)
|
| 52 |
+
raise_for_status(response)
|
| 53 |
+
self.verbose = verbose
|
| 54 |
+
return self.parse_response(response.raw)
|
| 55 |
+
except NetworkConnectionError as exc:
|
| 56 |
+
assert exc.response
|
| 57 |
+
logger.critical(
|
| 58 |
+
"HTTP error %s while getting %s",
|
| 59 |
+
exc.response.status_code,
|
| 60 |
+
url,
|
| 61 |
+
)
|
| 62 |
+
raise
|
vllm/lib/python3.10/site-packages/pip/_internal/operations/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (174 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (169 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/_jaraco_text.cpython-310.pyc
ADDED
|
Binary file (3.82 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/_log.cpython-310.pyc
ADDED
|
Binary file (1.5 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/appdirs.cpython-310.pyc
ADDED
|
Binary file (1.6 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/compat.cpython-310.pyc
ADDED
|
Binary file (1.94 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/compatibility_tags.cpython-310.pyc
ADDED
|
Binary file (4.43 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/pip/_internal/utils/__pycache__/datetime.cpython-310.pyc
ADDED
|
Binary file (492 Bytes). View file
|
|
|