Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- evalkit_llava/lib/python3.10/idlelib/Icons/python.gif +3 -0
- evalkit_llava/lib/python3.10/idlelib/Icons/tk.gif +3 -0
- evalkit_llava/lib/python3.10/lib2to3/Grammar3.10.16.final.0.pickle +3 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__init__.py +4 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/autocompletion.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/command_context.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/parser.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/req_command.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/spinners.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/status_codes.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.py +176 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/base_command.py +240 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/cmdoptions.py +1075 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/command_context.py +27 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/index_command.py +171 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/main.py +80 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/main_parser.py +134 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/parser.py +294 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/progress_bars.py +94 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/req_command.py +329 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/spinners.py +159 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/status_codes.py +6 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/__init__.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/cache.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/check.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/completion.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/configuration.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/debug.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/download.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/freeze.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/hash.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/help.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/index.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/inspect.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/install.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/list.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/search.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/show.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/uninstall.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/wheel.cpython-310.pyc +0 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/check.py +67 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/configuration.py +280 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/debug.py +201 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/freeze.py +109 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/install.py +784 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/list.py +375 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/show.py +224 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/wheel.py +182 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/index/__init__.py +2 -0
- evalkit_llava/lib/python3.10/site-packages/pip/_internal/index/__pycache__/__init__.cpython-310.pyc +0 -0
evalkit_llava/lib/python3.10/idlelib/Icons/python.gif
ADDED
|
|
Git LFS Details
|
evalkit_llava/lib/python3.10/idlelib/Icons/tk.gif
ADDED
|
|
Git LFS Details
|
evalkit_llava/lib/python3.10/lib2to3/Grammar3.10.16.final.0.pickle
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:97c8ed74d091fcfd23498029bb819c29d096c3dcb1326edee5dfb0591ade2e4b
|
| 3 |
+
size 15313
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Subpackage containing all of pip's command line interface related code
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
# This file intentionally does not import submodules
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/autocompletion.cpython-310.pyc
ADDED
|
Binary file (5.43 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/command_context.cpython-310.pyc
ADDED
|
Binary file (1.3 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/parser.cpython-310.pyc
ADDED
|
Binary file (9.96 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/req_command.cpython-310.pyc
ADDED
|
Binary file (8.7 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/spinners.cpython-310.pyc
ADDED
|
Binary file (4.95 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/__pycache__/status_codes.cpython-310.pyc
ADDED
|
Binary file (338 Bytes). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/autocompletion.py
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Logic that powers autocompletion installed by ``pip completion``.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import optparse
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
from itertools import chain
|
| 8 |
+
from typing import Any, Iterable, List, Optional
|
| 9 |
+
|
| 10 |
+
from pip._internal.cli.main_parser import create_main_parser
|
| 11 |
+
from pip._internal.commands import commands_dict, create_command
|
| 12 |
+
from pip._internal.metadata import get_default_environment
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def autocomplete() -> None:
|
| 16 |
+
"""Entry Point for completion of main and subcommand options."""
|
| 17 |
+
# Don't complete if user hasn't sourced bash_completion file.
|
| 18 |
+
if "PIP_AUTO_COMPLETE" not in os.environ:
|
| 19 |
+
return
|
| 20 |
+
# Don't complete if autocompletion environment variables
|
| 21 |
+
# are not present
|
| 22 |
+
if not os.environ.get("COMP_WORDS") or not os.environ.get("COMP_CWORD"):
|
| 23 |
+
return
|
| 24 |
+
cwords = os.environ["COMP_WORDS"].split()[1:]
|
| 25 |
+
cword = int(os.environ["COMP_CWORD"])
|
| 26 |
+
try:
|
| 27 |
+
current = cwords[cword - 1]
|
| 28 |
+
except IndexError:
|
| 29 |
+
current = ""
|
| 30 |
+
|
| 31 |
+
parser = create_main_parser()
|
| 32 |
+
subcommands = list(commands_dict)
|
| 33 |
+
options = []
|
| 34 |
+
|
| 35 |
+
# subcommand
|
| 36 |
+
subcommand_name: Optional[str] = None
|
| 37 |
+
for word in cwords:
|
| 38 |
+
if word in subcommands:
|
| 39 |
+
subcommand_name = word
|
| 40 |
+
break
|
| 41 |
+
# subcommand options
|
| 42 |
+
if subcommand_name is not None:
|
| 43 |
+
# special case: 'help' subcommand has no options
|
| 44 |
+
if subcommand_name == "help":
|
| 45 |
+
sys.exit(1)
|
| 46 |
+
# special case: list locally installed dists for show and uninstall
|
| 47 |
+
should_list_installed = not current.startswith("-") and subcommand_name in [
|
| 48 |
+
"show",
|
| 49 |
+
"uninstall",
|
| 50 |
+
]
|
| 51 |
+
if should_list_installed:
|
| 52 |
+
env = get_default_environment()
|
| 53 |
+
lc = current.lower()
|
| 54 |
+
installed = [
|
| 55 |
+
dist.canonical_name
|
| 56 |
+
for dist in env.iter_installed_distributions(local_only=True)
|
| 57 |
+
if dist.canonical_name.startswith(lc)
|
| 58 |
+
and dist.canonical_name not in cwords[1:]
|
| 59 |
+
]
|
| 60 |
+
# if there are no dists installed, fall back to option completion
|
| 61 |
+
if installed:
|
| 62 |
+
for dist in installed:
|
| 63 |
+
print(dist)
|
| 64 |
+
sys.exit(1)
|
| 65 |
+
|
| 66 |
+
should_list_installables = (
|
| 67 |
+
not current.startswith("-") and subcommand_name == "install"
|
| 68 |
+
)
|
| 69 |
+
if should_list_installables:
|
| 70 |
+
for path in auto_complete_paths(current, "path"):
|
| 71 |
+
print(path)
|
| 72 |
+
sys.exit(1)
|
| 73 |
+
|
| 74 |
+
subcommand = create_command(subcommand_name)
|
| 75 |
+
|
| 76 |
+
for opt in subcommand.parser.option_list_all:
|
| 77 |
+
if opt.help != optparse.SUPPRESS_HELP:
|
| 78 |
+
options += [
|
| 79 |
+
(opt_str, opt.nargs) for opt_str in opt._long_opts + opt._short_opts
|
| 80 |
+
]
|
| 81 |
+
|
| 82 |
+
# filter out previously specified options from available options
|
| 83 |
+
prev_opts = [x.split("=")[0] for x in cwords[1 : cword - 1]]
|
| 84 |
+
options = [(x, v) for (x, v) in options if x not in prev_opts]
|
| 85 |
+
# filter options by current input
|
| 86 |
+
options = [(k, v) for k, v in options if k.startswith(current)]
|
| 87 |
+
# get completion type given cwords and available subcommand options
|
| 88 |
+
completion_type = get_path_completion_type(
|
| 89 |
+
cwords,
|
| 90 |
+
cword,
|
| 91 |
+
subcommand.parser.option_list_all,
|
| 92 |
+
)
|
| 93 |
+
# get completion files and directories if ``completion_type`` is
|
| 94 |
+
# ``<file>``, ``<dir>`` or ``<path>``
|
| 95 |
+
if completion_type:
|
| 96 |
+
paths = auto_complete_paths(current, completion_type)
|
| 97 |
+
options = [(path, 0) for path in paths]
|
| 98 |
+
for option in options:
|
| 99 |
+
opt_label = option[0]
|
| 100 |
+
# append '=' to options which require args
|
| 101 |
+
if option[1] and option[0][:2] == "--":
|
| 102 |
+
opt_label += "="
|
| 103 |
+
print(opt_label)
|
| 104 |
+
else:
|
| 105 |
+
# show main parser options only when necessary
|
| 106 |
+
|
| 107 |
+
opts = [i.option_list for i in parser.option_groups]
|
| 108 |
+
opts.append(parser.option_list)
|
| 109 |
+
flattened_opts = chain.from_iterable(opts)
|
| 110 |
+
if current.startswith("-"):
|
| 111 |
+
for opt in flattened_opts:
|
| 112 |
+
if opt.help != optparse.SUPPRESS_HELP:
|
| 113 |
+
subcommands += opt._long_opts + opt._short_opts
|
| 114 |
+
else:
|
| 115 |
+
# get completion type given cwords and all available options
|
| 116 |
+
completion_type = get_path_completion_type(cwords, cword, flattened_opts)
|
| 117 |
+
if completion_type:
|
| 118 |
+
subcommands = list(auto_complete_paths(current, completion_type))
|
| 119 |
+
|
| 120 |
+
print(" ".join([x for x in subcommands if x.startswith(current)]))
|
| 121 |
+
sys.exit(1)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def get_path_completion_type(
|
| 125 |
+
cwords: List[str], cword: int, opts: Iterable[Any]
|
| 126 |
+
) -> Optional[str]:
|
| 127 |
+
"""Get the type of path completion (``file``, ``dir``, ``path`` or None)
|
| 128 |
+
|
| 129 |
+
:param cwords: same as the environmental variable ``COMP_WORDS``
|
| 130 |
+
:param cword: same as the environmental variable ``COMP_CWORD``
|
| 131 |
+
:param opts: The available options to check
|
| 132 |
+
:return: path completion type (``file``, ``dir``, ``path`` or None)
|
| 133 |
+
"""
|
| 134 |
+
if cword < 2 or not cwords[cword - 2].startswith("-"):
|
| 135 |
+
return None
|
| 136 |
+
for opt in opts:
|
| 137 |
+
if opt.help == optparse.SUPPRESS_HELP:
|
| 138 |
+
continue
|
| 139 |
+
for o in str(opt).split("/"):
|
| 140 |
+
if cwords[cword - 2].split("=")[0] == o:
|
| 141 |
+
if not opt.metavar or any(
|
| 142 |
+
x in ("path", "file", "dir") for x in opt.metavar.split("/")
|
| 143 |
+
):
|
| 144 |
+
return opt.metavar
|
| 145 |
+
return None
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def auto_complete_paths(current: str, completion_type: str) -> Iterable[str]:
|
| 149 |
+
"""If ``completion_type`` is ``file`` or ``path``, list all regular files
|
| 150 |
+
and directories starting with ``current``; otherwise only list directories
|
| 151 |
+
starting with ``current``.
|
| 152 |
+
|
| 153 |
+
:param current: The word to be completed
|
| 154 |
+
:param completion_type: path completion type(``file``, ``path`` or ``dir``)
|
| 155 |
+
:return: A generator of regular files and/or directories
|
| 156 |
+
"""
|
| 157 |
+
directory, filename = os.path.split(current)
|
| 158 |
+
current_path = os.path.abspath(directory)
|
| 159 |
+
# Don't complete paths if they can't be accessed
|
| 160 |
+
if not os.access(current_path, os.R_OK):
|
| 161 |
+
return
|
| 162 |
+
filename = os.path.normcase(filename)
|
| 163 |
+
# list all files that start with ``filename``
|
| 164 |
+
file_list = (
|
| 165 |
+
x for x in os.listdir(current_path) if os.path.normcase(x).startswith(filename)
|
| 166 |
+
)
|
| 167 |
+
for f in file_list:
|
| 168 |
+
opt = os.path.join(current_path, f)
|
| 169 |
+
comp_file = os.path.normcase(os.path.join(directory, f))
|
| 170 |
+
# complete regular files when there is not ``<dir>`` after option
|
| 171 |
+
# complete directories when there is ``<file>``, ``<path>`` or
|
| 172 |
+
# ``<dir>``after option
|
| 173 |
+
if completion_type != "dir" and os.path.isfile(opt):
|
| 174 |
+
yield comp_file
|
| 175 |
+
elif os.path.isdir(opt):
|
| 176 |
+
yield os.path.join(comp_file, "")
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/base_command.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Base Command class, and related routines"""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import logging.config
|
| 5 |
+
import optparse
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
import traceback
|
| 9 |
+
from optparse import Values
|
| 10 |
+
from typing import List, Optional, Tuple
|
| 11 |
+
|
| 12 |
+
from pip._vendor.rich import reconfigure
|
| 13 |
+
from pip._vendor.rich import traceback as rich_traceback
|
| 14 |
+
|
| 15 |
+
from pip._internal.cli import cmdoptions
|
| 16 |
+
from pip._internal.cli.command_context import CommandContextMixIn
|
| 17 |
+
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
|
| 18 |
+
from pip._internal.cli.status_codes import (
|
| 19 |
+
ERROR,
|
| 20 |
+
PREVIOUS_BUILD_DIR_ERROR,
|
| 21 |
+
UNKNOWN_ERROR,
|
| 22 |
+
VIRTUALENV_NOT_FOUND,
|
| 23 |
+
)
|
| 24 |
+
from pip._internal.exceptions import (
|
| 25 |
+
BadCommand,
|
| 26 |
+
CommandError,
|
| 27 |
+
DiagnosticPipError,
|
| 28 |
+
InstallationError,
|
| 29 |
+
NetworkConnectionError,
|
| 30 |
+
PreviousBuildDirError,
|
| 31 |
+
)
|
| 32 |
+
from pip._internal.utils.deprecation import deprecated
|
| 33 |
+
from pip._internal.utils.filesystem import check_path_owner
|
| 34 |
+
from pip._internal.utils.logging import BrokenStdoutLoggingError, setup_logging
|
| 35 |
+
from pip._internal.utils.misc import get_prog, normalize_path
|
| 36 |
+
from pip._internal.utils.temp_dir import TempDirectoryTypeRegistry as TempDirRegistry
|
| 37 |
+
from pip._internal.utils.temp_dir import global_tempdir_manager, tempdir_registry
|
| 38 |
+
from pip._internal.utils.virtualenv import running_under_virtualenv
|
| 39 |
+
|
| 40 |
+
__all__ = ["Command"]
|
| 41 |
+
|
| 42 |
+
logger = logging.getLogger(__name__)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class Command(CommandContextMixIn):
|
| 46 |
+
usage: str = ""
|
| 47 |
+
ignore_require_venv: bool = False
|
| 48 |
+
|
| 49 |
+
def __init__(self, name: str, summary: str, isolated: bool = False) -> None:
|
| 50 |
+
super().__init__()
|
| 51 |
+
|
| 52 |
+
self.name = name
|
| 53 |
+
self.summary = summary
|
| 54 |
+
self.parser = ConfigOptionParser(
|
| 55 |
+
usage=self.usage,
|
| 56 |
+
prog=f"{get_prog()} {name}",
|
| 57 |
+
formatter=UpdatingDefaultsHelpFormatter(),
|
| 58 |
+
add_help_option=False,
|
| 59 |
+
name=name,
|
| 60 |
+
description=self.__doc__,
|
| 61 |
+
isolated=isolated,
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
self.tempdir_registry: Optional[TempDirRegistry] = None
|
| 65 |
+
|
| 66 |
+
# Commands should add options to this option group
|
| 67 |
+
optgroup_name = f"{self.name.capitalize()} Options"
|
| 68 |
+
self.cmd_opts = optparse.OptionGroup(self.parser, optgroup_name)
|
| 69 |
+
|
| 70 |
+
# Add the general options
|
| 71 |
+
gen_opts = cmdoptions.make_option_group(
|
| 72 |
+
cmdoptions.general_group,
|
| 73 |
+
self.parser,
|
| 74 |
+
)
|
| 75 |
+
self.parser.add_option_group(gen_opts)
|
| 76 |
+
|
| 77 |
+
self.add_options()
|
| 78 |
+
|
| 79 |
+
def add_options(self) -> None:
|
| 80 |
+
pass
|
| 81 |
+
|
| 82 |
+
def handle_pip_version_check(self, options: Values) -> None:
|
| 83 |
+
"""
|
| 84 |
+
This is a no-op so that commands by default do not do the pip version
|
| 85 |
+
check.
|
| 86 |
+
"""
|
| 87 |
+
# Make sure we do the pip version check if the index_group options
|
| 88 |
+
# are present.
|
| 89 |
+
assert not hasattr(options, "no_index")
|
| 90 |
+
|
| 91 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 92 |
+
raise NotImplementedError
|
| 93 |
+
|
| 94 |
+
def _run_wrapper(self, level_number: int, options: Values, args: List[str]) -> int:
|
| 95 |
+
def _inner_run() -> int:
|
| 96 |
+
try:
|
| 97 |
+
return self.run(options, args)
|
| 98 |
+
finally:
|
| 99 |
+
self.handle_pip_version_check(options)
|
| 100 |
+
|
| 101 |
+
if options.debug_mode:
|
| 102 |
+
rich_traceback.install(show_locals=True)
|
| 103 |
+
return _inner_run()
|
| 104 |
+
|
| 105 |
+
try:
|
| 106 |
+
status = _inner_run()
|
| 107 |
+
assert isinstance(status, int)
|
| 108 |
+
return status
|
| 109 |
+
except DiagnosticPipError as exc:
|
| 110 |
+
logger.error("%s", exc, extra={"rich": True})
|
| 111 |
+
logger.debug("Exception information:", exc_info=True)
|
| 112 |
+
|
| 113 |
+
return ERROR
|
| 114 |
+
except PreviousBuildDirError as exc:
|
| 115 |
+
logger.critical(str(exc))
|
| 116 |
+
logger.debug("Exception information:", exc_info=True)
|
| 117 |
+
|
| 118 |
+
return PREVIOUS_BUILD_DIR_ERROR
|
| 119 |
+
except (
|
| 120 |
+
InstallationError,
|
| 121 |
+
BadCommand,
|
| 122 |
+
NetworkConnectionError,
|
| 123 |
+
) as exc:
|
| 124 |
+
logger.critical(str(exc))
|
| 125 |
+
logger.debug("Exception information:", exc_info=True)
|
| 126 |
+
|
| 127 |
+
return ERROR
|
| 128 |
+
except CommandError as exc:
|
| 129 |
+
logger.critical("%s", exc)
|
| 130 |
+
logger.debug("Exception information:", exc_info=True)
|
| 131 |
+
|
| 132 |
+
return ERROR
|
| 133 |
+
except BrokenStdoutLoggingError:
|
| 134 |
+
# Bypass our logger and write any remaining messages to
|
| 135 |
+
# stderr because stdout no longer works.
|
| 136 |
+
print("ERROR: Pipe to stdout was broken", file=sys.stderr)
|
| 137 |
+
if level_number <= logging.DEBUG:
|
| 138 |
+
traceback.print_exc(file=sys.stderr)
|
| 139 |
+
|
| 140 |
+
return ERROR
|
| 141 |
+
except KeyboardInterrupt:
|
| 142 |
+
logger.critical("Operation cancelled by user")
|
| 143 |
+
logger.debug("Exception information:", exc_info=True)
|
| 144 |
+
|
| 145 |
+
return ERROR
|
| 146 |
+
except BaseException:
|
| 147 |
+
logger.critical("Exception:", exc_info=True)
|
| 148 |
+
|
| 149 |
+
return UNKNOWN_ERROR
|
| 150 |
+
|
| 151 |
+
def parse_args(self, args: List[str]) -> Tuple[Values, List[str]]:
|
| 152 |
+
# factored out for testability
|
| 153 |
+
return self.parser.parse_args(args)
|
| 154 |
+
|
| 155 |
+
def main(self, args: List[str]) -> int:
|
| 156 |
+
try:
|
| 157 |
+
with self.main_context():
|
| 158 |
+
return self._main(args)
|
| 159 |
+
finally:
|
| 160 |
+
logging.shutdown()
|
| 161 |
+
|
| 162 |
+
def _main(self, args: List[str]) -> int:
|
| 163 |
+
# We must initialize this before the tempdir manager, otherwise the
|
| 164 |
+
# configuration would not be accessible by the time we clean up the
|
| 165 |
+
# tempdir manager.
|
| 166 |
+
self.tempdir_registry = self.enter_context(tempdir_registry())
|
| 167 |
+
# Intentionally set as early as possible so globally-managed temporary
|
| 168 |
+
# directories are available to the rest of the code.
|
| 169 |
+
self.enter_context(global_tempdir_manager())
|
| 170 |
+
|
| 171 |
+
options, args = self.parse_args(args)
|
| 172 |
+
|
| 173 |
+
# Set verbosity so that it can be used elsewhere.
|
| 174 |
+
self.verbosity = options.verbose - options.quiet
|
| 175 |
+
|
| 176 |
+
reconfigure(no_color=options.no_color)
|
| 177 |
+
level_number = setup_logging(
|
| 178 |
+
verbosity=self.verbosity,
|
| 179 |
+
no_color=options.no_color,
|
| 180 |
+
user_log_file=options.log,
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
always_enabled_features = set(options.features_enabled) & set(
|
| 184 |
+
cmdoptions.ALWAYS_ENABLED_FEATURES
|
| 185 |
+
)
|
| 186 |
+
if always_enabled_features:
|
| 187 |
+
logger.warning(
|
| 188 |
+
"The following features are always enabled: %s. ",
|
| 189 |
+
", ".join(sorted(always_enabled_features)),
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
# Make sure that the --python argument isn't specified after the
|
| 193 |
+
# subcommand. We can tell, because if --python was specified,
|
| 194 |
+
# we should only reach this point if we're running in the created
|
| 195 |
+
# subprocess, which has the _PIP_RUNNING_IN_SUBPROCESS environment
|
| 196 |
+
# variable set.
|
| 197 |
+
if options.python and "_PIP_RUNNING_IN_SUBPROCESS" not in os.environ:
|
| 198 |
+
logger.critical(
|
| 199 |
+
"The --python option must be placed before the pip subcommand name"
|
| 200 |
+
)
|
| 201 |
+
sys.exit(ERROR)
|
| 202 |
+
|
| 203 |
+
# TODO: Try to get these passing down from the command?
|
| 204 |
+
# without resorting to os.environ to hold these.
|
| 205 |
+
# This also affects isolated builds and it should.
|
| 206 |
+
|
| 207 |
+
if options.no_input:
|
| 208 |
+
os.environ["PIP_NO_INPUT"] = "1"
|
| 209 |
+
|
| 210 |
+
if options.exists_action:
|
| 211 |
+
os.environ["PIP_EXISTS_ACTION"] = " ".join(options.exists_action)
|
| 212 |
+
|
| 213 |
+
if options.require_venv and not self.ignore_require_venv:
|
| 214 |
+
# If a venv is required check if it can really be found
|
| 215 |
+
if not running_under_virtualenv():
|
| 216 |
+
logger.critical("Could not find an activated virtualenv (required).")
|
| 217 |
+
sys.exit(VIRTUALENV_NOT_FOUND)
|
| 218 |
+
|
| 219 |
+
if options.cache_dir:
|
| 220 |
+
options.cache_dir = normalize_path(options.cache_dir)
|
| 221 |
+
if not check_path_owner(options.cache_dir):
|
| 222 |
+
logger.warning(
|
| 223 |
+
"The directory '%s' or its parent directory is not owned "
|
| 224 |
+
"or is not writable by the current user. The cache "
|
| 225 |
+
"has been disabled. Check the permissions and owner of "
|
| 226 |
+
"that directory. If executing pip with sudo, you should "
|
| 227 |
+
"use sudo's -H flag.",
|
| 228 |
+
options.cache_dir,
|
| 229 |
+
)
|
| 230 |
+
options.cache_dir = None
|
| 231 |
+
|
| 232 |
+
if options.no_python_version_warning:
|
| 233 |
+
deprecated(
|
| 234 |
+
reason="--no-python-version-warning is deprecated.",
|
| 235 |
+
replacement="to remove the flag as it's a no-op",
|
| 236 |
+
gone_in="25.1",
|
| 237 |
+
issue=13154,
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
return self._run_wrapper(level_number, options, args)
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/cmdoptions.py
ADDED
|
@@ -0,0 +1,1075 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
shared options and groups
|
| 3 |
+
|
| 4 |
+
The principle here is to define options once, but *not* instantiate them
|
| 5 |
+
globally. One reason being that options with action='append' can carry state
|
| 6 |
+
between parses. pip parses general options twice internally, and shouldn't
|
| 7 |
+
pass on state. To be consistent, all options will follow this design.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
# The following comment should be removed at some point in the future.
|
| 11 |
+
# mypy: strict-optional=False
|
| 12 |
+
|
| 13 |
+
import importlib.util
|
| 14 |
+
import logging
|
| 15 |
+
import os
|
| 16 |
+
import textwrap
|
| 17 |
+
from functools import partial
|
| 18 |
+
from optparse import SUPPRESS_HELP, Option, OptionGroup, OptionParser, Values
|
| 19 |
+
from textwrap import dedent
|
| 20 |
+
from typing import Any, Callable, Dict, Optional, Tuple
|
| 21 |
+
|
| 22 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 23 |
+
|
| 24 |
+
from pip._internal.cli.parser import ConfigOptionParser
|
| 25 |
+
from pip._internal.exceptions import CommandError
|
| 26 |
+
from pip._internal.locations import USER_CACHE_DIR, get_src_prefix
|
| 27 |
+
from pip._internal.models.format_control import FormatControl
|
| 28 |
+
from pip._internal.models.index import PyPI
|
| 29 |
+
from pip._internal.models.target_python import TargetPython
|
| 30 |
+
from pip._internal.utils.hashes import STRONG_HASHES
|
| 31 |
+
from pip._internal.utils.misc import strtobool
|
| 32 |
+
|
| 33 |
+
logger = logging.getLogger(__name__)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def raise_option_error(parser: OptionParser, option: Option, msg: str) -> None:
|
| 37 |
+
"""
|
| 38 |
+
Raise an option parsing error using parser.error().
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
parser: an OptionParser instance.
|
| 42 |
+
option: an Option instance.
|
| 43 |
+
msg: the error text.
|
| 44 |
+
"""
|
| 45 |
+
msg = f"{option} error: {msg}"
|
| 46 |
+
msg = textwrap.fill(" ".join(msg.split()))
|
| 47 |
+
parser.error(msg)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def make_option_group(group: Dict[str, Any], parser: ConfigOptionParser) -> OptionGroup:
|
| 51 |
+
"""
|
| 52 |
+
Return an OptionGroup object
|
| 53 |
+
group -- assumed to be dict with 'name' and 'options' keys
|
| 54 |
+
parser -- an optparse Parser
|
| 55 |
+
"""
|
| 56 |
+
option_group = OptionGroup(parser, group["name"])
|
| 57 |
+
for option in group["options"]:
|
| 58 |
+
option_group.add_option(option())
|
| 59 |
+
return option_group
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def check_dist_restriction(options: Values, check_target: bool = False) -> None:
|
| 63 |
+
"""Function for determining if custom platform options are allowed.
|
| 64 |
+
|
| 65 |
+
:param options: The OptionParser options.
|
| 66 |
+
:param check_target: Whether or not to check if --target is being used.
|
| 67 |
+
"""
|
| 68 |
+
dist_restriction_set = any(
|
| 69 |
+
[
|
| 70 |
+
options.python_version,
|
| 71 |
+
options.platforms,
|
| 72 |
+
options.abis,
|
| 73 |
+
options.implementation,
|
| 74 |
+
]
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
binary_only = FormatControl(set(), {":all:"})
|
| 78 |
+
sdist_dependencies_allowed = (
|
| 79 |
+
options.format_control != binary_only and not options.ignore_dependencies
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
# Installations or downloads using dist restrictions must not combine
|
| 83 |
+
# source distributions and dist-specific wheels, as they are not
|
| 84 |
+
# guaranteed to be locally compatible.
|
| 85 |
+
if dist_restriction_set and sdist_dependencies_allowed:
|
| 86 |
+
raise CommandError(
|
| 87 |
+
"When restricting platform and interpreter constraints using "
|
| 88 |
+
"--python-version, --platform, --abi, or --implementation, "
|
| 89 |
+
"either --no-deps must be set, or --only-binary=:all: must be "
|
| 90 |
+
"set and --no-binary must not be set (or must be set to "
|
| 91 |
+
":none:)."
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
if check_target:
|
| 95 |
+
if not options.dry_run and dist_restriction_set and not options.target_dir:
|
| 96 |
+
raise CommandError(
|
| 97 |
+
"Can not use any platform or abi specific options unless "
|
| 98 |
+
"installing via '--target' or using '--dry-run'"
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def _path_option_check(option: Option, opt: str, value: str) -> str:
|
| 103 |
+
return os.path.expanduser(value)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def _package_name_option_check(option: Option, opt: str, value: str) -> str:
|
| 107 |
+
return canonicalize_name(value)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
class PipOption(Option):
|
| 111 |
+
TYPES = Option.TYPES + ("path", "package_name")
|
| 112 |
+
TYPE_CHECKER = Option.TYPE_CHECKER.copy()
|
| 113 |
+
TYPE_CHECKER["package_name"] = _package_name_option_check
|
| 114 |
+
TYPE_CHECKER["path"] = _path_option_check
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
###########
|
| 118 |
+
# options #
|
| 119 |
+
###########
|
| 120 |
+
|
| 121 |
+
help_: Callable[..., Option] = partial(
|
| 122 |
+
Option,
|
| 123 |
+
"-h",
|
| 124 |
+
"--help",
|
| 125 |
+
dest="help",
|
| 126 |
+
action="help",
|
| 127 |
+
help="Show help.",
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
debug_mode: Callable[..., Option] = partial(
|
| 131 |
+
Option,
|
| 132 |
+
"--debug",
|
| 133 |
+
dest="debug_mode",
|
| 134 |
+
action="store_true",
|
| 135 |
+
default=False,
|
| 136 |
+
help=(
|
| 137 |
+
"Let unhandled exceptions propagate outside the main subroutine, "
|
| 138 |
+
"instead of logging them to stderr."
|
| 139 |
+
),
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
isolated_mode: Callable[..., Option] = partial(
|
| 143 |
+
Option,
|
| 144 |
+
"--isolated",
|
| 145 |
+
dest="isolated_mode",
|
| 146 |
+
action="store_true",
|
| 147 |
+
default=False,
|
| 148 |
+
help=(
|
| 149 |
+
"Run pip in an isolated mode, ignoring environment variables and user "
|
| 150 |
+
"configuration."
|
| 151 |
+
),
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
require_virtualenv: Callable[..., Option] = partial(
|
| 155 |
+
Option,
|
| 156 |
+
"--require-virtualenv",
|
| 157 |
+
"--require-venv",
|
| 158 |
+
dest="require_venv",
|
| 159 |
+
action="store_true",
|
| 160 |
+
default=False,
|
| 161 |
+
help=(
|
| 162 |
+
"Allow pip to only run in a virtual environment; "
|
| 163 |
+
"exit with an error otherwise."
|
| 164 |
+
),
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
override_externally_managed: Callable[..., Option] = partial(
|
| 168 |
+
Option,
|
| 169 |
+
"--break-system-packages",
|
| 170 |
+
dest="override_externally_managed",
|
| 171 |
+
action="store_true",
|
| 172 |
+
help="Allow pip to modify an EXTERNALLY-MANAGED Python installation",
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
python: Callable[..., Option] = partial(
|
| 176 |
+
Option,
|
| 177 |
+
"--python",
|
| 178 |
+
dest="python",
|
| 179 |
+
help="Run pip with the specified Python interpreter.",
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
verbose: Callable[..., Option] = partial(
|
| 183 |
+
Option,
|
| 184 |
+
"-v",
|
| 185 |
+
"--verbose",
|
| 186 |
+
dest="verbose",
|
| 187 |
+
action="count",
|
| 188 |
+
default=0,
|
| 189 |
+
help="Give more output. Option is additive, and can be used up to 3 times.",
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
no_color: Callable[..., Option] = partial(
|
| 193 |
+
Option,
|
| 194 |
+
"--no-color",
|
| 195 |
+
dest="no_color",
|
| 196 |
+
action="store_true",
|
| 197 |
+
default=False,
|
| 198 |
+
help="Suppress colored output.",
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
version: Callable[..., Option] = partial(
|
| 202 |
+
Option,
|
| 203 |
+
"-V",
|
| 204 |
+
"--version",
|
| 205 |
+
dest="version",
|
| 206 |
+
action="store_true",
|
| 207 |
+
help="Show version and exit.",
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
quiet: Callable[..., Option] = partial(
|
| 211 |
+
Option,
|
| 212 |
+
"-q",
|
| 213 |
+
"--quiet",
|
| 214 |
+
dest="quiet",
|
| 215 |
+
action="count",
|
| 216 |
+
default=0,
|
| 217 |
+
help=(
|
| 218 |
+
"Give less output. Option is additive, and can be used up to 3"
|
| 219 |
+
" times (corresponding to WARNING, ERROR, and CRITICAL logging"
|
| 220 |
+
" levels)."
|
| 221 |
+
),
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
progress_bar: Callable[..., Option] = partial(
|
| 225 |
+
Option,
|
| 226 |
+
"--progress-bar",
|
| 227 |
+
dest="progress_bar",
|
| 228 |
+
type="choice",
|
| 229 |
+
choices=["on", "off", "raw"],
|
| 230 |
+
default="on",
|
| 231 |
+
help="Specify whether the progress bar should be used [on, off, raw] (default: on)",
|
| 232 |
+
)
|
| 233 |
+
|
| 234 |
+
log: Callable[..., Option] = partial(
|
| 235 |
+
PipOption,
|
| 236 |
+
"--log",
|
| 237 |
+
"--log-file",
|
| 238 |
+
"--local-log",
|
| 239 |
+
dest="log",
|
| 240 |
+
metavar="path",
|
| 241 |
+
type="path",
|
| 242 |
+
help="Path to a verbose appending log.",
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
no_input: Callable[..., Option] = partial(
|
| 246 |
+
Option,
|
| 247 |
+
# Don't ask for input
|
| 248 |
+
"--no-input",
|
| 249 |
+
dest="no_input",
|
| 250 |
+
action="store_true",
|
| 251 |
+
default=False,
|
| 252 |
+
help="Disable prompting for input.",
|
| 253 |
+
)
|
| 254 |
+
|
| 255 |
+
keyring_provider: Callable[..., Option] = partial(
|
| 256 |
+
Option,
|
| 257 |
+
"--keyring-provider",
|
| 258 |
+
dest="keyring_provider",
|
| 259 |
+
choices=["auto", "disabled", "import", "subprocess"],
|
| 260 |
+
default="auto",
|
| 261 |
+
help=(
|
| 262 |
+
"Enable the credential lookup via the keyring library if user input is allowed."
|
| 263 |
+
" Specify which mechanism to use [auto, disabled, import, subprocess]."
|
| 264 |
+
" (default: %default)"
|
| 265 |
+
),
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
proxy: Callable[..., Option] = partial(
|
| 269 |
+
Option,
|
| 270 |
+
"--proxy",
|
| 271 |
+
dest="proxy",
|
| 272 |
+
type="str",
|
| 273 |
+
default="",
|
| 274 |
+
help="Specify a proxy in the form scheme://[user:passwd@]proxy.server:port.",
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
retries: Callable[..., Option] = partial(
|
| 278 |
+
Option,
|
| 279 |
+
"--retries",
|
| 280 |
+
dest="retries",
|
| 281 |
+
type="int",
|
| 282 |
+
default=5,
|
| 283 |
+
help="Maximum number of retries each connection should attempt "
|
| 284 |
+
"(default %default times).",
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
timeout: Callable[..., Option] = partial(
|
| 288 |
+
Option,
|
| 289 |
+
"--timeout",
|
| 290 |
+
"--default-timeout",
|
| 291 |
+
metavar="sec",
|
| 292 |
+
dest="timeout",
|
| 293 |
+
type="float",
|
| 294 |
+
default=15,
|
| 295 |
+
help="Set the socket timeout (default %default seconds).",
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def exists_action() -> Option:
|
| 300 |
+
return Option(
|
| 301 |
+
# Option when path already exist
|
| 302 |
+
"--exists-action",
|
| 303 |
+
dest="exists_action",
|
| 304 |
+
type="choice",
|
| 305 |
+
choices=["s", "i", "w", "b", "a"],
|
| 306 |
+
default=[],
|
| 307 |
+
action="append",
|
| 308 |
+
metavar="action",
|
| 309 |
+
help="Default action when a path already exists: "
|
| 310 |
+
"(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.",
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
cert: Callable[..., Option] = partial(
|
| 315 |
+
PipOption,
|
| 316 |
+
"--cert",
|
| 317 |
+
dest="cert",
|
| 318 |
+
type="path",
|
| 319 |
+
metavar="path",
|
| 320 |
+
help=(
|
| 321 |
+
"Path to PEM-encoded CA certificate bundle. "
|
| 322 |
+
"If provided, overrides the default. "
|
| 323 |
+
"See 'SSL Certificate Verification' in pip documentation "
|
| 324 |
+
"for more information."
|
| 325 |
+
),
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
client_cert: Callable[..., Option] = partial(
|
| 329 |
+
PipOption,
|
| 330 |
+
"--client-cert",
|
| 331 |
+
dest="client_cert",
|
| 332 |
+
type="path",
|
| 333 |
+
default=None,
|
| 334 |
+
metavar="path",
|
| 335 |
+
help="Path to SSL client certificate, a single file containing the "
|
| 336 |
+
"private key and the certificate in PEM format.",
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
index_url: Callable[..., Option] = partial(
|
| 340 |
+
Option,
|
| 341 |
+
"-i",
|
| 342 |
+
"--index-url",
|
| 343 |
+
"--pypi-url",
|
| 344 |
+
dest="index_url",
|
| 345 |
+
metavar="URL",
|
| 346 |
+
default=PyPI.simple_url,
|
| 347 |
+
help="Base URL of the Python Package Index (default %default). "
|
| 348 |
+
"This should point to a repository compliant with PEP 503 "
|
| 349 |
+
"(the simple repository API) or a local directory laid out "
|
| 350 |
+
"in the same format.",
|
| 351 |
+
)
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
def extra_index_url() -> Option:
|
| 355 |
+
return Option(
|
| 356 |
+
"--extra-index-url",
|
| 357 |
+
dest="extra_index_urls",
|
| 358 |
+
metavar="URL",
|
| 359 |
+
action="append",
|
| 360 |
+
default=[],
|
| 361 |
+
help="Extra URLs of package indexes to use in addition to "
|
| 362 |
+
"--index-url. Should follow the same rules as "
|
| 363 |
+
"--index-url.",
|
| 364 |
+
)
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
no_index: Callable[..., Option] = partial(
|
| 368 |
+
Option,
|
| 369 |
+
"--no-index",
|
| 370 |
+
dest="no_index",
|
| 371 |
+
action="store_true",
|
| 372 |
+
default=False,
|
| 373 |
+
help="Ignore package index (only looking at --find-links URLs instead).",
|
| 374 |
+
)
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def find_links() -> Option:
|
| 378 |
+
return Option(
|
| 379 |
+
"-f",
|
| 380 |
+
"--find-links",
|
| 381 |
+
dest="find_links",
|
| 382 |
+
action="append",
|
| 383 |
+
default=[],
|
| 384 |
+
metavar="url",
|
| 385 |
+
help="If a URL or path to an html file, then parse for links to "
|
| 386 |
+
"archives such as sdist (.tar.gz) or wheel (.whl) files. "
|
| 387 |
+
"If a local path or file:// URL that's a directory, "
|
| 388 |
+
"then look for archives in the directory listing. "
|
| 389 |
+
"Links to VCS project URLs are not supported.",
|
| 390 |
+
)
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
def trusted_host() -> Option:
|
| 394 |
+
return Option(
|
| 395 |
+
"--trusted-host",
|
| 396 |
+
dest="trusted_hosts",
|
| 397 |
+
action="append",
|
| 398 |
+
metavar="HOSTNAME",
|
| 399 |
+
default=[],
|
| 400 |
+
help="Mark this host or host:port pair as trusted, even though it "
|
| 401 |
+
"does not have valid or any HTTPS.",
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def constraints() -> Option:
|
| 406 |
+
return Option(
|
| 407 |
+
"-c",
|
| 408 |
+
"--constraint",
|
| 409 |
+
dest="constraints",
|
| 410 |
+
action="append",
|
| 411 |
+
default=[],
|
| 412 |
+
metavar="file",
|
| 413 |
+
help="Constrain versions using the given constraints file. "
|
| 414 |
+
"This option can be used multiple times.",
|
| 415 |
+
)
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
def requirements() -> Option:
|
| 419 |
+
return Option(
|
| 420 |
+
"-r",
|
| 421 |
+
"--requirement",
|
| 422 |
+
dest="requirements",
|
| 423 |
+
action="append",
|
| 424 |
+
default=[],
|
| 425 |
+
metavar="file",
|
| 426 |
+
help="Install from the given requirements file. "
|
| 427 |
+
"This option can be used multiple times.",
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
def editable() -> Option:
|
| 432 |
+
return Option(
|
| 433 |
+
"-e",
|
| 434 |
+
"--editable",
|
| 435 |
+
dest="editables",
|
| 436 |
+
action="append",
|
| 437 |
+
default=[],
|
| 438 |
+
metavar="path/url",
|
| 439 |
+
help=(
|
| 440 |
+
"Install a project in editable mode (i.e. setuptools "
|
| 441 |
+
'"develop mode") from a local project path or a VCS url.'
|
| 442 |
+
),
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
def _handle_src(option: Option, opt_str: str, value: str, parser: OptionParser) -> None:
|
| 447 |
+
value = os.path.abspath(value)
|
| 448 |
+
setattr(parser.values, option.dest, value)
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
src: Callable[..., Option] = partial(
|
| 452 |
+
PipOption,
|
| 453 |
+
"--src",
|
| 454 |
+
"--source",
|
| 455 |
+
"--source-dir",
|
| 456 |
+
"--source-directory",
|
| 457 |
+
dest="src_dir",
|
| 458 |
+
type="path",
|
| 459 |
+
metavar="dir",
|
| 460 |
+
default=get_src_prefix(),
|
| 461 |
+
action="callback",
|
| 462 |
+
callback=_handle_src,
|
| 463 |
+
help="Directory to check out editable projects into. "
|
| 464 |
+
'The default in a virtualenv is "<venv path>/src". '
|
| 465 |
+
'The default for global installs is "<current dir>/src".',
|
| 466 |
+
)
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
def _get_format_control(values: Values, option: Option) -> Any:
|
| 470 |
+
"""Get a format_control object."""
|
| 471 |
+
return getattr(values, option.dest)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
def _handle_no_binary(
|
| 475 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 476 |
+
) -> None:
|
| 477 |
+
existing = _get_format_control(parser.values, option)
|
| 478 |
+
FormatControl.handle_mutual_excludes(
|
| 479 |
+
value,
|
| 480 |
+
existing.no_binary,
|
| 481 |
+
existing.only_binary,
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
def _handle_only_binary(
|
| 486 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 487 |
+
) -> None:
|
| 488 |
+
existing = _get_format_control(parser.values, option)
|
| 489 |
+
FormatControl.handle_mutual_excludes(
|
| 490 |
+
value,
|
| 491 |
+
existing.only_binary,
|
| 492 |
+
existing.no_binary,
|
| 493 |
+
)
|
| 494 |
+
|
| 495 |
+
|
| 496 |
+
def no_binary() -> Option:
|
| 497 |
+
format_control = FormatControl(set(), set())
|
| 498 |
+
return Option(
|
| 499 |
+
"--no-binary",
|
| 500 |
+
dest="format_control",
|
| 501 |
+
action="callback",
|
| 502 |
+
callback=_handle_no_binary,
|
| 503 |
+
type="str",
|
| 504 |
+
default=format_control,
|
| 505 |
+
help="Do not use binary packages. Can be supplied multiple times, and "
|
| 506 |
+
'each time adds to the existing value. Accepts either ":all:" to '
|
| 507 |
+
'disable all binary packages, ":none:" to empty the set (notice '
|
| 508 |
+
"the colons), or one or more package names with commas between "
|
| 509 |
+
"them (no colons). Note that some packages are tricky to compile "
|
| 510 |
+
"and may fail to install when this option is used on them.",
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
def only_binary() -> Option:
|
| 515 |
+
format_control = FormatControl(set(), set())
|
| 516 |
+
return Option(
|
| 517 |
+
"--only-binary",
|
| 518 |
+
dest="format_control",
|
| 519 |
+
action="callback",
|
| 520 |
+
callback=_handle_only_binary,
|
| 521 |
+
type="str",
|
| 522 |
+
default=format_control,
|
| 523 |
+
help="Do not use source packages. Can be supplied multiple times, and "
|
| 524 |
+
'each time adds to the existing value. Accepts either ":all:" to '
|
| 525 |
+
'disable all source packages, ":none:" to empty the set, or one '
|
| 526 |
+
"or more package names with commas between them. Packages "
|
| 527 |
+
"without binary distributions will fail to install when this "
|
| 528 |
+
"option is used on them.",
|
| 529 |
+
)
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
platforms: Callable[..., Option] = partial(
|
| 533 |
+
Option,
|
| 534 |
+
"--platform",
|
| 535 |
+
dest="platforms",
|
| 536 |
+
metavar="platform",
|
| 537 |
+
action="append",
|
| 538 |
+
default=None,
|
| 539 |
+
help=(
|
| 540 |
+
"Only use wheels compatible with <platform>. Defaults to the "
|
| 541 |
+
"platform of the running system. Use this option multiple times to "
|
| 542 |
+
"specify multiple platforms supported by the target interpreter."
|
| 543 |
+
),
|
| 544 |
+
)
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
# This was made a separate function for unit-testing purposes.
|
| 548 |
+
def _convert_python_version(value: str) -> Tuple[Tuple[int, ...], Optional[str]]:
|
| 549 |
+
"""
|
| 550 |
+
Convert a version string like "3", "37", or "3.7.3" into a tuple of ints.
|
| 551 |
+
|
| 552 |
+
:return: A 2-tuple (version_info, error_msg), where `error_msg` is
|
| 553 |
+
non-None if and only if there was a parsing error.
|
| 554 |
+
"""
|
| 555 |
+
if not value:
|
| 556 |
+
# The empty string is the same as not providing a value.
|
| 557 |
+
return (None, None)
|
| 558 |
+
|
| 559 |
+
parts = value.split(".")
|
| 560 |
+
if len(parts) > 3:
|
| 561 |
+
return ((), "at most three version parts are allowed")
|
| 562 |
+
|
| 563 |
+
if len(parts) == 1:
|
| 564 |
+
# Then we are in the case of "3" or "37".
|
| 565 |
+
value = parts[0]
|
| 566 |
+
if len(value) > 1:
|
| 567 |
+
parts = [value[0], value[1:]]
|
| 568 |
+
|
| 569 |
+
try:
|
| 570 |
+
version_info = tuple(int(part) for part in parts)
|
| 571 |
+
except ValueError:
|
| 572 |
+
return ((), "each version part must be an integer")
|
| 573 |
+
|
| 574 |
+
return (version_info, None)
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
def _handle_python_version(
|
| 578 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 579 |
+
) -> None:
|
| 580 |
+
"""
|
| 581 |
+
Handle a provided --python-version value.
|
| 582 |
+
"""
|
| 583 |
+
version_info, error_msg = _convert_python_version(value)
|
| 584 |
+
if error_msg is not None:
|
| 585 |
+
msg = f"invalid --python-version value: {value!r}: {error_msg}"
|
| 586 |
+
raise_option_error(parser, option=option, msg=msg)
|
| 587 |
+
|
| 588 |
+
parser.values.python_version = version_info
|
| 589 |
+
|
| 590 |
+
|
| 591 |
+
python_version: Callable[..., Option] = partial(
|
| 592 |
+
Option,
|
| 593 |
+
"--python-version",
|
| 594 |
+
dest="python_version",
|
| 595 |
+
metavar="python_version",
|
| 596 |
+
action="callback",
|
| 597 |
+
callback=_handle_python_version,
|
| 598 |
+
type="str",
|
| 599 |
+
default=None,
|
| 600 |
+
help=dedent(
|
| 601 |
+
"""\
|
| 602 |
+
The Python interpreter version to use for wheel and "Requires-Python"
|
| 603 |
+
compatibility checks. Defaults to a version derived from the running
|
| 604 |
+
interpreter. The version can be specified using up to three dot-separated
|
| 605 |
+
integers (e.g. "3" for 3.0.0, "3.7" for 3.7.0, or "3.7.3"). A major-minor
|
| 606 |
+
version can also be given as a string without dots (e.g. "37" for 3.7.0).
|
| 607 |
+
"""
|
| 608 |
+
),
|
| 609 |
+
)
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
implementation: Callable[..., Option] = partial(
|
| 613 |
+
Option,
|
| 614 |
+
"--implementation",
|
| 615 |
+
dest="implementation",
|
| 616 |
+
metavar="implementation",
|
| 617 |
+
default=None,
|
| 618 |
+
help=(
|
| 619 |
+
"Only use wheels compatible with Python "
|
| 620 |
+
"implementation <implementation>, e.g. 'pp', 'jy', 'cp', "
|
| 621 |
+
" or 'ip'. If not specified, then the current "
|
| 622 |
+
"interpreter implementation is used. Use 'py' to force "
|
| 623 |
+
"implementation-agnostic wheels."
|
| 624 |
+
),
|
| 625 |
+
)
|
| 626 |
+
|
| 627 |
+
|
| 628 |
+
abis: Callable[..., Option] = partial(
|
| 629 |
+
Option,
|
| 630 |
+
"--abi",
|
| 631 |
+
dest="abis",
|
| 632 |
+
metavar="abi",
|
| 633 |
+
action="append",
|
| 634 |
+
default=None,
|
| 635 |
+
help=(
|
| 636 |
+
"Only use wheels compatible with Python abi <abi>, e.g. 'pypy_41'. "
|
| 637 |
+
"If not specified, then the current interpreter abi tag is used. "
|
| 638 |
+
"Use this option multiple times to specify multiple abis supported "
|
| 639 |
+
"by the target interpreter. Generally you will need to specify "
|
| 640 |
+
"--implementation, --platform, and --python-version when using this "
|
| 641 |
+
"option."
|
| 642 |
+
),
|
| 643 |
+
)
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
def add_target_python_options(cmd_opts: OptionGroup) -> None:
|
| 647 |
+
cmd_opts.add_option(platforms())
|
| 648 |
+
cmd_opts.add_option(python_version())
|
| 649 |
+
cmd_opts.add_option(implementation())
|
| 650 |
+
cmd_opts.add_option(abis())
|
| 651 |
+
|
| 652 |
+
|
| 653 |
+
def make_target_python(options: Values) -> TargetPython:
|
| 654 |
+
target_python = TargetPython(
|
| 655 |
+
platforms=options.platforms,
|
| 656 |
+
py_version_info=options.python_version,
|
| 657 |
+
abis=options.abis,
|
| 658 |
+
implementation=options.implementation,
|
| 659 |
+
)
|
| 660 |
+
|
| 661 |
+
return target_python
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
def prefer_binary() -> Option:
|
| 665 |
+
return Option(
|
| 666 |
+
"--prefer-binary",
|
| 667 |
+
dest="prefer_binary",
|
| 668 |
+
action="store_true",
|
| 669 |
+
default=False,
|
| 670 |
+
help=(
|
| 671 |
+
"Prefer binary packages over source packages, even if the "
|
| 672 |
+
"source packages are newer."
|
| 673 |
+
),
|
| 674 |
+
)
|
| 675 |
+
|
| 676 |
+
|
| 677 |
+
cache_dir: Callable[..., Option] = partial(
|
| 678 |
+
PipOption,
|
| 679 |
+
"--cache-dir",
|
| 680 |
+
dest="cache_dir",
|
| 681 |
+
default=USER_CACHE_DIR,
|
| 682 |
+
metavar="dir",
|
| 683 |
+
type="path",
|
| 684 |
+
help="Store the cache data in <dir>.",
|
| 685 |
+
)
|
| 686 |
+
|
| 687 |
+
|
| 688 |
+
def _handle_no_cache_dir(
|
| 689 |
+
option: Option, opt: str, value: str, parser: OptionParser
|
| 690 |
+
) -> None:
|
| 691 |
+
"""
|
| 692 |
+
Process a value provided for the --no-cache-dir option.
|
| 693 |
+
|
| 694 |
+
This is an optparse.Option callback for the --no-cache-dir option.
|
| 695 |
+
"""
|
| 696 |
+
# The value argument will be None if --no-cache-dir is passed via the
|
| 697 |
+
# command-line, since the option doesn't accept arguments. However,
|
| 698 |
+
# the value can be non-None if the option is triggered e.g. by an
|
| 699 |
+
# environment variable, like PIP_NO_CACHE_DIR=true.
|
| 700 |
+
if value is not None:
|
| 701 |
+
# Then parse the string value to get argument error-checking.
|
| 702 |
+
try:
|
| 703 |
+
strtobool(value)
|
| 704 |
+
except ValueError as exc:
|
| 705 |
+
raise_option_error(parser, option=option, msg=str(exc))
|
| 706 |
+
|
| 707 |
+
# Originally, setting PIP_NO_CACHE_DIR to a value that strtobool()
|
| 708 |
+
# converted to 0 (like "false" or "no") caused cache_dir to be disabled
|
| 709 |
+
# rather than enabled (logic would say the latter). Thus, we disable
|
| 710 |
+
# the cache directory not just on values that parse to True, but (for
|
| 711 |
+
# backwards compatibility reasons) also on values that parse to False.
|
| 712 |
+
# In other words, always set it to False if the option is provided in
|
| 713 |
+
# some (valid) form.
|
| 714 |
+
parser.values.cache_dir = False
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
no_cache: Callable[..., Option] = partial(
|
| 718 |
+
Option,
|
| 719 |
+
"--no-cache-dir",
|
| 720 |
+
dest="cache_dir",
|
| 721 |
+
action="callback",
|
| 722 |
+
callback=_handle_no_cache_dir,
|
| 723 |
+
help="Disable the cache.",
|
| 724 |
+
)
|
| 725 |
+
|
| 726 |
+
no_deps: Callable[..., Option] = partial(
|
| 727 |
+
Option,
|
| 728 |
+
"--no-deps",
|
| 729 |
+
"--no-dependencies",
|
| 730 |
+
dest="ignore_dependencies",
|
| 731 |
+
action="store_true",
|
| 732 |
+
default=False,
|
| 733 |
+
help="Don't install package dependencies.",
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
+
ignore_requires_python: Callable[..., Option] = partial(
|
| 737 |
+
Option,
|
| 738 |
+
"--ignore-requires-python",
|
| 739 |
+
dest="ignore_requires_python",
|
| 740 |
+
action="store_true",
|
| 741 |
+
help="Ignore the Requires-Python information.",
|
| 742 |
+
)
|
| 743 |
+
|
| 744 |
+
no_build_isolation: Callable[..., Option] = partial(
|
| 745 |
+
Option,
|
| 746 |
+
"--no-build-isolation",
|
| 747 |
+
dest="build_isolation",
|
| 748 |
+
action="store_false",
|
| 749 |
+
default=True,
|
| 750 |
+
help="Disable isolation when building a modern source distribution. "
|
| 751 |
+
"Build dependencies specified by PEP 518 must be already installed "
|
| 752 |
+
"if this option is used.",
|
| 753 |
+
)
|
| 754 |
+
|
| 755 |
+
check_build_deps: Callable[..., Option] = partial(
|
| 756 |
+
Option,
|
| 757 |
+
"--check-build-dependencies",
|
| 758 |
+
dest="check_build_deps",
|
| 759 |
+
action="store_true",
|
| 760 |
+
default=False,
|
| 761 |
+
help="Check the build dependencies when PEP517 is used.",
|
| 762 |
+
)
|
| 763 |
+
|
| 764 |
+
|
| 765 |
+
def _handle_no_use_pep517(
|
| 766 |
+
option: Option, opt: str, value: str, parser: OptionParser
|
| 767 |
+
) -> None:
|
| 768 |
+
"""
|
| 769 |
+
Process a value provided for the --no-use-pep517 option.
|
| 770 |
+
|
| 771 |
+
This is an optparse.Option callback for the no_use_pep517 option.
|
| 772 |
+
"""
|
| 773 |
+
# Since --no-use-pep517 doesn't accept arguments, the value argument
|
| 774 |
+
# will be None if --no-use-pep517 is passed via the command-line.
|
| 775 |
+
# However, the value can be non-None if the option is triggered e.g.
|
| 776 |
+
# by an environment variable, for example "PIP_NO_USE_PEP517=true".
|
| 777 |
+
if value is not None:
|
| 778 |
+
msg = """A value was passed for --no-use-pep517,
|
| 779 |
+
probably using either the PIP_NO_USE_PEP517 environment variable
|
| 780 |
+
or the "no-use-pep517" config file option. Use an appropriate value
|
| 781 |
+
of the PIP_USE_PEP517 environment variable or the "use-pep517"
|
| 782 |
+
config file option instead.
|
| 783 |
+
"""
|
| 784 |
+
raise_option_error(parser, option=option, msg=msg)
|
| 785 |
+
|
| 786 |
+
# If user doesn't wish to use pep517, we check if setuptools and wheel are installed
|
| 787 |
+
# and raise error if it is not.
|
| 788 |
+
packages = ("setuptools", "wheel")
|
| 789 |
+
if not all(importlib.util.find_spec(package) for package in packages):
|
| 790 |
+
msg = (
|
| 791 |
+
f"It is not possible to use --no-use-pep517 "
|
| 792 |
+
f"without {' and '.join(packages)} installed."
|
| 793 |
+
)
|
| 794 |
+
raise_option_error(parser, option=option, msg=msg)
|
| 795 |
+
|
| 796 |
+
# Otherwise, --no-use-pep517 was passed via the command-line.
|
| 797 |
+
parser.values.use_pep517 = False
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
use_pep517: Any = partial(
|
| 801 |
+
Option,
|
| 802 |
+
"--use-pep517",
|
| 803 |
+
dest="use_pep517",
|
| 804 |
+
action="store_true",
|
| 805 |
+
default=None,
|
| 806 |
+
help="Use PEP 517 for building source distributions "
|
| 807 |
+
"(use --no-use-pep517 to force legacy behaviour).",
|
| 808 |
+
)
|
| 809 |
+
|
| 810 |
+
no_use_pep517: Any = partial(
|
| 811 |
+
Option,
|
| 812 |
+
"--no-use-pep517",
|
| 813 |
+
dest="use_pep517",
|
| 814 |
+
action="callback",
|
| 815 |
+
callback=_handle_no_use_pep517,
|
| 816 |
+
default=None,
|
| 817 |
+
help=SUPPRESS_HELP,
|
| 818 |
+
)
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
def _handle_config_settings(
|
| 822 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 823 |
+
) -> None:
|
| 824 |
+
key, sep, val = value.partition("=")
|
| 825 |
+
if sep != "=":
|
| 826 |
+
parser.error(f"Arguments to {opt_str} must be of the form KEY=VAL")
|
| 827 |
+
dest = getattr(parser.values, option.dest)
|
| 828 |
+
if dest is None:
|
| 829 |
+
dest = {}
|
| 830 |
+
setattr(parser.values, option.dest, dest)
|
| 831 |
+
if key in dest:
|
| 832 |
+
if isinstance(dest[key], list):
|
| 833 |
+
dest[key].append(val)
|
| 834 |
+
else:
|
| 835 |
+
dest[key] = [dest[key], val]
|
| 836 |
+
else:
|
| 837 |
+
dest[key] = val
|
| 838 |
+
|
| 839 |
+
|
| 840 |
+
config_settings: Callable[..., Option] = partial(
|
| 841 |
+
Option,
|
| 842 |
+
"-C",
|
| 843 |
+
"--config-settings",
|
| 844 |
+
dest="config_settings",
|
| 845 |
+
type=str,
|
| 846 |
+
action="callback",
|
| 847 |
+
callback=_handle_config_settings,
|
| 848 |
+
metavar="settings",
|
| 849 |
+
help="Configuration settings to be passed to the PEP 517 build backend. "
|
| 850 |
+
"Settings take the form KEY=VALUE. Use multiple --config-settings options "
|
| 851 |
+
"to pass multiple keys to the backend.",
|
| 852 |
+
)
|
| 853 |
+
|
| 854 |
+
build_options: Callable[..., Option] = partial(
|
| 855 |
+
Option,
|
| 856 |
+
"--build-option",
|
| 857 |
+
dest="build_options",
|
| 858 |
+
metavar="options",
|
| 859 |
+
action="append",
|
| 860 |
+
help="Extra arguments to be supplied to 'setup.py bdist_wheel'.",
|
| 861 |
+
)
|
| 862 |
+
|
| 863 |
+
global_options: Callable[..., Option] = partial(
|
| 864 |
+
Option,
|
| 865 |
+
"--global-option",
|
| 866 |
+
dest="global_options",
|
| 867 |
+
action="append",
|
| 868 |
+
metavar="options",
|
| 869 |
+
help="Extra global options to be supplied to the setup.py "
|
| 870 |
+
"call before the install or bdist_wheel command.",
|
| 871 |
+
)
|
| 872 |
+
|
| 873 |
+
no_clean: Callable[..., Option] = partial(
|
| 874 |
+
Option,
|
| 875 |
+
"--no-clean",
|
| 876 |
+
action="store_true",
|
| 877 |
+
default=False,
|
| 878 |
+
help="Don't clean up build directories.",
|
| 879 |
+
)
|
| 880 |
+
|
| 881 |
+
pre: Callable[..., Option] = partial(
|
| 882 |
+
Option,
|
| 883 |
+
"--pre",
|
| 884 |
+
action="store_true",
|
| 885 |
+
default=False,
|
| 886 |
+
help="Include pre-release and development versions. By default, "
|
| 887 |
+
"pip only finds stable versions.",
|
| 888 |
+
)
|
| 889 |
+
|
| 890 |
+
disable_pip_version_check: Callable[..., Option] = partial(
|
| 891 |
+
Option,
|
| 892 |
+
"--disable-pip-version-check",
|
| 893 |
+
dest="disable_pip_version_check",
|
| 894 |
+
action="store_true",
|
| 895 |
+
default=False,
|
| 896 |
+
help="Don't periodically check PyPI to determine whether a new version "
|
| 897 |
+
"of pip is available for download. Implied with --no-index.",
|
| 898 |
+
)
|
| 899 |
+
|
| 900 |
+
root_user_action: Callable[..., Option] = partial(
|
| 901 |
+
Option,
|
| 902 |
+
"--root-user-action",
|
| 903 |
+
dest="root_user_action",
|
| 904 |
+
default="warn",
|
| 905 |
+
choices=["warn", "ignore"],
|
| 906 |
+
help="Action if pip is run as a root user [warn, ignore] (default: warn)",
|
| 907 |
+
)
|
| 908 |
+
|
| 909 |
+
|
| 910 |
+
def _handle_merge_hash(
|
| 911 |
+
option: Option, opt_str: str, value: str, parser: OptionParser
|
| 912 |
+
) -> None:
|
| 913 |
+
"""Given a value spelled "algo:digest", append the digest to a list
|
| 914 |
+
pointed to in a dict by the algo name."""
|
| 915 |
+
if not parser.values.hashes:
|
| 916 |
+
parser.values.hashes = {}
|
| 917 |
+
try:
|
| 918 |
+
algo, digest = value.split(":", 1)
|
| 919 |
+
except ValueError:
|
| 920 |
+
parser.error(
|
| 921 |
+
f"Arguments to {opt_str} must be a hash name "
|
| 922 |
+
"followed by a value, like --hash=sha256:"
|
| 923 |
+
"abcde..."
|
| 924 |
+
)
|
| 925 |
+
if algo not in STRONG_HASHES:
|
| 926 |
+
parser.error(
|
| 927 |
+
"Allowed hash algorithms for {} are {}.".format(
|
| 928 |
+
opt_str, ", ".join(STRONG_HASHES)
|
| 929 |
+
)
|
| 930 |
+
)
|
| 931 |
+
parser.values.hashes.setdefault(algo, []).append(digest)
|
| 932 |
+
|
| 933 |
+
|
| 934 |
+
hash: Callable[..., Option] = partial(
|
| 935 |
+
Option,
|
| 936 |
+
"--hash",
|
| 937 |
+
# Hash values eventually end up in InstallRequirement.hashes due to
|
| 938 |
+
# __dict__ copying in process_line().
|
| 939 |
+
dest="hashes",
|
| 940 |
+
action="callback",
|
| 941 |
+
callback=_handle_merge_hash,
|
| 942 |
+
type="string",
|
| 943 |
+
help="Verify that the package's archive matches this "
|
| 944 |
+
"hash before installing. Example: --hash=sha256:abcdef...",
|
| 945 |
+
)
|
| 946 |
+
|
| 947 |
+
|
| 948 |
+
require_hashes: Callable[..., Option] = partial(
|
| 949 |
+
Option,
|
| 950 |
+
"--require-hashes",
|
| 951 |
+
dest="require_hashes",
|
| 952 |
+
action="store_true",
|
| 953 |
+
default=False,
|
| 954 |
+
help="Require a hash to check each requirement against, for "
|
| 955 |
+
"repeatable installs. This option is implied when any package in a "
|
| 956 |
+
"requirements file has a --hash option.",
|
| 957 |
+
)
|
| 958 |
+
|
| 959 |
+
|
| 960 |
+
list_path: Callable[..., Option] = partial(
|
| 961 |
+
PipOption,
|
| 962 |
+
"--path",
|
| 963 |
+
dest="path",
|
| 964 |
+
type="path",
|
| 965 |
+
action="append",
|
| 966 |
+
help="Restrict to the specified installation path for listing "
|
| 967 |
+
"packages (can be used multiple times).",
|
| 968 |
+
)
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
def check_list_path_option(options: Values) -> None:
|
| 972 |
+
if options.path and (options.user or options.local):
|
| 973 |
+
raise CommandError("Cannot combine '--path' with '--user' or '--local'")
|
| 974 |
+
|
| 975 |
+
|
| 976 |
+
list_exclude: Callable[..., Option] = partial(
|
| 977 |
+
PipOption,
|
| 978 |
+
"--exclude",
|
| 979 |
+
dest="excludes",
|
| 980 |
+
action="append",
|
| 981 |
+
metavar="package",
|
| 982 |
+
type="package_name",
|
| 983 |
+
help="Exclude specified package from the output",
|
| 984 |
+
)
|
| 985 |
+
|
| 986 |
+
|
| 987 |
+
no_python_version_warning: Callable[..., Option] = partial(
|
| 988 |
+
Option,
|
| 989 |
+
"--no-python-version-warning",
|
| 990 |
+
dest="no_python_version_warning",
|
| 991 |
+
action="store_true",
|
| 992 |
+
default=False,
|
| 993 |
+
help="Silence deprecation warnings for upcoming unsupported Pythons.",
|
| 994 |
+
)
|
| 995 |
+
|
| 996 |
+
|
| 997 |
+
# Features that are now always on. A warning is printed if they are used.
|
| 998 |
+
ALWAYS_ENABLED_FEATURES = [
|
| 999 |
+
"truststore", # always on since 24.2
|
| 1000 |
+
"no-binary-enable-wheel-cache", # always on since 23.1
|
| 1001 |
+
]
|
| 1002 |
+
|
| 1003 |
+
use_new_feature: Callable[..., Option] = partial(
|
| 1004 |
+
Option,
|
| 1005 |
+
"--use-feature",
|
| 1006 |
+
dest="features_enabled",
|
| 1007 |
+
metavar="feature",
|
| 1008 |
+
action="append",
|
| 1009 |
+
default=[],
|
| 1010 |
+
choices=[
|
| 1011 |
+
"fast-deps",
|
| 1012 |
+
]
|
| 1013 |
+
+ ALWAYS_ENABLED_FEATURES,
|
| 1014 |
+
help="Enable new functionality, that may be backward incompatible.",
|
| 1015 |
+
)
|
| 1016 |
+
|
| 1017 |
+
use_deprecated_feature: Callable[..., Option] = partial(
|
| 1018 |
+
Option,
|
| 1019 |
+
"--use-deprecated",
|
| 1020 |
+
dest="deprecated_features_enabled",
|
| 1021 |
+
metavar="feature",
|
| 1022 |
+
action="append",
|
| 1023 |
+
default=[],
|
| 1024 |
+
choices=[
|
| 1025 |
+
"legacy-resolver",
|
| 1026 |
+
"legacy-certs",
|
| 1027 |
+
],
|
| 1028 |
+
help=("Enable deprecated functionality, that will be removed in the future."),
|
| 1029 |
+
)
|
| 1030 |
+
|
| 1031 |
+
|
| 1032 |
+
##########
|
| 1033 |
+
# groups #
|
| 1034 |
+
##########
|
| 1035 |
+
|
| 1036 |
+
general_group: Dict[str, Any] = {
|
| 1037 |
+
"name": "General Options",
|
| 1038 |
+
"options": [
|
| 1039 |
+
help_,
|
| 1040 |
+
debug_mode,
|
| 1041 |
+
isolated_mode,
|
| 1042 |
+
require_virtualenv,
|
| 1043 |
+
python,
|
| 1044 |
+
verbose,
|
| 1045 |
+
version,
|
| 1046 |
+
quiet,
|
| 1047 |
+
log,
|
| 1048 |
+
no_input,
|
| 1049 |
+
keyring_provider,
|
| 1050 |
+
proxy,
|
| 1051 |
+
retries,
|
| 1052 |
+
timeout,
|
| 1053 |
+
exists_action,
|
| 1054 |
+
trusted_host,
|
| 1055 |
+
cert,
|
| 1056 |
+
client_cert,
|
| 1057 |
+
cache_dir,
|
| 1058 |
+
no_cache,
|
| 1059 |
+
disable_pip_version_check,
|
| 1060 |
+
no_color,
|
| 1061 |
+
no_python_version_warning,
|
| 1062 |
+
use_new_feature,
|
| 1063 |
+
use_deprecated_feature,
|
| 1064 |
+
],
|
| 1065 |
+
}
|
| 1066 |
+
|
| 1067 |
+
index_group: Dict[str, Any] = {
|
| 1068 |
+
"name": "Package Index Options",
|
| 1069 |
+
"options": [
|
| 1070 |
+
index_url,
|
| 1071 |
+
extra_index_url,
|
| 1072 |
+
no_index,
|
| 1073 |
+
find_links,
|
| 1074 |
+
],
|
| 1075 |
+
}
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/command_context.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from contextlib import ExitStack, contextmanager
|
| 2 |
+
from typing import ContextManager, Generator, TypeVar
|
| 3 |
+
|
| 4 |
+
_T = TypeVar("_T", covariant=True)
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class CommandContextMixIn:
|
| 8 |
+
def __init__(self) -> None:
|
| 9 |
+
super().__init__()
|
| 10 |
+
self._in_main_context = False
|
| 11 |
+
self._main_context = ExitStack()
|
| 12 |
+
|
| 13 |
+
@contextmanager
|
| 14 |
+
def main_context(self) -> Generator[None, None, None]:
|
| 15 |
+
assert not self._in_main_context
|
| 16 |
+
|
| 17 |
+
self._in_main_context = True
|
| 18 |
+
try:
|
| 19 |
+
with self._main_context:
|
| 20 |
+
yield
|
| 21 |
+
finally:
|
| 22 |
+
self._in_main_context = False
|
| 23 |
+
|
| 24 |
+
def enter_context(self, context_provider: ContextManager[_T]) -> _T:
|
| 25 |
+
assert self._in_main_context
|
| 26 |
+
|
| 27 |
+
return self._main_context.enter_context(context_provider)
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/index_command.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Contains command classes which may interact with an index / the network.
|
| 3 |
+
|
| 4 |
+
Unlike its sister module, req_command, this module still uses lazy imports
|
| 5 |
+
so commands which don't always hit the network (e.g. list w/o --outdated or
|
| 6 |
+
--uptodate) don't need waste time importing PipSession and friends.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import logging
|
| 10 |
+
import os
|
| 11 |
+
import sys
|
| 12 |
+
from optparse import Values
|
| 13 |
+
from typing import TYPE_CHECKING, List, Optional
|
| 14 |
+
|
| 15 |
+
from pip._vendor import certifi
|
| 16 |
+
|
| 17 |
+
from pip._internal.cli.base_command import Command
|
| 18 |
+
from pip._internal.cli.command_context import CommandContextMixIn
|
| 19 |
+
|
| 20 |
+
if TYPE_CHECKING:
|
| 21 |
+
from ssl import SSLContext
|
| 22 |
+
|
| 23 |
+
from pip._internal.network.session import PipSession
|
| 24 |
+
|
| 25 |
+
logger = logging.getLogger(__name__)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _create_truststore_ssl_context() -> Optional["SSLContext"]:
|
| 29 |
+
if sys.version_info < (3, 10):
|
| 30 |
+
logger.debug("Disabling truststore because Python version isn't 3.10+")
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
try:
|
| 34 |
+
import ssl
|
| 35 |
+
except ImportError:
|
| 36 |
+
logger.warning("Disabling truststore since ssl support is missing")
|
| 37 |
+
return None
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
from pip._vendor import truststore
|
| 41 |
+
except ImportError:
|
| 42 |
+
logger.warning("Disabling truststore because platform isn't supported")
|
| 43 |
+
return None
|
| 44 |
+
|
| 45 |
+
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
| 46 |
+
ctx.load_verify_locations(certifi.where())
|
| 47 |
+
return ctx
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class SessionCommandMixin(CommandContextMixIn):
|
| 51 |
+
"""
|
| 52 |
+
A class mixin for command classes needing _build_session().
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def __init__(self) -> None:
|
| 56 |
+
super().__init__()
|
| 57 |
+
self._session: Optional[PipSession] = None
|
| 58 |
+
|
| 59 |
+
@classmethod
|
| 60 |
+
def _get_index_urls(cls, options: Values) -> Optional[List[str]]:
|
| 61 |
+
"""Return a list of index urls from user-provided options."""
|
| 62 |
+
index_urls = []
|
| 63 |
+
if not getattr(options, "no_index", False):
|
| 64 |
+
url = getattr(options, "index_url", None)
|
| 65 |
+
if url:
|
| 66 |
+
index_urls.append(url)
|
| 67 |
+
urls = getattr(options, "extra_index_urls", None)
|
| 68 |
+
if urls:
|
| 69 |
+
index_urls.extend(urls)
|
| 70 |
+
# Return None rather than an empty list
|
| 71 |
+
return index_urls or None
|
| 72 |
+
|
| 73 |
+
def get_default_session(self, options: Values) -> "PipSession":
|
| 74 |
+
"""Get a default-managed session."""
|
| 75 |
+
if self._session is None:
|
| 76 |
+
self._session = self.enter_context(self._build_session(options))
|
| 77 |
+
# there's no type annotation on requests.Session, so it's
|
| 78 |
+
# automatically ContextManager[Any] and self._session becomes Any,
|
| 79 |
+
# then https://github.com/python/mypy/issues/7696 kicks in
|
| 80 |
+
assert self._session is not None
|
| 81 |
+
return self._session
|
| 82 |
+
|
| 83 |
+
def _build_session(
|
| 84 |
+
self,
|
| 85 |
+
options: Values,
|
| 86 |
+
retries: Optional[int] = None,
|
| 87 |
+
timeout: Optional[int] = None,
|
| 88 |
+
) -> "PipSession":
|
| 89 |
+
from pip._internal.network.session import PipSession
|
| 90 |
+
|
| 91 |
+
cache_dir = options.cache_dir
|
| 92 |
+
assert not cache_dir or os.path.isabs(cache_dir)
|
| 93 |
+
|
| 94 |
+
if "legacy-certs" not in options.deprecated_features_enabled:
|
| 95 |
+
ssl_context = _create_truststore_ssl_context()
|
| 96 |
+
else:
|
| 97 |
+
ssl_context = None
|
| 98 |
+
|
| 99 |
+
session = PipSession(
|
| 100 |
+
cache=os.path.join(cache_dir, "http-v2") if cache_dir else None,
|
| 101 |
+
retries=retries if retries is not None else options.retries,
|
| 102 |
+
trusted_hosts=options.trusted_hosts,
|
| 103 |
+
index_urls=self._get_index_urls(options),
|
| 104 |
+
ssl_context=ssl_context,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# Handle custom ca-bundles from the user
|
| 108 |
+
if options.cert:
|
| 109 |
+
session.verify = options.cert
|
| 110 |
+
|
| 111 |
+
# Handle SSL client certificate
|
| 112 |
+
if options.client_cert:
|
| 113 |
+
session.cert = options.client_cert
|
| 114 |
+
|
| 115 |
+
# Handle timeouts
|
| 116 |
+
if options.timeout or timeout:
|
| 117 |
+
session.timeout = timeout if timeout is not None else options.timeout
|
| 118 |
+
|
| 119 |
+
# Handle configured proxies
|
| 120 |
+
if options.proxy:
|
| 121 |
+
session.proxies = {
|
| 122 |
+
"http": options.proxy,
|
| 123 |
+
"https": options.proxy,
|
| 124 |
+
}
|
| 125 |
+
session.trust_env = False
|
| 126 |
+
session.pip_proxy = options.proxy
|
| 127 |
+
|
| 128 |
+
# Determine if we can prompt the user for authentication or not
|
| 129 |
+
session.auth.prompting = not options.no_input
|
| 130 |
+
session.auth.keyring_provider = options.keyring_provider
|
| 131 |
+
|
| 132 |
+
return session
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _pip_self_version_check(session: "PipSession", options: Values) -> None:
|
| 136 |
+
from pip._internal.self_outdated_check import pip_self_version_check as check
|
| 137 |
+
|
| 138 |
+
check(session, options)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
class IndexGroupCommand(Command, SessionCommandMixin):
|
| 142 |
+
"""
|
| 143 |
+
Abstract base class for commands with the index_group options.
|
| 144 |
+
|
| 145 |
+
This also corresponds to the commands that permit the pip version check.
|
| 146 |
+
"""
|
| 147 |
+
|
| 148 |
+
def handle_pip_version_check(self, options: Values) -> None:
|
| 149 |
+
"""
|
| 150 |
+
Do the pip version check if not disabled.
|
| 151 |
+
|
| 152 |
+
This overrides the default behavior of not doing the check.
|
| 153 |
+
"""
|
| 154 |
+
# Make sure the index_group options are present.
|
| 155 |
+
assert hasattr(options, "no_index")
|
| 156 |
+
|
| 157 |
+
if options.disable_pip_version_check or options.no_index:
|
| 158 |
+
return
|
| 159 |
+
|
| 160 |
+
try:
|
| 161 |
+
# Otherwise, check if we're using the latest version of pip available.
|
| 162 |
+
session = self._build_session(
|
| 163 |
+
options,
|
| 164 |
+
retries=0,
|
| 165 |
+
timeout=min(5, options.timeout),
|
| 166 |
+
)
|
| 167 |
+
with session:
|
| 168 |
+
_pip_self_version_check(session, options)
|
| 169 |
+
except Exception:
|
| 170 |
+
logger.warning("There was an error checking the latest version of pip.")
|
| 171 |
+
logger.debug("See below for error", exc_info=True)
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/main.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Primary application entrypoint.
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import locale
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
import warnings
|
| 9 |
+
from typing import List, Optional
|
| 10 |
+
|
| 11 |
+
from pip._internal.cli.autocompletion import autocomplete
|
| 12 |
+
from pip._internal.cli.main_parser import parse_command
|
| 13 |
+
from pip._internal.commands import create_command
|
| 14 |
+
from pip._internal.exceptions import PipError
|
| 15 |
+
from pip._internal.utils import deprecation
|
| 16 |
+
|
| 17 |
+
logger = logging.getLogger(__name__)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Do not import and use main() directly! Using it directly is actively
|
| 21 |
+
# discouraged by pip's maintainers. The name, location and behavior of
|
| 22 |
+
# this function is subject to change, so calling it directly is not
|
| 23 |
+
# portable across different pip versions.
|
| 24 |
+
|
| 25 |
+
# In addition, running pip in-process is unsupported and unsafe. This is
|
| 26 |
+
# elaborated in detail at
|
| 27 |
+
# https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program.
|
| 28 |
+
# That document also provides suggestions that should work for nearly
|
| 29 |
+
# all users that are considering importing and using main() directly.
|
| 30 |
+
|
| 31 |
+
# However, we know that certain users will still want to invoke pip
|
| 32 |
+
# in-process. If you understand and accept the implications of using pip
|
| 33 |
+
# in an unsupported manner, the best approach is to use runpy to avoid
|
| 34 |
+
# depending on the exact location of this entry point.
|
| 35 |
+
|
| 36 |
+
# The following example shows how to use runpy to invoke pip in that
|
| 37 |
+
# case:
|
| 38 |
+
#
|
| 39 |
+
# sys.argv = ["pip", your, args, here]
|
| 40 |
+
# runpy.run_module("pip", run_name="__main__")
|
| 41 |
+
#
|
| 42 |
+
# Note that this will exit the process after running, unlike a direct
|
| 43 |
+
# call to main. As it is not safe to do any processing after calling
|
| 44 |
+
# main, this should not be an issue in practice.
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def main(args: Optional[List[str]] = None) -> int:
|
| 48 |
+
if args is None:
|
| 49 |
+
args = sys.argv[1:]
|
| 50 |
+
|
| 51 |
+
# Suppress the pkg_resources deprecation warning
|
| 52 |
+
# Note - we use a module of .*pkg_resources to cover
|
| 53 |
+
# the normal case (pip._vendor.pkg_resources) and the
|
| 54 |
+
# devendored case (a bare pkg_resources)
|
| 55 |
+
warnings.filterwarnings(
|
| 56 |
+
action="ignore", category=DeprecationWarning, module=".*pkg_resources"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# Configure our deprecation warnings to be sent through loggers
|
| 60 |
+
deprecation.install_warning_logger()
|
| 61 |
+
|
| 62 |
+
autocomplete()
|
| 63 |
+
|
| 64 |
+
try:
|
| 65 |
+
cmd_name, cmd_args = parse_command(args)
|
| 66 |
+
except PipError as exc:
|
| 67 |
+
sys.stderr.write(f"ERROR: {exc}")
|
| 68 |
+
sys.stderr.write(os.linesep)
|
| 69 |
+
sys.exit(1)
|
| 70 |
+
|
| 71 |
+
# Needed for locale.getpreferredencoding(False) to work
|
| 72 |
+
# in pip._internal.utils.encoding.auto_decode
|
| 73 |
+
try:
|
| 74 |
+
locale.setlocale(locale.LC_ALL, "")
|
| 75 |
+
except locale.Error as e:
|
| 76 |
+
# setlocale can apparently crash if locale are uninitialized
|
| 77 |
+
logger.debug("Ignoring error %s when setting locale", e)
|
| 78 |
+
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
|
| 79 |
+
|
| 80 |
+
return command.main(cmd_args)
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/main_parser.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""A single place for constructing and exposing the main parser
|
| 2 |
+
"""
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
import subprocess
|
| 6 |
+
import sys
|
| 7 |
+
from typing import List, Optional, Tuple
|
| 8 |
+
|
| 9 |
+
from pip._internal.build_env import get_runnable_pip
|
| 10 |
+
from pip._internal.cli import cmdoptions
|
| 11 |
+
from pip._internal.cli.parser import ConfigOptionParser, UpdatingDefaultsHelpFormatter
|
| 12 |
+
from pip._internal.commands import commands_dict, get_similar_commands
|
| 13 |
+
from pip._internal.exceptions import CommandError
|
| 14 |
+
from pip._internal.utils.misc import get_pip_version, get_prog
|
| 15 |
+
|
| 16 |
+
__all__ = ["create_main_parser", "parse_command"]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def create_main_parser() -> ConfigOptionParser:
|
| 20 |
+
"""Creates and returns the main parser for pip's CLI"""
|
| 21 |
+
|
| 22 |
+
parser = ConfigOptionParser(
|
| 23 |
+
usage="\n%prog <command> [options]",
|
| 24 |
+
add_help_option=False,
|
| 25 |
+
formatter=UpdatingDefaultsHelpFormatter(),
|
| 26 |
+
name="global",
|
| 27 |
+
prog=get_prog(),
|
| 28 |
+
)
|
| 29 |
+
parser.disable_interspersed_args()
|
| 30 |
+
|
| 31 |
+
parser.version = get_pip_version()
|
| 32 |
+
|
| 33 |
+
# add the general options
|
| 34 |
+
gen_opts = cmdoptions.make_option_group(cmdoptions.general_group, parser)
|
| 35 |
+
parser.add_option_group(gen_opts)
|
| 36 |
+
|
| 37 |
+
# so the help formatter knows
|
| 38 |
+
parser.main = True # type: ignore
|
| 39 |
+
|
| 40 |
+
# create command listing for description
|
| 41 |
+
description = [""] + [
|
| 42 |
+
f"{name:27} {command_info.summary}"
|
| 43 |
+
for name, command_info in commands_dict.items()
|
| 44 |
+
]
|
| 45 |
+
parser.description = "\n".join(description)
|
| 46 |
+
|
| 47 |
+
return parser
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def identify_python_interpreter(python: str) -> Optional[str]:
|
| 51 |
+
# If the named file exists, use it.
|
| 52 |
+
# If it's a directory, assume it's a virtual environment and
|
| 53 |
+
# look for the environment's Python executable.
|
| 54 |
+
if os.path.exists(python):
|
| 55 |
+
if os.path.isdir(python):
|
| 56 |
+
# bin/python for Unix, Scripts/python.exe for Windows
|
| 57 |
+
# Try both in case of odd cases like cygwin.
|
| 58 |
+
for exe in ("bin/python", "Scripts/python.exe"):
|
| 59 |
+
py = os.path.join(python, exe)
|
| 60 |
+
if os.path.exists(py):
|
| 61 |
+
return py
|
| 62 |
+
else:
|
| 63 |
+
return python
|
| 64 |
+
|
| 65 |
+
# Could not find the interpreter specified
|
| 66 |
+
return None
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def parse_command(args: List[str]) -> Tuple[str, List[str]]:
|
| 70 |
+
parser = create_main_parser()
|
| 71 |
+
|
| 72 |
+
# Note: parser calls disable_interspersed_args(), so the result of this
|
| 73 |
+
# call is to split the initial args into the general options before the
|
| 74 |
+
# subcommand and everything else.
|
| 75 |
+
# For example:
|
| 76 |
+
# args: ['--timeout=5', 'install', '--user', 'INITools']
|
| 77 |
+
# general_options: ['--timeout==5']
|
| 78 |
+
# args_else: ['install', '--user', 'INITools']
|
| 79 |
+
general_options, args_else = parser.parse_args(args)
|
| 80 |
+
|
| 81 |
+
# --python
|
| 82 |
+
if general_options.python and "_PIP_RUNNING_IN_SUBPROCESS" not in os.environ:
|
| 83 |
+
# Re-invoke pip using the specified Python interpreter
|
| 84 |
+
interpreter = identify_python_interpreter(general_options.python)
|
| 85 |
+
if interpreter is None:
|
| 86 |
+
raise CommandError(
|
| 87 |
+
f"Could not locate Python interpreter {general_options.python}"
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
pip_cmd = [
|
| 91 |
+
interpreter,
|
| 92 |
+
get_runnable_pip(),
|
| 93 |
+
]
|
| 94 |
+
pip_cmd.extend(args)
|
| 95 |
+
|
| 96 |
+
# Set a flag so the child doesn't re-invoke itself, causing
|
| 97 |
+
# an infinite loop.
|
| 98 |
+
os.environ["_PIP_RUNNING_IN_SUBPROCESS"] = "1"
|
| 99 |
+
returncode = 0
|
| 100 |
+
try:
|
| 101 |
+
proc = subprocess.run(pip_cmd)
|
| 102 |
+
returncode = proc.returncode
|
| 103 |
+
except (subprocess.SubprocessError, OSError) as exc:
|
| 104 |
+
raise CommandError(f"Failed to run pip under {interpreter}: {exc}")
|
| 105 |
+
sys.exit(returncode)
|
| 106 |
+
|
| 107 |
+
# --version
|
| 108 |
+
if general_options.version:
|
| 109 |
+
sys.stdout.write(parser.version)
|
| 110 |
+
sys.stdout.write(os.linesep)
|
| 111 |
+
sys.exit()
|
| 112 |
+
|
| 113 |
+
# pip || pip help -> print_help()
|
| 114 |
+
if not args_else or (args_else[0] == "help" and len(args_else) == 1):
|
| 115 |
+
parser.print_help()
|
| 116 |
+
sys.exit()
|
| 117 |
+
|
| 118 |
+
# the subcommand name
|
| 119 |
+
cmd_name = args_else[0]
|
| 120 |
+
|
| 121 |
+
if cmd_name not in commands_dict:
|
| 122 |
+
guess = get_similar_commands(cmd_name)
|
| 123 |
+
|
| 124 |
+
msg = [f'unknown command "{cmd_name}"']
|
| 125 |
+
if guess:
|
| 126 |
+
msg.append(f'maybe you meant "{guess}"')
|
| 127 |
+
|
| 128 |
+
raise CommandError(" - ".join(msg))
|
| 129 |
+
|
| 130 |
+
# all the args without the subcommand
|
| 131 |
+
cmd_args = args[:]
|
| 132 |
+
cmd_args.remove(cmd_name)
|
| 133 |
+
|
| 134 |
+
return cmd_name, cmd_args
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/parser.py
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Base option parser setup"""
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
import optparse
|
| 5 |
+
import shutil
|
| 6 |
+
import sys
|
| 7 |
+
import textwrap
|
| 8 |
+
from contextlib import suppress
|
| 9 |
+
from typing import Any, Dict, Generator, List, NoReturn, Optional, Tuple
|
| 10 |
+
|
| 11 |
+
from pip._internal.cli.status_codes import UNKNOWN_ERROR
|
| 12 |
+
from pip._internal.configuration import Configuration, ConfigurationError
|
| 13 |
+
from pip._internal.utils.misc import redact_auth_from_url, strtobool
|
| 14 |
+
|
| 15 |
+
logger = logging.getLogger(__name__)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class PrettyHelpFormatter(optparse.IndentedHelpFormatter):
|
| 19 |
+
"""A prettier/less verbose help formatter for optparse."""
|
| 20 |
+
|
| 21 |
+
def __init__(self, *args: Any, **kwargs: Any) -> None:
|
| 22 |
+
# help position must be aligned with __init__.parseopts.description
|
| 23 |
+
kwargs["max_help_position"] = 30
|
| 24 |
+
kwargs["indent_increment"] = 1
|
| 25 |
+
kwargs["width"] = shutil.get_terminal_size()[0] - 2
|
| 26 |
+
super().__init__(*args, **kwargs)
|
| 27 |
+
|
| 28 |
+
def format_option_strings(self, option: optparse.Option) -> str:
|
| 29 |
+
return self._format_option_strings(option)
|
| 30 |
+
|
| 31 |
+
def _format_option_strings(
|
| 32 |
+
self, option: optparse.Option, mvarfmt: str = " <{}>", optsep: str = ", "
|
| 33 |
+
) -> str:
|
| 34 |
+
"""
|
| 35 |
+
Return a comma-separated list of option strings and metavars.
|
| 36 |
+
|
| 37 |
+
:param option: tuple of (short opt, long opt), e.g: ('-f', '--format')
|
| 38 |
+
:param mvarfmt: metavar format string
|
| 39 |
+
:param optsep: separator
|
| 40 |
+
"""
|
| 41 |
+
opts = []
|
| 42 |
+
|
| 43 |
+
if option._short_opts:
|
| 44 |
+
opts.append(option._short_opts[0])
|
| 45 |
+
if option._long_opts:
|
| 46 |
+
opts.append(option._long_opts[0])
|
| 47 |
+
if len(opts) > 1:
|
| 48 |
+
opts.insert(1, optsep)
|
| 49 |
+
|
| 50 |
+
if option.takes_value():
|
| 51 |
+
assert option.dest is not None
|
| 52 |
+
metavar = option.metavar or option.dest.lower()
|
| 53 |
+
opts.append(mvarfmt.format(metavar.lower()))
|
| 54 |
+
|
| 55 |
+
return "".join(opts)
|
| 56 |
+
|
| 57 |
+
def format_heading(self, heading: str) -> str:
|
| 58 |
+
if heading == "Options":
|
| 59 |
+
return ""
|
| 60 |
+
return heading + ":\n"
|
| 61 |
+
|
| 62 |
+
def format_usage(self, usage: str) -> str:
|
| 63 |
+
"""
|
| 64 |
+
Ensure there is only one newline between usage and the first heading
|
| 65 |
+
if there is no description.
|
| 66 |
+
"""
|
| 67 |
+
msg = "\nUsage: {}\n".format(self.indent_lines(textwrap.dedent(usage), " "))
|
| 68 |
+
return msg
|
| 69 |
+
|
| 70 |
+
def format_description(self, description: Optional[str]) -> str:
|
| 71 |
+
# leave full control over description to us
|
| 72 |
+
if description:
|
| 73 |
+
if hasattr(self.parser, "main"):
|
| 74 |
+
label = "Commands"
|
| 75 |
+
else:
|
| 76 |
+
label = "Description"
|
| 77 |
+
# some doc strings have initial newlines, some don't
|
| 78 |
+
description = description.lstrip("\n")
|
| 79 |
+
# some doc strings have final newlines and spaces, some don't
|
| 80 |
+
description = description.rstrip()
|
| 81 |
+
# dedent, then reindent
|
| 82 |
+
description = self.indent_lines(textwrap.dedent(description), " ")
|
| 83 |
+
description = f"{label}:\n{description}\n"
|
| 84 |
+
return description
|
| 85 |
+
else:
|
| 86 |
+
return ""
|
| 87 |
+
|
| 88 |
+
def format_epilog(self, epilog: Optional[str]) -> str:
|
| 89 |
+
# leave full control over epilog to us
|
| 90 |
+
if epilog:
|
| 91 |
+
return epilog
|
| 92 |
+
else:
|
| 93 |
+
return ""
|
| 94 |
+
|
| 95 |
+
def indent_lines(self, text: str, indent: str) -> str:
|
| 96 |
+
new_lines = [indent + line for line in text.split("\n")]
|
| 97 |
+
return "\n".join(new_lines)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class UpdatingDefaultsHelpFormatter(PrettyHelpFormatter):
|
| 101 |
+
"""Custom help formatter for use in ConfigOptionParser.
|
| 102 |
+
|
| 103 |
+
This is updates the defaults before expanding them, allowing
|
| 104 |
+
them to show up correctly in the help listing.
|
| 105 |
+
|
| 106 |
+
Also redact auth from url type options
|
| 107 |
+
"""
|
| 108 |
+
|
| 109 |
+
def expand_default(self, option: optparse.Option) -> str:
|
| 110 |
+
default_values = None
|
| 111 |
+
if self.parser is not None:
|
| 112 |
+
assert isinstance(self.parser, ConfigOptionParser)
|
| 113 |
+
self.parser._update_defaults(self.parser.defaults)
|
| 114 |
+
assert option.dest is not None
|
| 115 |
+
default_values = self.parser.defaults.get(option.dest)
|
| 116 |
+
help_text = super().expand_default(option)
|
| 117 |
+
|
| 118 |
+
if default_values and option.metavar == "URL":
|
| 119 |
+
if isinstance(default_values, str):
|
| 120 |
+
default_values = [default_values]
|
| 121 |
+
|
| 122 |
+
# If its not a list, we should abort and just return the help text
|
| 123 |
+
if not isinstance(default_values, list):
|
| 124 |
+
default_values = []
|
| 125 |
+
|
| 126 |
+
for val in default_values:
|
| 127 |
+
help_text = help_text.replace(val, redact_auth_from_url(val))
|
| 128 |
+
|
| 129 |
+
return help_text
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class CustomOptionParser(optparse.OptionParser):
|
| 133 |
+
def insert_option_group(
|
| 134 |
+
self, idx: int, *args: Any, **kwargs: Any
|
| 135 |
+
) -> optparse.OptionGroup:
|
| 136 |
+
"""Insert an OptionGroup at a given position."""
|
| 137 |
+
group = self.add_option_group(*args, **kwargs)
|
| 138 |
+
|
| 139 |
+
self.option_groups.pop()
|
| 140 |
+
self.option_groups.insert(idx, group)
|
| 141 |
+
|
| 142 |
+
return group
|
| 143 |
+
|
| 144 |
+
@property
|
| 145 |
+
def option_list_all(self) -> List[optparse.Option]:
|
| 146 |
+
"""Get a list of all options, including those in option groups."""
|
| 147 |
+
res = self.option_list[:]
|
| 148 |
+
for i in self.option_groups:
|
| 149 |
+
res.extend(i.option_list)
|
| 150 |
+
|
| 151 |
+
return res
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
class ConfigOptionParser(CustomOptionParser):
|
| 155 |
+
"""Custom option parser which updates its defaults by checking the
|
| 156 |
+
configuration files and environmental variables"""
|
| 157 |
+
|
| 158 |
+
def __init__(
|
| 159 |
+
self,
|
| 160 |
+
*args: Any,
|
| 161 |
+
name: str,
|
| 162 |
+
isolated: bool = False,
|
| 163 |
+
**kwargs: Any,
|
| 164 |
+
) -> None:
|
| 165 |
+
self.name = name
|
| 166 |
+
self.config = Configuration(isolated)
|
| 167 |
+
|
| 168 |
+
assert self.name
|
| 169 |
+
super().__init__(*args, **kwargs)
|
| 170 |
+
|
| 171 |
+
def check_default(self, option: optparse.Option, key: str, val: Any) -> Any:
|
| 172 |
+
try:
|
| 173 |
+
return option.check_value(key, val)
|
| 174 |
+
except optparse.OptionValueError as exc:
|
| 175 |
+
print(f"An error occurred during configuration: {exc}")
|
| 176 |
+
sys.exit(3)
|
| 177 |
+
|
| 178 |
+
def _get_ordered_configuration_items(
|
| 179 |
+
self,
|
| 180 |
+
) -> Generator[Tuple[str, Any], None, None]:
|
| 181 |
+
# Configuration gives keys in an unordered manner. Order them.
|
| 182 |
+
override_order = ["global", self.name, ":env:"]
|
| 183 |
+
|
| 184 |
+
# Pool the options into different groups
|
| 185 |
+
section_items: Dict[str, List[Tuple[str, Any]]] = {
|
| 186 |
+
name: [] for name in override_order
|
| 187 |
+
}
|
| 188 |
+
for section_key, val in self.config.items():
|
| 189 |
+
# ignore empty values
|
| 190 |
+
if not val:
|
| 191 |
+
logger.debug(
|
| 192 |
+
"Ignoring configuration key '%s' as it's value is empty.",
|
| 193 |
+
section_key,
|
| 194 |
+
)
|
| 195 |
+
continue
|
| 196 |
+
|
| 197 |
+
section, key = section_key.split(".", 1)
|
| 198 |
+
if section in override_order:
|
| 199 |
+
section_items[section].append((key, val))
|
| 200 |
+
|
| 201 |
+
# Yield each group in their override order
|
| 202 |
+
for section in override_order:
|
| 203 |
+
for key, val in section_items[section]:
|
| 204 |
+
yield key, val
|
| 205 |
+
|
| 206 |
+
def _update_defaults(self, defaults: Dict[str, Any]) -> Dict[str, Any]:
|
| 207 |
+
"""Updates the given defaults with values from the config files and
|
| 208 |
+
the environ. Does a little special handling for certain types of
|
| 209 |
+
options (lists)."""
|
| 210 |
+
|
| 211 |
+
# Accumulate complex default state.
|
| 212 |
+
self.values = optparse.Values(self.defaults)
|
| 213 |
+
late_eval = set()
|
| 214 |
+
# Then set the options with those values
|
| 215 |
+
for key, val in self._get_ordered_configuration_items():
|
| 216 |
+
# '--' because configuration supports only long names
|
| 217 |
+
option = self.get_option("--" + key)
|
| 218 |
+
|
| 219 |
+
# Ignore options not present in this parser. E.g. non-globals put
|
| 220 |
+
# in [global] by users that want them to apply to all applicable
|
| 221 |
+
# commands.
|
| 222 |
+
if option is None:
|
| 223 |
+
continue
|
| 224 |
+
|
| 225 |
+
assert option.dest is not None
|
| 226 |
+
|
| 227 |
+
if option.action in ("store_true", "store_false"):
|
| 228 |
+
try:
|
| 229 |
+
val = strtobool(val)
|
| 230 |
+
except ValueError:
|
| 231 |
+
self.error(
|
| 232 |
+
f"{val} is not a valid value for {key} option, "
|
| 233 |
+
"please specify a boolean value like yes/no, "
|
| 234 |
+
"true/false or 1/0 instead."
|
| 235 |
+
)
|
| 236 |
+
elif option.action == "count":
|
| 237 |
+
with suppress(ValueError):
|
| 238 |
+
val = strtobool(val)
|
| 239 |
+
with suppress(ValueError):
|
| 240 |
+
val = int(val)
|
| 241 |
+
if not isinstance(val, int) or val < 0:
|
| 242 |
+
self.error(
|
| 243 |
+
f"{val} is not a valid value for {key} option, "
|
| 244 |
+
"please instead specify either a non-negative integer "
|
| 245 |
+
"or a boolean value like yes/no or false/true "
|
| 246 |
+
"which is equivalent to 1/0."
|
| 247 |
+
)
|
| 248 |
+
elif option.action == "append":
|
| 249 |
+
val = val.split()
|
| 250 |
+
val = [self.check_default(option, key, v) for v in val]
|
| 251 |
+
elif option.action == "callback":
|
| 252 |
+
assert option.callback is not None
|
| 253 |
+
late_eval.add(option.dest)
|
| 254 |
+
opt_str = option.get_opt_string()
|
| 255 |
+
val = option.convert_value(opt_str, val)
|
| 256 |
+
# From take_action
|
| 257 |
+
args = option.callback_args or ()
|
| 258 |
+
kwargs = option.callback_kwargs or {}
|
| 259 |
+
option.callback(option, opt_str, val, self, *args, **kwargs)
|
| 260 |
+
else:
|
| 261 |
+
val = self.check_default(option, key, val)
|
| 262 |
+
|
| 263 |
+
defaults[option.dest] = val
|
| 264 |
+
|
| 265 |
+
for key in late_eval:
|
| 266 |
+
defaults[key] = getattr(self.values, key)
|
| 267 |
+
self.values = None
|
| 268 |
+
return defaults
|
| 269 |
+
|
| 270 |
+
def get_default_values(self) -> optparse.Values:
|
| 271 |
+
"""Overriding to make updating the defaults after instantiation of
|
| 272 |
+
the option parser possible, _update_defaults() does the dirty work."""
|
| 273 |
+
if not self.process_default_values:
|
| 274 |
+
# Old, pre-Optik 1.5 behaviour.
|
| 275 |
+
return optparse.Values(self.defaults)
|
| 276 |
+
|
| 277 |
+
# Load the configuration, or error out in case of an error
|
| 278 |
+
try:
|
| 279 |
+
self.config.load()
|
| 280 |
+
except ConfigurationError as err:
|
| 281 |
+
self.exit(UNKNOWN_ERROR, str(err))
|
| 282 |
+
|
| 283 |
+
defaults = self._update_defaults(self.defaults.copy()) # ours
|
| 284 |
+
for option in self._get_all_options():
|
| 285 |
+
assert option.dest is not None
|
| 286 |
+
default = defaults.get(option.dest)
|
| 287 |
+
if isinstance(default, str):
|
| 288 |
+
opt_str = option.get_opt_string()
|
| 289 |
+
defaults[option.dest] = option.check_value(opt_str, default)
|
| 290 |
+
return optparse.Values(defaults)
|
| 291 |
+
|
| 292 |
+
def error(self, msg: str) -> NoReturn:
|
| 293 |
+
self.print_usage(sys.stderr)
|
| 294 |
+
self.exit(UNKNOWN_ERROR, f"{msg}\n")
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/progress_bars.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import sys
|
| 3 |
+
from typing import Callable, Generator, Iterable, Iterator, Optional, Tuple
|
| 4 |
+
|
| 5 |
+
from pip._vendor.rich.progress import (
|
| 6 |
+
BarColumn,
|
| 7 |
+
DownloadColumn,
|
| 8 |
+
FileSizeColumn,
|
| 9 |
+
Progress,
|
| 10 |
+
ProgressColumn,
|
| 11 |
+
SpinnerColumn,
|
| 12 |
+
TextColumn,
|
| 13 |
+
TimeElapsedColumn,
|
| 14 |
+
TimeRemainingColumn,
|
| 15 |
+
TransferSpeedColumn,
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
from pip._internal.cli.spinners import RateLimiter
|
| 19 |
+
from pip._internal.utils.logging import get_indentation
|
| 20 |
+
|
| 21 |
+
DownloadProgressRenderer = Callable[[Iterable[bytes]], Iterator[bytes]]
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _rich_progress_bar(
|
| 25 |
+
iterable: Iterable[bytes],
|
| 26 |
+
*,
|
| 27 |
+
bar_type: str,
|
| 28 |
+
size: Optional[int],
|
| 29 |
+
) -> Generator[bytes, None, None]:
|
| 30 |
+
assert bar_type == "on", "This should only be used in the default mode."
|
| 31 |
+
|
| 32 |
+
if not size:
|
| 33 |
+
total = float("inf")
|
| 34 |
+
columns: Tuple[ProgressColumn, ...] = (
|
| 35 |
+
TextColumn("[progress.description]{task.description}"),
|
| 36 |
+
SpinnerColumn("line", speed=1.5),
|
| 37 |
+
FileSizeColumn(),
|
| 38 |
+
TransferSpeedColumn(),
|
| 39 |
+
TimeElapsedColumn(),
|
| 40 |
+
)
|
| 41 |
+
else:
|
| 42 |
+
total = size
|
| 43 |
+
columns = (
|
| 44 |
+
TextColumn("[progress.description]{task.description}"),
|
| 45 |
+
BarColumn(),
|
| 46 |
+
DownloadColumn(),
|
| 47 |
+
TransferSpeedColumn(),
|
| 48 |
+
TextColumn("eta"),
|
| 49 |
+
TimeRemainingColumn(),
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
progress = Progress(*columns, refresh_per_second=5)
|
| 53 |
+
task_id = progress.add_task(" " * (get_indentation() + 2), total=total)
|
| 54 |
+
with progress:
|
| 55 |
+
for chunk in iterable:
|
| 56 |
+
yield chunk
|
| 57 |
+
progress.update(task_id, advance=len(chunk))
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _raw_progress_bar(
|
| 61 |
+
iterable: Iterable[bytes],
|
| 62 |
+
*,
|
| 63 |
+
size: Optional[int],
|
| 64 |
+
) -> Generator[bytes, None, None]:
|
| 65 |
+
def write_progress(current: int, total: int) -> None:
|
| 66 |
+
sys.stdout.write(f"Progress {current} of {total}\n")
|
| 67 |
+
sys.stdout.flush()
|
| 68 |
+
|
| 69 |
+
current = 0
|
| 70 |
+
total = size or 0
|
| 71 |
+
rate_limiter = RateLimiter(0.25)
|
| 72 |
+
|
| 73 |
+
write_progress(current, total)
|
| 74 |
+
for chunk in iterable:
|
| 75 |
+
current += len(chunk)
|
| 76 |
+
if rate_limiter.ready() or current == total:
|
| 77 |
+
write_progress(current, total)
|
| 78 |
+
rate_limiter.reset()
|
| 79 |
+
yield chunk
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def get_download_progress_renderer(
|
| 83 |
+
*, bar_type: str, size: Optional[int] = None
|
| 84 |
+
) -> DownloadProgressRenderer:
|
| 85 |
+
"""Get an object that can be used to render the download progress.
|
| 86 |
+
|
| 87 |
+
Returns a callable, that takes an iterable to "wrap".
|
| 88 |
+
"""
|
| 89 |
+
if bar_type == "on":
|
| 90 |
+
return functools.partial(_rich_progress_bar, bar_type=bar_type, size=size)
|
| 91 |
+
elif bar_type == "raw":
|
| 92 |
+
return functools.partial(_raw_progress_bar, size=size)
|
| 93 |
+
else:
|
| 94 |
+
return iter # no-op, when passed an iterator
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/req_command.py
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Contains the RequirementCommand base class.
|
| 2 |
+
|
| 3 |
+
This class is in a separate module so the commands that do not always
|
| 4 |
+
need PackageFinder capability don't unnecessarily import the
|
| 5 |
+
PackageFinder machinery and all its vendored dependencies, etc.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import logging
|
| 9 |
+
from functools import partial
|
| 10 |
+
from optparse import Values
|
| 11 |
+
from typing import Any, List, Optional, Tuple
|
| 12 |
+
|
| 13 |
+
from pip._internal.cache import WheelCache
|
| 14 |
+
from pip._internal.cli import cmdoptions
|
| 15 |
+
from pip._internal.cli.index_command import IndexGroupCommand
|
| 16 |
+
from pip._internal.cli.index_command import SessionCommandMixin as SessionCommandMixin
|
| 17 |
+
from pip._internal.exceptions import CommandError, PreviousBuildDirError
|
| 18 |
+
from pip._internal.index.collector import LinkCollector
|
| 19 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 20 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
| 21 |
+
from pip._internal.models.target_python import TargetPython
|
| 22 |
+
from pip._internal.network.session import PipSession
|
| 23 |
+
from pip._internal.operations.build.build_tracker import BuildTracker
|
| 24 |
+
from pip._internal.operations.prepare import RequirementPreparer
|
| 25 |
+
from pip._internal.req.constructors import (
|
| 26 |
+
install_req_from_editable,
|
| 27 |
+
install_req_from_line,
|
| 28 |
+
install_req_from_parsed_requirement,
|
| 29 |
+
install_req_from_req_string,
|
| 30 |
+
)
|
| 31 |
+
from pip._internal.req.req_file import parse_requirements
|
| 32 |
+
from pip._internal.req.req_install import InstallRequirement
|
| 33 |
+
from pip._internal.resolution.base import BaseResolver
|
| 34 |
+
from pip._internal.utils.temp_dir import (
|
| 35 |
+
TempDirectory,
|
| 36 |
+
TempDirectoryTypeRegistry,
|
| 37 |
+
tempdir_kinds,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
logger = logging.getLogger(__name__)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
KEEPABLE_TEMPDIR_TYPES = [
|
| 44 |
+
tempdir_kinds.BUILD_ENV,
|
| 45 |
+
tempdir_kinds.EPHEM_WHEEL_CACHE,
|
| 46 |
+
tempdir_kinds.REQ_BUILD,
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def with_cleanup(func: Any) -> Any:
|
| 51 |
+
"""Decorator for common logic related to managing temporary
|
| 52 |
+
directories.
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def configure_tempdir_registry(registry: TempDirectoryTypeRegistry) -> None:
|
| 56 |
+
for t in KEEPABLE_TEMPDIR_TYPES:
|
| 57 |
+
registry.set_delete(t, False)
|
| 58 |
+
|
| 59 |
+
def wrapper(
|
| 60 |
+
self: RequirementCommand, options: Values, args: List[Any]
|
| 61 |
+
) -> Optional[int]:
|
| 62 |
+
assert self.tempdir_registry is not None
|
| 63 |
+
if options.no_clean:
|
| 64 |
+
configure_tempdir_registry(self.tempdir_registry)
|
| 65 |
+
|
| 66 |
+
try:
|
| 67 |
+
return func(self, options, args)
|
| 68 |
+
except PreviousBuildDirError:
|
| 69 |
+
# This kind of conflict can occur when the user passes an explicit
|
| 70 |
+
# build directory with a pre-existing folder. In that case we do
|
| 71 |
+
# not want to accidentally remove it.
|
| 72 |
+
configure_tempdir_registry(self.tempdir_registry)
|
| 73 |
+
raise
|
| 74 |
+
|
| 75 |
+
return wrapper
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
class RequirementCommand(IndexGroupCommand):
|
| 79 |
+
def __init__(self, *args: Any, **kw: Any) -> None:
|
| 80 |
+
super().__init__(*args, **kw)
|
| 81 |
+
|
| 82 |
+
self.cmd_opts.add_option(cmdoptions.no_clean())
|
| 83 |
+
|
| 84 |
+
@staticmethod
|
| 85 |
+
def determine_resolver_variant(options: Values) -> str:
|
| 86 |
+
"""Determines which resolver should be used, based on the given options."""
|
| 87 |
+
if "legacy-resolver" in options.deprecated_features_enabled:
|
| 88 |
+
return "legacy"
|
| 89 |
+
|
| 90 |
+
return "resolvelib"
|
| 91 |
+
|
| 92 |
+
@classmethod
|
| 93 |
+
def make_requirement_preparer(
|
| 94 |
+
cls,
|
| 95 |
+
temp_build_dir: TempDirectory,
|
| 96 |
+
options: Values,
|
| 97 |
+
build_tracker: BuildTracker,
|
| 98 |
+
session: PipSession,
|
| 99 |
+
finder: PackageFinder,
|
| 100 |
+
use_user_site: bool,
|
| 101 |
+
download_dir: Optional[str] = None,
|
| 102 |
+
verbosity: int = 0,
|
| 103 |
+
) -> RequirementPreparer:
|
| 104 |
+
"""
|
| 105 |
+
Create a RequirementPreparer instance for the given parameters.
|
| 106 |
+
"""
|
| 107 |
+
temp_build_dir_path = temp_build_dir.path
|
| 108 |
+
assert temp_build_dir_path is not None
|
| 109 |
+
legacy_resolver = False
|
| 110 |
+
|
| 111 |
+
resolver_variant = cls.determine_resolver_variant(options)
|
| 112 |
+
if resolver_variant == "resolvelib":
|
| 113 |
+
lazy_wheel = "fast-deps" in options.features_enabled
|
| 114 |
+
if lazy_wheel:
|
| 115 |
+
logger.warning(
|
| 116 |
+
"pip is using lazily downloaded wheels using HTTP "
|
| 117 |
+
"range requests to obtain dependency information. "
|
| 118 |
+
"This experimental feature is enabled through "
|
| 119 |
+
"--use-feature=fast-deps and it is not ready for "
|
| 120 |
+
"production."
|
| 121 |
+
)
|
| 122 |
+
else:
|
| 123 |
+
legacy_resolver = True
|
| 124 |
+
lazy_wheel = False
|
| 125 |
+
if "fast-deps" in options.features_enabled:
|
| 126 |
+
logger.warning(
|
| 127 |
+
"fast-deps has no effect when used with the legacy resolver."
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
return RequirementPreparer(
|
| 131 |
+
build_dir=temp_build_dir_path,
|
| 132 |
+
src_dir=options.src_dir,
|
| 133 |
+
download_dir=download_dir,
|
| 134 |
+
build_isolation=options.build_isolation,
|
| 135 |
+
check_build_deps=options.check_build_deps,
|
| 136 |
+
build_tracker=build_tracker,
|
| 137 |
+
session=session,
|
| 138 |
+
progress_bar=options.progress_bar,
|
| 139 |
+
finder=finder,
|
| 140 |
+
require_hashes=options.require_hashes,
|
| 141 |
+
use_user_site=use_user_site,
|
| 142 |
+
lazy_wheel=lazy_wheel,
|
| 143 |
+
verbosity=verbosity,
|
| 144 |
+
legacy_resolver=legacy_resolver,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
@classmethod
|
| 148 |
+
def make_resolver(
|
| 149 |
+
cls,
|
| 150 |
+
preparer: RequirementPreparer,
|
| 151 |
+
finder: PackageFinder,
|
| 152 |
+
options: Values,
|
| 153 |
+
wheel_cache: Optional[WheelCache] = None,
|
| 154 |
+
use_user_site: bool = False,
|
| 155 |
+
ignore_installed: bool = True,
|
| 156 |
+
ignore_requires_python: bool = False,
|
| 157 |
+
force_reinstall: bool = False,
|
| 158 |
+
upgrade_strategy: str = "to-satisfy-only",
|
| 159 |
+
use_pep517: Optional[bool] = None,
|
| 160 |
+
py_version_info: Optional[Tuple[int, ...]] = None,
|
| 161 |
+
) -> BaseResolver:
|
| 162 |
+
"""
|
| 163 |
+
Create a Resolver instance for the given parameters.
|
| 164 |
+
"""
|
| 165 |
+
make_install_req = partial(
|
| 166 |
+
install_req_from_req_string,
|
| 167 |
+
isolated=options.isolated_mode,
|
| 168 |
+
use_pep517=use_pep517,
|
| 169 |
+
)
|
| 170 |
+
resolver_variant = cls.determine_resolver_variant(options)
|
| 171 |
+
# The long import name and duplicated invocation is needed to convince
|
| 172 |
+
# Mypy into correctly typechecking. Otherwise it would complain the
|
| 173 |
+
# "Resolver" class being redefined.
|
| 174 |
+
if resolver_variant == "resolvelib":
|
| 175 |
+
import pip._internal.resolution.resolvelib.resolver
|
| 176 |
+
|
| 177 |
+
return pip._internal.resolution.resolvelib.resolver.Resolver(
|
| 178 |
+
preparer=preparer,
|
| 179 |
+
finder=finder,
|
| 180 |
+
wheel_cache=wheel_cache,
|
| 181 |
+
make_install_req=make_install_req,
|
| 182 |
+
use_user_site=use_user_site,
|
| 183 |
+
ignore_dependencies=options.ignore_dependencies,
|
| 184 |
+
ignore_installed=ignore_installed,
|
| 185 |
+
ignore_requires_python=ignore_requires_python,
|
| 186 |
+
force_reinstall=force_reinstall,
|
| 187 |
+
upgrade_strategy=upgrade_strategy,
|
| 188 |
+
py_version_info=py_version_info,
|
| 189 |
+
)
|
| 190 |
+
import pip._internal.resolution.legacy.resolver
|
| 191 |
+
|
| 192 |
+
return pip._internal.resolution.legacy.resolver.Resolver(
|
| 193 |
+
preparer=preparer,
|
| 194 |
+
finder=finder,
|
| 195 |
+
wheel_cache=wheel_cache,
|
| 196 |
+
make_install_req=make_install_req,
|
| 197 |
+
use_user_site=use_user_site,
|
| 198 |
+
ignore_dependencies=options.ignore_dependencies,
|
| 199 |
+
ignore_installed=ignore_installed,
|
| 200 |
+
ignore_requires_python=ignore_requires_python,
|
| 201 |
+
force_reinstall=force_reinstall,
|
| 202 |
+
upgrade_strategy=upgrade_strategy,
|
| 203 |
+
py_version_info=py_version_info,
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
def get_requirements(
|
| 207 |
+
self,
|
| 208 |
+
args: List[str],
|
| 209 |
+
options: Values,
|
| 210 |
+
finder: PackageFinder,
|
| 211 |
+
session: PipSession,
|
| 212 |
+
) -> List[InstallRequirement]:
|
| 213 |
+
"""
|
| 214 |
+
Parse command-line arguments into the corresponding requirements.
|
| 215 |
+
"""
|
| 216 |
+
requirements: List[InstallRequirement] = []
|
| 217 |
+
for filename in options.constraints:
|
| 218 |
+
for parsed_req in parse_requirements(
|
| 219 |
+
filename,
|
| 220 |
+
constraint=True,
|
| 221 |
+
finder=finder,
|
| 222 |
+
options=options,
|
| 223 |
+
session=session,
|
| 224 |
+
):
|
| 225 |
+
req_to_add = install_req_from_parsed_requirement(
|
| 226 |
+
parsed_req,
|
| 227 |
+
isolated=options.isolated_mode,
|
| 228 |
+
user_supplied=False,
|
| 229 |
+
)
|
| 230 |
+
requirements.append(req_to_add)
|
| 231 |
+
|
| 232 |
+
for req in args:
|
| 233 |
+
req_to_add = install_req_from_line(
|
| 234 |
+
req,
|
| 235 |
+
comes_from=None,
|
| 236 |
+
isolated=options.isolated_mode,
|
| 237 |
+
use_pep517=options.use_pep517,
|
| 238 |
+
user_supplied=True,
|
| 239 |
+
config_settings=getattr(options, "config_settings", None),
|
| 240 |
+
)
|
| 241 |
+
requirements.append(req_to_add)
|
| 242 |
+
|
| 243 |
+
for req in options.editables:
|
| 244 |
+
req_to_add = install_req_from_editable(
|
| 245 |
+
req,
|
| 246 |
+
user_supplied=True,
|
| 247 |
+
isolated=options.isolated_mode,
|
| 248 |
+
use_pep517=options.use_pep517,
|
| 249 |
+
config_settings=getattr(options, "config_settings", None),
|
| 250 |
+
)
|
| 251 |
+
requirements.append(req_to_add)
|
| 252 |
+
|
| 253 |
+
# NOTE: options.require_hashes may be set if --require-hashes is True
|
| 254 |
+
for filename in options.requirements:
|
| 255 |
+
for parsed_req in parse_requirements(
|
| 256 |
+
filename, finder=finder, options=options, session=session
|
| 257 |
+
):
|
| 258 |
+
req_to_add = install_req_from_parsed_requirement(
|
| 259 |
+
parsed_req,
|
| 260 |
+
isolated=options.isolated_mode,
|
| 261 |
+
use_pep517=options.use_pep517,
|
| 262 |
+
user_supplied=True,
|
| 263 |
+
config_settings=(
|
| 264 |
+
parsed_req.options.get("config_settings")
|
| 265 |
+
if parsed_req.options
|
| 266 |
+
else None
|
| 267 |
+
),
|
| 268 |
+
)
|
| 269 |
+
requirements.append(req_to_add)
|
| 270 |
+
|
| 271 |
+
# If any requirement has hash options, enable hash checking.
|
| 272 |
+
if any(req.has_hash_options for req in requirements):
|
| 273 |
+
options.require_hashes = True
|
| 274 |
+
|
| 275 |
+
if not (args or options.editables or options.requirements):
|
| 276 |
+
opts = {"name": self.name}
|
| 277 |
+
if options.find_links:
|
| 278 |
+
raise CommandError(
|
| 279 |
+
"You must give at least one requirement to {name} "
|
| 280 |
+
'(maybe you meant "pip {name} {links}"?)'.format(
|
| 281 |
+
**dict(opts, links=" ".join(options.find_links))
|
| 282 |
+
)
|
| 283 |
+
)
|
| 284 |
+
else:
|
| 285 |
+
raise CommandError(
|
| 286 |
+
"You must give at least one requirement to {name} "
|
| 287 |
+
'(see "pip help {name}")'.format(**opts)
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
return requirements
|
| 291 |
+
|
| 292 |
+
@staticmethod
|
| 293 |
+
def trace_basic_info(finder: PackageFinder) -> None:
|
| 294 |
+
"""
|
| 295 |
+
Trace basic information about the provided objects.
|
| 296 |
+
"""
|
| 297 |
+
# Display where finder is looking for packages
|
| 298 |
+
search_scope = finder.search_scope
|
| 299 |
+
locations = search_scope.get_formatted_locations()
|
| 300 |
+
if locations:
|
| 301 |
+
logger.info(locations)
|
| 302 |
+
|
| 303 |
+
def _build_package_finder(
|
| 304 |
+
self,
|
| 305 |
+
options: Values,
|
| 306 |
+
session: PipSession,
|
| 307 |
+
target_python: Optional[TargetPython] = None,
|
| 308 |
+
ignore_requires_python: Optional[bool] = None,
|
| 309 |
+
) -> PackageFinder:
|
| 310 |
+
"""
|
| 311 |
+
Create a package finder appropriate to this requirement command.
|
| 312 |
+
|
| 313 |
+
:param ignore_requires_python: Whether to ignore incompatible
|
| 314 |
+
"Requires-Python" values in links. Defaults to False.
|
| 315 |
+
"""
|
| 316 |
+
link_collector = LinkCollector.create(session, options=options)
|
| 317 |
+
selection_prefs = SelectionPreferences(
|
| 318 |
+
allow_yanked=True,
|
| 319 |
+
format_control=options.format_control,
|
| 320 |
+
allow_all_prereleases=options.pre,
|
| 321 |
+
prefer_binary=options.prefer_binary,
|
| 322 |
+
ignore_requires_python=ignore_requires_python,
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
return PackageFinder.create(
|
| 326 |
+
link_collector=link_collector,
|
| 327 |
+
selection_prefs=selection_prefs,
|
| 328 |
+
target_python=target_python,
|
| 329 |
+
)
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/spinners.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import contextlib
|
| 2 |
+
import itertools
|
| 3 |
+
import logging
|
| 4 |
+
import sys
|
| 5 |
+
import time
|
| 6 |
+
from typing import IO, Generator, Optional
|
| 7 |
+
|
| 8 |
+
from pip._internal.utils.compat import WINDOWS
|
| 9 |
+
from pip._internal.utils.logging import get_indentation
|
| 10 |
+
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class SpinnerInterface:
|
| 15 |
+
def spin(self) -> None:
|
| 16 |
+
raise NotImplementedError()
|
| 17 |
+
|
| 18 |
+
def finish(self, final_status: str) -> None:
|
| 19 |
+
raise NotImplementedError()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class InteractiveSpinner(SpinnerInterface):
|
| 23 |
+
def __init__(
|
| 24 |
+
self,
|
| 25 |
+
message: str,
|
| 26 |
+
file: Optional[IO[str]] = None,
|
| 27 |
+
spin_chars: str = "-\\|/",
|
| 28 |
+
# Empirically, 8 updates/second looks nice
|
| 29 |
+
min_update_interval_seconds: float = 0.125,
|
| 30 |
+
):
|
| 31 |
+
self._message = message
|
| 32 |
+
if file is None:
|
| 33 |
+
file = sys.stdout
|
| 34 |
+
self._file = file
|
| 35 |
+
self._rate_limiter = RateLimiter(min_update_interval_seconds)
|
| 36 |
+
self._finished = False
|
| 37 |
+
|
| 38 |
+
self._spin_cycle = itertools.cycle(spin_chars)
|
| 39 |
+
|
| 40 |
+
self._file.write(" " * get_indentation() + self._message + " ... ")
|
| 41 |
+
self._width = 0
|
| 42 |
+
|
| 43 |
+
def _write(self, status: str) -> None:
|
| 44 |
+
assert not self._finished
|
| 45 |
+
# Erase what we wrote before by backspacing to the beginning, writing
|
| 46 |
+
# spaces to overwrite the old text, and then backspacing again
|
| 47 |
+
backup = "\b" * self._width
|
| 48 |
+
self._file.write(backup + " " * self._width + backup)
|
| 49 |
+
# Now we have a blank slate to add our status
|
| 50 |
+
self._file.write(status)
|
| 51 |
+
self._width = len(status)
|
| 52 |
+
self._file.flush()
|
| 53 |
+
self._rate_limiter.reset()
|
| 54 |
+
|
| 55 |
+
def spin(self) -> None:
|
| 56 |
+
if self._finished:
|
| 57 |
+
return
|
| 58 |
+
if not self._rate_limiter.ready():
|
| 59 |
+
return
|
| 60 |
+
self._write(next(self._spin_cycle))
|
| 61 |
+
|
| 62 |
+
def finish(self, final_status: str) -> None:
|
| 63 |
+
if self._finished:
|
| 64 |
+
return
|
| 65 |
+
self._write(final_status)
|
| 66 |
+
self._file.write("\n")
|
| 67 |
+
self._file.flush()
|
| 68 |
+
self._finished = True
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
# Used for dumb terminals, non-interactive installs (no tty), etc.
|
| 72 |
+
# We still print updates occasionally (once every 60 seconds by default) to
|
| 73 |
+
# act as a keep-alive for systems like Travis-CI that take lack-of-output as
|
| 74 |
+
# an indication that a task has frozen.
|
| 75 |
+
class NonInteractiveSpinner(SpinnerInterface):
|
| 76 |
+
def __init__(self, message: str, min_update_interval_seconds: float = 60.0) -> None:
|
| 77 |
+
self._message = message
|
| 78 |
+
self._finished = False
|
| 79 |
+
self._rate_limiter = RateLimiter(min_update_interval_seconds)
|
| 80 |
+
self._update("started")
|
| 81 |
+
|
| 82 |
+
def _update(self, status: str) -> None:
|
| 83 |
+
assert not self._finished
|
| 84 |
+
self._rate_limiter.reset()
|
| 85 |
+
logger.info("%s: %s", self._message, status)
|
| 86 |
+
|
| 87 |
+
def spin(self) -> None:
|
| 88 |
+
if self._finished:
|
| 89 |
+
return
|
| 90 |
+
if not self._rate_limiter.ready():
|
| 91 |
+
return
|
| 92 |
+
self._update("still running...")
|
| 93 |
+
|
| 94 |
+
def finish(self, final_status: str) -> None:
|
| 95 |
+
if self._finished:
|
| 96 |
+
return
|
| 97 |
+
self._update(f"finished with status '{final_status}'")
|
| 98 |
+
self._finished = True
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
class RateLimiter:
|
| 102 |
+
def __init__(self, min_update_interval_seconds: float) -> None:
|
| 103 |
+
self._min_update_interval_seconds = min_update_interval_seconds
|
| 104 |
+
self._last_update: float = 0
|
| 105 |
+
|
| 106 |
+
def ready(self) -> bool:
|
| 107 |
+
now = time.time()
|
| 108 |
+
delta = now - self._last_update
|
| 109 |
+
return delta >= self._min_update_interval_seconds
|
| 110 |
+
|
| 111 |
+
def reset(self) -> None:
|
| 112 |
+
self._last_update = time.time()
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
@contextlib.contextmanager
|
| 116 |
+
def open_spinner(message: str) -> Generator[SpinnerInterface, None, None]:
|
| 117 |
+
# Interactive spinner goes directly to sys.stdout rather than being routed
|
| 118 |
+
# through the logging system, but it acts like it has level INFO,
|
| 119 |
+
# i.e. it's only displayed if we're at level INFO or better.
|
| 120 |
+
# Non-interactive spinner goes through the logging system, so it is always
|
| 121 |
+
# in sync with logging configuration.
|
| 122 |
+
if sys.stdout.isatty() and logger.getEffectiveLevel() <= logging.INFO:
|
| 123 |
+
spinner: SpinnerInterface = InteractiveSpinner(message)
|
| 124 |
+
else:
|
| 125 |
+
spinner = NonInteractiveSpinner(message)
|
| 126 |
+
try:
|
| 127 |
+
with hidden_cursor(sys.stdout):
|
| 128 |
+
yield spinner
|
| 129 |
+
except KeyboardInterrupt:
|
| 130 |
+
spinner.finish("canceled")
|
| 131 |
+
raise
|
| 132 |
+
except Exception:
|
| 133 |
+
spinner.finish("error")
|
| 134 |
+
raise
|
| 135 |
+
else:
|
| 136 |
+
spinner.finish("done")
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
HIDE_CURSOR = "\x1b[?25l"
|
| 140 |
+
SHOW_CURSOR = "\x1b[?25h"
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
@contextlib.contextmanager
|
| 144 |
+
def hidden_cursor(file: IO[str]) -> Generator[None, None, None]:
|
| 145 |
+
# The Windows terminal does not support the hide/show cursor ANSI codes,
|
| 146 |
+
# even via colorama. So don't even try.
|
| 147 |
+
if WINDOWS:
|
| 148 |
+
yield
|
| 149 |
+
# We don't want to clutter the output with control characters if we're
|
| 150 |
+
# writing to a file, or if the user is running with --quiet.
|
| 151 |
+
# See https://github.com/pypa/pip/issues/3418
|
| 152 |
+
elif not file.isatty() or logger.getEffectiveLevel() > logging.INFO:
|
| 153 |
+
yield
|
| 154 |
+
else:
|
| 155 |
+
file.write(HIDE_CURSOR)
|
| 156 |
+
try:
|
| 157 |
+
yield
|
| 158 |
+
finally:
|
| 159 |
+
file.write(SHOW_CURSOR)
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/cli/status_codes.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
SUCCESS = 0
|
| 2 |
+
ERROR = 1
|
| 3 |
+
UNKNOWN_ERROR = 2
|
| 4 |
+
VIRTUALENV_NOT_FOUND = 3
|
| 5 |
+
PREVIOUS_BUILD_DIR_ERROR = 4
|
| 6 |
+
NO_MATCHES_FOUND = 23
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (3.24 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/cache.cpython-310.pyc
ADDED
|
Binary file (6.53 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/check.cpython-310.pyc
ADDED
|
Binary file (1.96 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/completion.cpython-310.pyc
ADDED
|
Binary file (4.31 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/configuration.cpython-310.pyc
ADDED
|
Binary file (8.92 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/debug.cpython-310.pyc
ADDED
|
Binary file (6.87 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/download.cpython-310.pyc
ADDED
|
Binary file (4.19 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/freeze.cpython-310.pyc
ADDED
|
Binary file (2.99 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/hash.cpython-310.pyc
ADDED
|
Binary file (2.14 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/help.cpython-310.pyc
ADDED
|
Binary file (1.3 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/index.cpython-310.pyc
ADDED
|
Binary file (4.53 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/inspect.cpython-310.pyc
ADDED
|
Binary file (2.96 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/install.cpython-310.pyc
ADDED
|
Binary file (17.9 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/list.cpython-310.pyc
ADDED
|
Binary file (10.6 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/search.cpython-310.pyc
ADDED
|
Binary file (5.3 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/show.cpython-310.pyc
ADDED
|
Binary file (7.15 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/uninstall.cpython-310.pyc
ADDED
|
Binary file (3.32 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/__pycache__/wheel.cpython-310.pyc
ADDED
|
Binary file (4.92 kB). View file
|
|
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/check.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from optparse import Values
|
| 3 |
+
from typing import List
|
| 4 |
+
|
| 5 |
+
from pip._internal.cli.base_command import Command
|
| 6 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 7 |
+
from pip._internal.metadata import get_default_environment
|
| 8 |
+
from pip._internal.operations.check import (
|
| 9 |
+
check_package_set,
|
| 10 |
+
check_unsupported,
|
| 11 |
+
create_package_set_from_installed,
|
| 12 |
+
)
|
| 13 |
+
from pip._internal.utils.compatibility_tags import get_supported
|
| 14 |
+
from pip._internal.utils.misc import write_output
|
| 15 |
+
|
| 16 |
+
logger = logging.getLogger(__name__)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class CheckCommand(Command):
|
| 20 |
+
"""Verify installed packages have compatible dependencies."""
|
| 21 |
+
|
| 22 |
+
ignore_require_venv = True
|
| 23 |
+
usage = """
|
| 24 |
+
%prog [options]"""
|
| 25 |
+
|
| 26 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 27 |
+
package_set, parsing_probs = create_package_set_from_installed()
|
| 28 |
+
missing, conflicting = check_package_set(package_set)
|
| 29 |
+
unsupported = list(
|
| 30 |
+
check_unsupported(
|
| 31 |
+
get_default_environment().iter_installed_distributions(),
|
| 32 |
+
get_supported(),
|
| 33 |
+
)
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
for project_name in missing:
|
| 37 |
+
version = package_set[project_name].version
|
| 38 |
+
for dependency in missing[project_name]:
|
| 39 |
+
write_output(
|
| 40 |
+
"%s %s requires %s, which is not installed.",
|
| 41 |
+
project_name,
|
| 42 |
+
version,
|
| 43 |
+
dependency[0],
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
for project_name in conflicting:
|
| 47 |
+
version = package_set[project_name].version
|
| 48 |
+
for dep_name, dep_version, req in conflicting[project_name]:
|
| 49 |
+
write_output(
|
| 50 |
+
"%s %s has requirement %s, but you have %s %s.",
|
| 51 |
+
project_name,
|
| 52 |
+
version,
|
| 53 |
+
req,
|
| 54 |
+
dep_name,
|
| 55 |
+
dep_version,
|
| 56 |
+
)
|
| 57 |
+
for package in unsupported:
|
| 58 |
+
write_output(
|
| 59 |
+
"%s %s is not supported on this platform",
|
| 60 |
+
package.raw_name,
|
| 61 |
+
package.version,
|
| 62 |
+
)
|
| 63 |
+
if missing or conflicting or parsing_probs or unsupported:
|
| 64 |
+
return ERROR
|
| 65 |
+
else:
|
| 66 |
+
write_output("No broken requirements found.")
|
| 67 |
+
return SUCCESS
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/configuration.py
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
from optparse import Values
|
| 5 |
+
from typing import Any, List, Optional
|
| 6 |
+
|
| 7 |
+
from pip._internal.cli.base_command import Command
|
| 8 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 9 |
+
from pip._internal.configuration import (
|
| 10 |
+
Configuration,
|
| 11 |
+
Kind,
|
| 12 |
+
get_configuration_files,
|
| 13 |
+
kinds,
|
| 14 |
+
)
|
| 15 |
+
from pip._internal.exceptions import PipError
|
| 16 |
+
from pip._internal.utils.logging import indent_log
|
| 17 |
+
from pip._internal.utils.misc import get_prog, write_output
|
| 18 |
+
|
| 19 |
+
logger = logging.getLogger(__name__)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class ConfigurationCommand(Command):
|
| 23 |
+
"""
|
| 24 |
+
Manage local and global configuration.
|
| 25 |
+
|
| 26 |
+
Subcommands:
|
| 27 |
+
|
| 28 |
+
- list: List the active configuration (or from the file specified)
|
| 29 |
+
- edit: Edit the configuration file in an editor
|
| 30 |
+
- get: Get the value associated with command.option
|
| 31 |
+
- set: Set the command.option=value
|
| 32 |
+
- unset: Unset the value associated with command.option
|
| 33 |
+
- debug: List the configuration files and values defined under them
|
| 34 |
+
|
| 35 |
+
Configuration keys should be dot separated command and option name,
|
| 36 |
+
with the special prefix "global" affecting any command. For example,
|
| 37 |
+
"pip config set global.index-url https://example.org/" would configure
|
| 38 |
+
the index url for all commands, but "pip config set download.timeout 10"
|
| 39 |
+
would configure a 10 second timeout only for "pip download" commands.
|
| 40 |
+
|
| 41 |
+
If none of --user, --global and --site are passed, a virtual
|
| 42 |
+
environment configuration file is used if one is active and the file
|
| 43 |
+
exists. Otherwise, all modifications happen to the user file by
|
| 44 |
+
default.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
ignore_require_venv = True
|
| 48 |
+
usage = """
|
| 49 |
+
%prog [<file-option>] list
|
| 50 |
+
%prog [<file-option>] [--editor <editor-path>] edit
|
| 51 |
+
|
| 52 |
+
%prog [<file-option>] get command.option
|
| 53 |
+
%prog [<file-option>] set command.option value
|
| 54 |
+
%prog [<file-option>] unset command.option
|
| 55 |
+
%prog [<file-option>] debug
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
def add_options(self) -> None:
|
| 59 |
+
self.cmd_opts.add_option(
|
| 60 |
+
"--editor",
|
| 61 |
+
dest="editor",
|
| 62 |
+
action="store",
|
| 63 |
+
default=None,
|
| 64 |
+
help=(
|
| 65 |
+
"Editor to use to edit the file. Uses VISUAL or EDITOR "
|
| 66 |
+
"environment variables if not provided."
|
| 67 |
+
),
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
self.cmd_opts.add_option(
|
| 71 |
+
"--global",
|
| 72 |
+
dest="global_file",
|
| 73 |
+
action="store_true",
|
| 74 |
+
default=False,
|
| 75 |
+
help="Use the system-wide configuration file only",
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
self.cmd_opts.add_option(
|
| 79 |
+
"--user",
|
| 80 |
+
dest="user_file",
|
| 81 |
+
action="store_true",
|
| 82 |
+
default=False,
|
| 83 |
+
help="Use the user configuration file only",
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
self.cmd_opts.add_option(
|
| 87 |
+
"--site",
|
| 88 |
+
dest="site_file",
|
| 89 |
+
action="store_true",
|
| 90 |
+
default=False,
|
| 91 |
+
help="Use the current environment configuration file only",
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 95 |
+
|
| 96 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 97 |
+
handlers = {
|
| 98 |
+
"list": self.list_values,
|
| 99 |
+
"edit": self.open_in_editor,
|
| 100 |
+
"get": self.get_name,
|
| 101 |
+
"set": self.set_name_value,
|
| 102 |
+
"unset": self.unset_name,
|
| 103 |
+
"debug": self.list_config_values,
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
# Determine action
|
| 107 |
+
if not args or args[0] not in handlers:
|
| 108 |
+
logger.error(
|
| 109 |
+
"Need an action (%s) to perform.",
|
| 110 |
+
", ".join(sorted(handlers)),
|
| 111 |
+
)
|
| 112 |
+
return ERROR
|
| 113 |
+
|
| 114 |
+
action = args[0]
|
| 115 |
+
|
| 116 |
+
# Determine which configuration files are to be loaded
|
| 117 |
+
# Depends on whether the command is modifying.
|
| 118 |
+
try:
|
| 119 |
+
load_only = self._determine_file(
|
| 120 |
+
options, need_value=(action in ["get", "set", "unset", "edit"])
|
| 121 |
+
)
|
| 122 |
+
except PipError as e:
|
| 123 |
+
logger.error(e.args[0])
|
| 124 |
+
return ERROR
|
| 125 |
+
|
| 126 |
+
# Load a new configuration
|
| 127 |
+
self.configuration = Configuration(
|
| 128 |
+
isolated=options.isolated_mode, load_only=load_only
|
| 129 |
+
)
|
| 130 |
+
self.configuration.load()
|
| 131 |
+
|
| 132 |
+
# Error handling happens here, not in the action-handlers.
|
| 133 |
+
try:
|
| 134 |
+
handlers[action](options, args[1:])
|
| 135 |
+
except PipError as e:
|
| 136 |
+
logger.error(e.args[0])
|
| 137 |
+
return ERROR
|
| 138 |
+
|
| 139 |
+
return SUCCESS
|
| 140 |
+
|
| 141 |
+
def _determine_file(self, options: Values, need_value: bool) -> Optional[Kind]:
|
| 142 |
+
file_options = [
|
| 143 |
+
key
|
| 144 |
+
for key, value in (
|
| 145 |
+
(kinds.USER, options.user_file),
|
| 146 |
+
(kinds.GLOBAL, options.global_file),
|
| 147 |
+
(kinds.SITE, options.site_file),
|
| 148 |
+
)
|
| 149 |
+
if value
|
| 150 |
+
]
|
| 151 |
+
|
| 152 |
+
if not file_options:
|
| 153 |
+
if not need_value:
|
| 154 |
+
return None
|
| 155 |
+
# Default to user, unless there's a site file.
|
| 156 |
+
elif any(
|
| 157 |
+
os.path.exists(site_config_file)
|
| 158 |
+
for site_config_file in get_configuration_files()[kinds.SITE]
|
| 159 |
+
):
|
| 160 |
+
return kinds.SITE
|
| 161 |
+
else:
|
| 162 |
+
return kinds.USER
|
| 163 |
+
elif len(file_options) == 1:
|
| 164 |
+
return file_options[0]
|
| 165 |
+
|
| 166 |
+
raise PipError(
|
| 167 |
+
"Need exactly one file to operate upon "
|
| 168 |
+
"(--user, --site, --global) to perform."
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
def list_values(self, options: Values, args: List[str]) -> None:
|
| 172 |
+
self._get_n_args(args, "list", n=0)
|
| 173 |
+
|
| 174 |
+
for key, value in sorted(self.configuration.items()):
|
| 175 |
+
write_output("%s=%r", key, value)
|
| 176 |
+
|
| 177 |
+
def get_name(self, options: Values, args: List[str]) -> None:
|
| 178 |
+
key = self._get_n_args(args, "get [name]", n=1)
|
| 179 |
+
value = self.configuration.get_value(key)
|
| 180 |
+
|
| 181 |
+
write_output("%s", value)
|
| 182 |
+
|
| 183 |
+
def set_name_value(self, options: Values, args: List[str]) -> None:
|
| 184 |
+
key, value = self._get_n_args(args, "set [name] [value]", n=2)
|
| 185 |
+
self.configuration.set_value(key, value)
|
| 186 |
+
|
| 187 |
+
self._save_configuration()
|
| 188 |
+
|
| 189 |
+
def unset_name(self, options: Values, args: List[str]) -> None:
|
| 190 |
+
key = self._get_n_args(args, "unset [name]", n=1)
|
| 191 |
+
self.configuration.unset_value(key)
|
| 192 |
+
|
| 193 |
+
self._save_configuration()
|
| 194 |
+
|
| 195 |
+
def list_config_values(self, options: Values, args: List[str]) -> None:
|
| 196 |
+
"""List config key-value pairs across different config files"""
|
| 197 |
+
self._get_n_args(args, "debug", n=0)
|
| 198 |
+
|
| 199 |
+
self.print_env_var_values()
|
| 200 |
+
# Iterate over config files and print if they exist, and the
|
| 201 |
+
# key-value pairs present in them if they do
|
| 202 |
+
for variant, files in sorted(self.configuration.iter_config_files()):
|
| 203 |
+
write_output("%s:", variant)
|
| 204 |
+
for fname in files:
|
| 205 |
+
with indent_log():
|
| 206 |
+
file_exists = os.path.exists(fname)
|
| 207 |
+
write_output("%s, exists: %r", fname, file_exists)
|
| 208 |
+
if file_exists:
|
| 209 |
+
self.print_config_file_values(variant)
|
| 210 |
+
|
| 211 |
+
def print_config_file_values(self, variant: Kind) -> None:
|
| 212 |
+
"""Get key-value pairs from the file of a variant"""
|
| 213 |
+
for name, value in self.configuration.get_values_in_config(variant).items():
|
| 214 |
+
with indent_log():
|
| 215 |
+
write_output("%s: %s", name, value)
|
| 216 |
+
|
| 217 |
+
def print_env_var_values(self) -> None:
|
| 218 |
+
"""Get key-values pairs present as environment variables"""
|
| 219 |
+
write_output("%s:", "env_var")
|
| 220 |
+
with indent_log():
|
| 221 |
+
for key, value in sorted(self.configuration.get_environ_vars()):
|
| 222 |
+
env_var = f"PIP_{key.upper()}"
|
| 223 |
+
write_output("%s=%r", env_var, value)
|
| 224 |
+
|
| 225 |
+
def open_in_editor(self, options: Values, args: List[str]) -> None:
|
| 226 |
+
editor = self._determine_editor(options)
|
| 227 |
+
|
| 228 |
+
fname = self.configuration.get_file_to_edit()
|
| 229 |
+
if fname is None:
|
| 230 |
+
raise PipError("Could not determine appropriate file.")
|
| 231 |
+
elif '"' in fname:
|
| 232 |
+
# This shouldn't happen, unless we see a username like that.
|
| 233 |
+
# If that happens, we'd appreciate a pull request fixing this.
|
| 234 |
+
raise PipError(
|
| 235 |
+
f'Can not open an editor for a file name containing "\n{fname}'
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
try:
|
| 239 |
+
subprocess.check_call(f'{editor} "{fname}"', shell=True)
|
| 240 |
+
except FileNotFoundError as e:
|
| 241 |
+
if not e.filename:
|
| 242 |
+
e.filename = editor
|
| 243 |
+
raise
|
| 244 |
+
except subprocess.CalledProcessError as e:
|
| 245 |
+
raise PipError(f"Editor Subprocess exited with exit code {e.returncode}")
|
| 246 |
+
|
| 247 |
+
def _get_n_args(self, args: List[str], example: str, n: int) -> Any:
|
| 248 |
+
"""Helper to make sure the command got the right number of arguments"""
|
| 249 |
+
if len(args) != n:
|
| 250 |
+
msg = (
|
| 251 |
+
f"Got unexpected number of arguments, expected {n}. "
|
| 252 |
+
f'(example: "{get_prog()} config {example}")'
|
| 253 |
+
)
|
| 254 |
+
raise PipError(msg)
|
| 255 |
+
|
| 256 |
+
if n == 1:
|
| 257 |
+
return args[0]
|
| 258 |
+
else:
|
| 259 |
+
return args
|
| 260 |
+
|
| 261 |
+
def _save_configuration(self) -> None:
|
| 262 |
+
# We successfully ran a modifying command. Need to save the
|
| 263 |
+
# configuration.
|
| 264 |
+
try:
|
| 265 |
+
self.configuration.save()
|
| 266 |
+
except Exception:
|
| 267 |
+
logger.exception(
|
| 268 |
+
"Unable to save configuration. Please report this as a bug."
|
| 269 |
+
)
|
| 270 |
+
raise PipError("Internal Error.")
|
| 271 |
+
|
| 272 |
+
def _determine_editor(self, options: Values) -> str:
|
| 273 |
+
if options.editor is not None:
|
| 274 |
+
return options.editor
|
| 275 |
+
elif "VISUAL" in os.environ:
|
| 276 |
+
return os.environ["VISUAL"]
|
| 277 |
+
elif "EDITOR" in os.environ:
|
| 278 |
+
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import locale
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from optparse import Values
|
| 6 |
+
from types import ModuleType
|
| 7 |
+
from typing import Any, Dict, List, Optional
|
| 8 |
+
|
| 9 |
+
import pip._vendor
|
| 10 |
+
from pip._vendor.certifi import where
|
| 11 |
+
from pip._vendor.packaging.version import parse as parse_version
|
| 12 |
+
|
| 13 |
+
from pip._internal.cli import cmdoptions
|
| 14 |
+
from pip._internal.cli.base_command import Command
|
| 15 |
+
from pip._internal.cli.cmdoptions import make_target_python
|
| 16 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 17 |
+
from pip._internal.configuration import Configuration
|
| 18 |
+
from pip._internal.metadata import get_environment
|
| 19 |
+
from pip._internal.utils.compat import open_text_resource
|
| 20 |
+
from pip._internal.utils.logging import indent_log
|
| 21 |
+
from pip._internal.utils.misc import get_pip_version
|
| 22 |
+
|
| 23 |
+
logger = logging.getLogger(__name__)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def show_value(name: str, value: Any) -> None:
|
| 27 |
+
logger.info("%s: %s", name, value)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def show_sys_implementation() -> None:
|
| 31 |
+
logger.info("sys.implementation:")
|
| 32 |
+
implementation_name = sys.implementation.name
|
| 33 |
+
with indent_log():
|
| 34 |
+
show_value("name", implementation_name)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def create_vendor_txt_map() -> Dict[str, str]:
|
| 38 |
+
with open_text_resource("pip._vendor", "vendor.txt") as f:
|
| 39 |
+
# Purge non version specifying lines.
|
| 40 |
+
# Also, remove any space prefix or suffixes (including comments).
|
| 41 |
+
lines = [
|
| 42 |
+
line.strip().split(" ", 1)[0] for line in f.readlines() if "==" in line
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
# Transform into "module" -> version dict.
|
| 46 |
+
return dict(line.split("==", 1) for line in lines)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def get_module_from_module_name(module_name: str) -> Optional[ModuleType]:
|
| 50 |
+
# Module name can be uppercase in vendor.txt for some reason...
|
| 51 |
+
module_name = module_name.lower().replace("-", "_")
|
| 52 |
+
# PATCH: setuptools is actually only pkg_resources.
|
| 53 |
+
if module_name == "setuptools":
|
| 54 |
+
module_name = "pkg_resources"
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
__import__(f"pip._vendor.{module_name}", globals(), locals(), level=0)
|
| 58 |
+
return getattr(pip._vendor, module_name)
|
| 59 |
+
except ImportError:
|
| 60 |
+
# We allow 'truststore' to fail to import due
|
| 61 |
+
# to being unavailable on Python 3.9 and earlier.
|
| 62 |
+
if module_name == "truststore" and sys.version_info < (3, 10):
|
| 63 |
+
return None
|
| 64 |
+
raise
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def get_vendor_version_from_module(module_name: str) -> Optional[str]:
|
| 68 |
+
module = get_module_from_module_name(module_name)
|
| 69 |
+
version = getattr(module, "__version__", None)
|
| 70 |
+
|
| 71 |
+
if module and not version:
|
| 72 |
+
# Try to find version in debundled module info.
|
| 73 |
+
assert module.__file__ is not None
|
| 74 |
+
env = get_environment([os.path.dirname(module.__file__)])
|
| 75 |
+
dist = env.get_distribution(module_name)
|
| 76 |
+
if dist:
|
| 77 |
+
version = str(dist.version)
|
| 78 |
+
|
| 79 |
+
return version
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def show_actual_vendor_versions(vendor_txt_versions: Dict[str, str]) -> None:
|
| 83 |
+
"""Log the actual version and print extra info if there is
|
| 84 |
+
a conflict or if the actual version could not be imported.
|
| 85 |
+
"""
|
| 86 |
+
for module_name, expected_version in vendor_txt_versions.items():
|
| 87 |
+
extra_message = ""
|
| 88 |
+
actual_version = get_vendor_version_from_module(module_name)
|
| 89 |
+
if not actual_version:
|
| 90 |
+
extra_message = (
|
| 91 |
+
" (Unable to locate actual module version, using"
|
| 92 |
+
" vendor.txt specified version)"
|
| 93 |
+
)
|
| 94 |
+
actual_version = expected_version
|
| 95 |
+
elif parse_version(actual_version) != parse_version(expected_version):
|
| 96 |
+
extra_message = (
|
| 97 |
+
" (CONFLICT: vendor.txt suggests version should"
|
| 98 |
+
f" be {expected_version})"
|
| 99 |
+
)
|
| 100 |
+
logger.info("%s==%s%s", module_name, actual_version, extra_message)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def show_vendor_versions() -> None:
|
| 104 |
+
logger.info("vendored library versions:")
|
| 105 |
+
|
| 106 |
+
vendor_txt_versions = create_vendor_txt_map()
|
| 107 |
+
with indent_log():
|
| 108 |
+
show_actual_vendor_versions(vendor_txt_versions)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def show_tags(options: Values) -> None:
|
| 112 |
+
tag_limit = 10
|
| 113 |
+
|
| 114 |
+
target_python = make_target_python(options)
|
| 115 |
+
tags = target_python.get_sorted_tags()
|
| 116 |
+
|
| 117 |
+
# Display the target options that were explicitly provided.
|
| 118 |
+
formatted_target = target_python.format_given()
|
| 119 |
+
suffix = ""
|
| 120 |
+
if formatted_target:
|
| 121 |
+
suffix = f" (target: {formatted_target})"
|
| 122 |
+
|
| 123 |
+
msg = f"Compatible tags: {len(tags)}{suffix}"
|
| 124 |
+
logger.info(msg)
|
| 125 |
+
|
| 126 |
+
if options.verbose < 1 and len(tags) > tag_limit:
|
| 127 |
+
tags_limited = True
|
| 128 |
+
tags = tags[:tag_limit]
|
| 129 |
+
else:
|
| 130 |
+
tags_limited = False
|
| 131 |
+
|
| 132 |
+
with indent_log():
|
| 133 |
+
for tag in tags:
|
| 134 |
+
logger.info(str(tag))
|
| 135 |
+
|
| 136 |
+
if tags_limited:
|
| 137 |
+
msg = f"...\n[First {tag_limit} tags shown. Pass --verbose to show all.]"
|
| 138 |
+
logger.info(msg)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def ca_bundle_info(config: Configuration) -> str:
|
| 142 |
+
levels = {key.split(".", 1)[0] for key, _ in config.items()}
|
| 143 |
+
if not levels:
|
| 144 |
+
return "Not specified"
|
| 145 |
+
|
| 146 |
+
levels_that_override_global = ["install", "wheel", "download"]
|
| 147 |
+
global_overriding_level = [
|
| 148 |
+
level for level in levels if level in levels_that_override_global
|
| 149 |
+
]
|
| 150 |
+
if not global_overriding_level:
|
| 151 |
+
return "global"
|
| 152 |
+
|
| 153 |
+
if "global" in levels:
|
| 154 |
+
levels.remove("global")
|
| 155 |
+
return ", ".join(levels)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class DebugCommand(Command):
|
| 159 |
+
"""
|
| 160 |
+
Display debug information.
|
| 161 |
+
"""
|
| 162 |
+
|
| 163 |
+
usage = """
|
| 164 |
+
%prog <options>"""
|
| 165 |
+
ignore_require_venv = True
|
| 166 |
+
|
| 167 |
+
def add_options(self) -> None:
|
| 168 |
+
cmdoptions.add_target_python_options(self.cmd_opts)
|
| 169 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 170 |
+
self.parser.config.load()
|
| 171 |
+
|
| 172 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 173 |
+
logger.warning(
|
| 174 |
+
"This command is only meant for debugging. "
|
| 175 |
+
"Do not use this with automation for parsing and getting these "
|
| 176 |
+
"details, since the output and options of this command may "
|
| 177 |
+
"change without notice."
|
| 178 |
+
)
|
| 179 |
+
show_value("pip version", get_pip_version())
|
| 180 |
+
show_value("sys.version", sys.version)
|
| 181 |
+
show_value("sys.executable", sys.executable)
|
| 182 |
+
show_value("sys.getdefaultencoding", sys.getdefaultencoding())
|
| 183 |
+
show_value("sys.getfilesystemencoding", sys.getfilesystemencoding())
|
| 184 |
+
show_value(
|
| 185 |
+
"locale.getpreferredencoding",
|
| 186 |
+
locale.getpreferredencoding(),
|
| 187 |
+
)
|
| 188 |
+
show_value("sys.platform", sys.platform)
|
| 189 |
+
show_sys_implementation()
|
| 190 |
+
|
| 191 |
+
show_value("'cert' config value", ca_bundle_info(self.parser.config))
|
| 192 |
+
show_value("REQUESTS_CA_BUNDLE", os.environ.get("REQUESTS_CA_BUNDLE"))
|
| 193 |
+
show_value("CURL_CA_BUNDLE", os.environ.get("CURL_CA_BUNDLE"))
|
| 194 |
+
show_value("pip._vendor.certifi.where()", where())
|
| 195 |
+
show_value("pip._vendor.DEBUNDLED", pip._vendor.DEBUNDLED)
|
| 196 |
+
|
| 197 |
+
show_vendor_versions()
|
| 198 |
+
|
| 199 |
+
show_tags(options)
|
| 200 |
+
|
| 201 |
+
return SUCCESS
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/freeze.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from optparse import Values
|
| 3 |
+
from typing import AbstractSet, List
|
| 4 |
+
|
| 5 |
+
from pip._internal.cli import cmdoptions
|
| 6 |
+
from pip._internal.cli.base_command import Command
|
| 7 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 8 |
+
from pip._internal.operations.freeze import freeze
|
| 9 |
+
from pip._internal.utils.compat import stdlib_pkgs
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _should_suppress_build_backends() -> bool:
|
| 13 |
+
return sys.version_info < (3, 12)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def _dev_pkgs() -> AbstractSet[str]:
|
| 17 |
+
pkgs = {"pip"}
|
| 18 |
+
|
| 19 |
+
if _should_suppress_build_backends():
|
| 20 |
+
pkgs |= {"setuptools", "distribute", "wheel"}
|
| 21 |
+
|
| 22 |
+
return pkgs
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class FreezeCommand(Command):
|
| 26 |
+
"""
|
| 27 |
+
Output installed packages in requirements format.
|
| 28 |
+
|
| 29 |
+
packages are listed in a case-insensitive sorted order.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
ignore_require_venv = True
|
| 33 |
+
usage = """
|
| 34 |
+
%prog [options]"""
|
| 35 |
+
log_streams = ("ext://sys.stderr", "ext://sys.stderr")
|
| 36 |
+
|
| 37 |
+
def add_options(self) -> None:
|
| 38 |
+
self.cmd_opts.add_option(
|
| 39 |
+
"-r",
|
| 40 |
+
"--requirement",
|
| 41 |
+
dest="requirements",
|
| 42 |
+
action="append",
|
| 43 |
+
default=[],
|
| 44 |
+
metavar="file",
|
| 45 |
+
help=(
|
| 46 |
+
"Use the order in the given requirements file and its "
|
| 47 |
+
"comments when generating output. This option can be "
|
| 48 |
+
"used multiple times."
|
| 49 |
+
),
|
| 50 |
+
)
|
| 51 |
+
self.cmd_opts.add_option(
|
| 52 |
+
"-l",
|
| 53 |
+
"--local",
|
| 54 |
+
dest="local",
|
| 55 |
+
action="store_true",
|
| 56 |
+
default=False,
|
| 57 |
+
help=(
|
| 58 |
+
"If in a virtualenv that has global access, do not output "
|
| 59 |
+
"globally-installed packages."
|
| 60 |
+
),
|
| 61 |
+
)
|
| 62 |
+
self.cmd_opts.add_option(
|
| 63 |
+
"--user",
|
| 64 |
+
dest="user",
|
| 65 |
+
action="store_true",
|
| 66 |
+
default=False,
|
| 67 |
+
help="Only output packages installed in user-site.",
|
| 68 |
+
)
|
| 69 |
+
self.cmd_opts.add_option(cmdoptions.list_path())
|
| 70 |
+
self.cmd_opts.add_option(
|
| 71 |
+
"--all",
|
| 72 |
+
dest="freeze_all",
|
| 73 |
+
action="store_true",
|
| 74 |
+
help=(
|
| 75 |
+
"Do not skip these packages in the output:"
|
| 76 |
+
" {}".format(", ".join(_dev_pkgs()))
|
| 77 |
+
),
|
| 78 |
+
)
|
| 79 |
+
self.cmd_opts.add_option(
|
| 80 |
+
"--exclude-editable",
|
| 81 |
+
dest="exclude_editable",
|
| 82 |
+
action="store_true",
|
| 83 |
+
help="Exclude editable package from output.",
|
| 84 |
+
)
|
| 85 |
+
self.cmd_opts.add_option(cmdoptions.list_exclude())
|
| 86 |
+
|
| 87 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 88 |
+
|
| 89 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 90 |
+
skip = set(stdlib_pkgs)
|
| 91 |
+
if not options.freeze_all:
|
| 92 |
+
skip.update(_dev_pkgs())
|
| 93 |
+
|
| 94 |
+
if options.excludes:
|
| 95 |
+
skip.update(options.excludes)
|
| 96 |
+
|
| 97 |
+
cmdoptions.check_list_path_option(options)
|
| 98 |
+
|
| 99 |
+
for line in freeze(
|
| 100 |
+
requirement=options.requirements,
|
| 101 |
+
local_only=options.local,
|
| 102 |
+
user_only=options.user,
|
| 103 |
+
paths=options.path,
|
| 104 |
+
isolated=options.isolated_mode,
|
| 105 |
+
skip=skip,
|
| 106 |
+
exclude_editable=options.exclude_editable,
|
| 107 |
+
):
|
| 108 |
+
sys.stdout.write(line + "\n")
|
| 109 |
+
return SUCCESS
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/install.py
ADDED
|
@@ -0,0 +1,784 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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5 |
+
import shutil
|
| 6 |
+
import site
|
| 7 |
+
from optparse import SUPPRESS_HELP, Values
|
| 8 |
+
from typing import List, Optional
|
| 9 |
+
|
| 10 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 11 |
+
from pip._vendor.rich import print_json
|
| 12 |
+
|
| 13 |
+
# Eagerly import self_outdated_check to avoid crashes. Otherwise,
|
| 14 |
+
# this module would be imported *after* pip was replaced, resulting
|
| 15 |
+
# in crashes if the new self_outdated_check module was incompatible
|
| 16 |
+
# with the rest of pip that's already imported, or allowing a
|
| 17 |
+
# wheel to execute arbitrary code on install by replacing
|
| 18 |
+
# self_outdated_check.
|
| 19 |
+
import pip._internal.self_outdated_check # noqa: F401
|
| 20 |
+
from pip._internal.cache import WheelCache
|
| 21 |
+
from pip._internal.cli import cmdoptions
|
| 22 |
+
from pip._internal.cli.cmdoptions import make_target_python
|
| 23 |
+
from pip._internal.cli.req_command import (
|
| 24 |
+
RequirementCommand,
|
| 25 |
+
with_cleanup,
|
| 26 |
+
)
|
| 27 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 28 |
+
from pip._internal.exceptions import CommandError, InstallationError
|
| 29 |
+
from pip._internal.locations import get_scheme
|
| 30 |
+
from pip._internal.metadata import get_environment
|
| 31 |
+
from pip._internal.models.installation_report import InstallationReport
|
| 32 |
+
from pip._internal.operations.build.build_tracker import get_build_tracker
|
| 33 |
+
from pip._internal.operations.check import ConflictDetails, check_install_conflicts
|
| 34 |
+
from pip._internal.req import install_given_reqs
|
| 35 |
+
from pip._internal.req.req_install import (
|
| 36 |
+
InstallRequirement,
|
| 37 |
+
check_legacy_setup_py_options,
|
| 38 |
+
)
|
| 39 |
+
from pip._internal.utils.compat import WINDOWS
|
| 40 |
+
from pip._internal.utils.filesystem import test_writable_dir
|
| 41 |
+
from pip._internal.utils.logging import getLogger
|
| 42 |
+
from pip._internal.utils.misc import (
|
| 43 |
+
check_externally_managed,
|
| 44 |
+
ensure_dir,
|
| 45 |
+
get_pip_version,
|
| 46 |
+
protect_pip_from_modification_on_windows,
|
| 47 |
+
warn_if_run_as_root,
|
| 48 |
+
write_output,
|
| 49 |
+
)
|
| 50 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 51 |
+
from pip._internal.utils.virtualenv import (
|
| 52 |
+
running_under_virtualenv,
|
| 53 |
+
virtualenv_no_global,
|
| 54 |
+
)
|
| 55 |
+
from pip._internal.wheel_builder import build, should_build_for_install_command
|
| 56 |
+
|
| 57 |
+
logger = getLogger(__name__)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class InstallCommand(RequirementCommand):
|
| 61 |
+
"""
|
| 62 |
+
Install packages from:
|
| 63 |
+
|
| 64 |
+
- PyPI (and other indexes) using requirement specifiers.
|
| 65 |
+
- VCS project urls.
|
| 66 |
+
- Local project directories.
|
| 67 |
+
- Local or remote source archives.
|
| 68 |
+
|
| 69 |
+
pip also supports installing from "requirements files", which provide
|
| 70 |
+
an easy way to specify a whole environment to be installed.
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
usage = """
|
| 74 |
+
%prog [options] <requirement specifier> [package-index-options] ...
|
| 75 |
+
%prog [options] -r <requirements file> [package-index-options] ...
|
| 76 |
+
%prog [options] [-e] <vcs project url> ...
|
| 77 |
+
%prog [options] [-e] <local project path> ...
|
| 78 |
+
%prog [options] <archive url/path> ..."""
|
| 79 |
+
|
| 80 |
+
def add_options(self) -> None:
|
| 81 |
+
self.cmd_opts.add_option(cmdoptions.requirements())
|
| 82 |
+
self.cmd_opts.add_option(cmdoptions.constraints())
|
| 83 |
+
self.cmd_opts.add_option(cmdoptions.no_deps())
|
| 84 |
+
self.cmd_opts.add_option(cmdoptions.pre())
|
| 85 |
+
|
| 86 |
+
self.cmd_opts.add_option(cmdoptions.editable())
|
| 87 |
+
self.cmd_opts.add_option(
|
| 88 |
+
"--dry-run",
|
| 89 |
+
action="store_true",
|
| 90 |
+
dest="dry_run",
|
| 91 |
+
default=False,
|
| 92 |
+
help=(
|
| 93 |
+
"Don't actually install anything, just print what would be. "
|
| 94 |
+
"Can be used in combination with --ignore-installed "
|
| 95 |
+
"to 'resolve' the requirements."
|
| 96 |
+
),
|
| 97 |
+
)
|
| 98 |
+
self.cmd_opts.add_option(
|
| 99 |
+
"-t",
|
| 100 |
+
"--target",
|
| 101 |
+
dest="target_dir",
|
| 102 |
+
metavar="dir",
|
| 103 |
+
default=None,
|
| 104 |
+
help=(
|
| 105 |
+
"Install packages into <dir>. "
|
| 106 |
+
"By default this will not replace existing files/folders in "
|
| 107 |
+
"<dir>. Use --upgrade to replace existing packages in <dir> "
|
| 108 |
+
"with new versions."
|
| 109 |
+
),
|
| 110 |
+
)
|
| 111 |
+
cmdoptions.add_target_python_options(self.cmd_opts)
|
| 112 |
+
|
| 113 |
+
self.cmd_opts.add_option(
|
| 114 |
+
"--user",
|
| 115 |
+
dest="use_user_site",
|
| 116 |
+
action="store_true",
|
| 117 |
+
help=(
|
| 118 |
+
"Install to the Python user install directory for your "
|
| 119 |
+
"platform. Typically ~/.local/, or %APPDATA%\\Python on "
|
| 120 |
+
"Windows. (See the Python documentation for site.USER_BASE "
|
| 121 |
+
"for full details.)"
|
| 122 |
+
),
|
| 123 |
+
)
|
| 124 |
+
self.cmd_opts.add_option(
|
| 125 |
+
"--no-user",
|
| 126 |
+
dest="use_user_site",
|
| 127 |
+
action="store_false",
|
| 128 |
+
help=SUPPRESS_HELP,
|
| 129 |
+
)
|
| 130 |
+
self.cmd_opts.add_option(
|
| 131 |
+
"--root",
|
| 132 |
+
dest="root_path",
|
| 133 |
+
metavar="dir",
|
| 134 |
+
default=None,
|
| 135 |
+
help="Install everything relative to this alternate root directory.",
|
| 136 |
+
)
|
| 137 |
+
self.cmd_opts.add_option(
|
| 138 |
+
"--prefix",
|
| 139 |
+
dest="prefix_path",
|
| 140 |
+
metavar="dir",
|
| 141 |
+
default=None,
|
| 142 |
+
help=(
|
| 143 |
+
"Installation prefix where lib, bin and other top-level "
|
| 144 |
+
"folders are placed. Note that the resulting installation may "
|
| 145 |
+
"contain scripts and other resources which reference the "
|
| 146 |
+
"Python interpreter of pip, and not that of ``--prefix``. "
|
| 147 |
+
"See also the ``--python`` option if the intention is to "
|
| 148 |
+
"install packages into another (possibly pip-free) "
|
| 149 |
+
"environment."
|
| 150 |
+
),
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
self.cmd_opts.add_option(cmdoptions.src())
|
| 154 |
+
|
| 155 |
+
self.cmd_opts.add_option(
|
| 156 |
+
"-U",
|
| 157 |
+
"--upgrade",
|
| 158 |
+
dest="upgrade",
|
| 159 |
+
action="store_true",
|
| 160 |
+
help=(
|
| 161 |
+
"Upgrade all specified packages to the newest available "
|
| 162 |
+
"version. The handling of dependencies depends on the "
|
| 163 |
+
"upgrade-strategy used."
|
| 164 |
+
),
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
self.cmd_opts.add_option(
|
| 168 |
+
"--upgrade-strategy",
|
| 169 |
+
dest="upgrade_strategy",
|
| 170 |
+
default="only-if-needed",
|
| 171 |
+
choices=["only-if-needed", "eager"],
|
| 172 |
+
help=(
|
| 173 |
+
"Determines how dependency upgrading should be handled "
|
| 174 |
+
"[default: %default]. "
|
| 175 |
+
'"eager" - dependencies are upgraded regardless of '
|
| 176 |
+
"whether the currently installed version satisfies the "
|
| 177 |
+
"requirements of the upgraded package(s). "
|
| 178 |
+
'"only-if-needed" - are upgraded only when they do not '
|
| 179 |
+
"satisfy the requirements of the upgraded package(s)."
|
| 180 |
+
),
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
self.cmd_opts.add_option(
|
| 184 |
+
"--force-reinstall",
|
| 185 |
+
dest="force_reinstall",
|
| 186 |
+
action="store_true",
|
| 187 |
+
help="Reinstall all packages even if they are already up-to-date.",
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
self.cmd_opts.add_option(
|
| 191 |
+
"-I",
|
| 192 |
+
"--ignore-installed",
|
| 193 |
+
dest="ignore_installed",
|
| 194 |
+
action="store_true",
|
| 195 |
+
help=(
|
| 196 |
+
"Ignore the installed packages, overwriting them. "
|
| 197 |
+
"This can break your system if the existing package "
|
| 198 |
+
"is of a different version or was installed "
|
| 199 |
+
"with a different package manager!"
|
| 200 |
+
),
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
| 204 |
+
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
|
| 205 |
+
self.cmd_opts.add_option(cmdoptions.use_pep517())
|
| 206 |
+
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
|
| 207 |
+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
|
| 208 |
+
self.cmd_opts.add_option(cmdoptions.override_externally_managed())
|
| 209 |
+
|
| 210 |
+
self.cmd_opts.add_option(cmdoptions.config_settings())
|
| 211 |
+
self.cmd_opts.add_option(cmdoptions.global_options())
|
| 212 |
+
|
| 213 |
+
self.cmd_opts.add_option(
|
| 214 |
+
"--compile",
|
| 215 |
+
action="store_true",
|
| 216 |
+
dest="compile",
|
| 217 |
+
default=True,
|
| 218 |
+
help="Compile Python source files to bytecode",
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
self.cmd_opts.add_option(
|
| 222 |
+
"--no-compile",
|
| 223 |
+
action="store_false",
|
| 224 |
+
dest="compile",
|
| 225 |
+
help="Do not compile Python source files to bytecode",
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
self.cmd_opts.add_option(
|
| 229 |
+
"--no-warn-script-location",
|
| 230 |
+
action="store_false",
|
| 231 |
+
dest="warn_script_location",
|
| 232 |
+
default=True,
|
| 233 |
+
help="Do not warn when installing scripts outside PATH",
|
| 234 |
+
)
|
| 235 |
+
self.cmd_opts.add_option(
|
| 236 |
+
"--no-warn-conflicts",
|
| 237 |
+
action="store_false",
|
| 238 |
+
dest="warn_about_conflicts",
|
| 239 |
+
default=True,
|
| 240 |
+
help="Do not warn about broken dependencies",
|
| 241 |
+
)
|
| 242 |
+
self.cmd_opts.add_option(cmdoptions.no_binary())
|
| 243 |
+
self.cmd_opts.add_option(cmdoptions.only_binary())
|
| 244 |
+
self.cmd_opts.add_option(cmdoptions.prefer_binary())
|
| 245 |
+
self.cmd_opts.add_option(cmdoptions.require_hashes())
|
| 246 |
+
self.cmd_opts.add_option(cmdoptions.progress_bar())
|
| 247 |
+
self.cmd_opts.add_option(cmdoptions.root_user_action())
|
| 248 |
+
|
| 249 |
+
index_opts = cmdoptions.make_option_group(
|
| 250 |
+
cmdoptions.index_group,
|
| 251 |
+
self.parser,
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
self.parser.insert_option_group(0, index_opts)
|
| 255 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 256 |
+
|
| 257 |
+
self.cmd_opts.add_option(
|
| 258 |
+
"--report",
|
| 259 |
+
dest="json_report_file",
|
| 260 |
+
metavar="file",
|
| 261 |
+
default=None,
|
| 262 |
+
help=(
|
| 263 |
+
"Generate a JSON file describing what pip did to install "
|
| 264 |
+
"the provided requirements. "
|
| 265 |
+
"Can be used in combination with --dry-run and --ignore-installed "
|
| 266 |
+
"to 'resolve' the requirements. "
|
| 267 |
+
"When - is used as file name it writes to stdout. "
|
| 268 |
+
"When writing to stdout, please combine with the --quiet option "
|
| 269 |
+
"to avoid mixing pip logging output with JSON output."
|
| 270 |
+
),
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
@with_cleanup
|
| 274 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 275 |
+
if options.use_user_site and options.target_dir is not None:
|
| 276 |
+
raise CommandError("Can not combine '--user' and '--target'")
|
| 277 |
+
|
| 278 |
+
# Check whether the environment we're installing into is externally
|
| 279 |
+
# managed, as specified in PEP 668. Specifying --root, --target, or
|
| 280 |
+
# --prefix disables the check, since there's no reliable way to locate
|
| 281 |
+
# the EXTERNALLY-MANAGED file for those cases. An exception is also
|
| 282 |
+
# made specifically for "--dry-run --report" for convenience.
|
| 283 |
+
installing_into_current_environment = (
|
| 284 |
+
not (options.dry_run and options.json_report_file)
|
| 285 |
+
and options.root_path is None
|
| 286 |
+
and options.target_dir is None
|
| 287 |
+
and options.prefix_path is None
|
| 288 |
+
)
|
| 289 |
+
if (
|
| 290 |
+
installing_into_current_environment
|
| 291 |
+
and not options.override_externally_managed
|
| 292 |
+
):
|
| 293 |
+
check_externally_managed()
|
| 294 |
+
|
| 295 |
+
upgrade_strategy = "to-satisfy-only"
|
| 296 |
+
if options.upgrade:
|
| 297 |
+
upgrade_strategy = options.upgrade_strategy
|
| 298 |
+
|
| 299 |
+
cmdoptions.check_dist_restriction(options, check_target=True)
|
| 300 |
+
|
| 301 |
+
logger.verbose("Using %s", get_pip_version())
|
| 302 |
+
options.use_user_site = decide_user_install(
|
| 303 |
+
options.use_user_site,
|
| 304 |
+
prefix_path=options.prefix_path,
|
| 305 |
+
target_dir=options.target_dir,
|
| 306 |
+
root_path=options.root_path,
|
| 307 |
+
isolated_mode=options.isolated_mode,
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
target_temp_dir: Optional[TempDirectory] = None
|
| 311 |
+
target_temp_dir_path: Optional[str] = None
|
| 312 |
+
if options.target_dir:
|
| 313 |
+
options.ignore_installed = True
|
| 314 |
+
options.target_dir = os.path.abspath(options.target_dir)
|
| 315 |
+
if (
|
| 316 |
+
# fmt: off
|
| 317 |
+
os.path.exists(options.target_dir) and
|
| 318 |
+
not os.path.isdir(options.target_dir)
|
| 319 |
+
# fmt: on
|
| 320 |
+
):
|
| 321 |
+
raise CommandError(
|
| 322 |
+
"Target path exists but is not a directory, will not continue."
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
# Create a target directory for using with the target option
|
| 326 |
+
target_temp_dir = TempDirectory(kind="target")
|
| 327 |
+
target_temp_dir_path = target_temp_dir.path
|
| 328 |
+
self.enter_context(target_temp_dir)
|
| 329 |
+
|
| 330 |
+
global_options = options.global_options or []
|
| 331 |
+
|
| 332 |
+
session = self.get_default_session(options)
|
| 333 |
+
|
| 334 |
+
target_python = make_target_python(options)
|
| 335 |
+
finder = self._build_package_finder(
|
| 336 |
+
options=options,
|
| 337 |
+
session=session,
|
| 338 |
+
target_python=target_python,
|
| 339 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 340 |
+
)
|
| 341 |
+
build_tracker = self.enter_context(get_build_tracker())
|
| 342 |
+
|
| 343 |
+
directory = TempDirectory(
|
| 344 |
+
delete=not options.no_clean,
|
| 345 |
+
kind="install",
|
| 346 |
+
globally_managed=True,
|
| 347 |
+
)
|
| 348 |
+
|
| 349 |
+
try:
|
| 350 |
+
reqs = self.get_requirements(args, options, finder, session)
|
| 351 |
+
check_legacy_setup_py_options(options, reqs)
|
| 352 |
+
|
| 353 |
+
wheel_cache = WheelCache(options.cache_dir)
|
| 354 |
+
|
| 355 |
+
# Only when installing is it permitted to use PEP 660.
|
| 356 |
+
# In other circumstances (pip wheel, pip download) we generate
|
| 357 |
+
# regular (i.e. non editable) metadata and wheels.
|
| 358 |
+
for req in reqs:
|
| 359 |
+
req.permit_editable_wheels = True
|
| 360 |
+
|
| 361 |
+
preparer = self.make_requirement_preparer(
|
| 362 |
+
temp_build_dir=directory,
|
| 363 |
+
options=options,
|
| 364 |
+
build_tracker=build_tracker,
|
| 365 |
+
session=session,
|
| 366 |
+
finder=finder,
|
| 367 |
+
use_user_site=options.use_user_site,
|
| 368 |
+
verbosity=self.verbosity,
|
| 369 |
+
)
|
| 370 |
+
resolver = self.make_resolver(
|
| 371 |
+
preparer=preparer,
|
| 372 |
+
finder=finder,
|
| 373 |
+
options=options,
|
| 374 |
+
wheel_cache=wheel_cache,
|
| 375 |
+
use_user_site=options.use_user_site,
|
| 376 |
+
ignore_installed=options.ignore_installed,
|
| 377 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 378 |
+
force_reinstall=options.force_reinstall,
|
| 379 |
+
upgrade_strategy=upgrade_strategy,
|
| 380 |
+
use_pep517=options.use_pep517,
|
| 381 |
+
py_version_info=options.python_version,
|
| 382 |
+
)
|
| 383 |
+
|
| 384 |
+
self.trace_basic_info(finder)
|
| 385 |
+
|
| 386 |
+
requirement_set = resolver.resolve(
|
| 387 |
+
reqs, check_supported_wheels=not options.target_dir
|
| 388 |
+
)
|
| 389 |
+
|
| 390 |
+
if options.json_report_file:
|
| 391 |
+
report = InstallationReport(requirement_set.requirements_to_install)
|
| 392 |
+
if options.json_report_file == "-":
|
| 393 |
+
print_json(data=report.to_dict())
|
| 394 |
+
else:
|
| 395 |
+
with open(options.json_report_file, "w", encoding="utf-8") as f:
|
| 396 |
+
json.dump(report.to_dict(), f, indent=2, ensure_ascii=False)
|
| 397 |
+
|
| 398 |
+
if options.dry_run:
|
| 399 |
+
would_install_items = sorted(
|
| 400 |
+
(r.metadata["name"], r.metadata["version"])
|
| 401 |
+
for r in requirement_set.requirements_to_install
|
| 402 |
+
)
|
| 403 |
+
if would_install_items:
|
| 404 |
+
write_output(
|
| 405 |
+
"Would install %s",
|
| 406 |
+
" ".join("-".join(item) for item in would_install_items),
|
| 407 |
+
)
|
| 408 |
+
return SUCCESS
|
| 409 |
+
|
| 410 |
+
try:
|
| 411 |
+
pip_req = requirement_set.get_requirement("pip")
|
| 412 |
+
except KeyError:
|
| 413 |
+
modifying_pip = False
|
| 414 |
+
else:
|
| 415 |
+
# If we're not replacing an already installed pip,
|
| 416 |
+
# we're not modifying it.
|
| 417 |
+
modifying_pip = pip_req.satisfied_by is None
|
| 418 |
+
protect_pip_from_modification_on_windows(modifying_pip=modifying_pip)
|
| 419 |
+
|
| 420 |
+
reqs_to_build = [
|
| 421 |
+
r
|
| 422 |
+
for r in requirement_set.requirements.values()
|
| 423 |
+
if should_build_for_install_command(r)
|
| 424 |
+
]
|
| 425 |
+
|
| 426 |
+
_, build_failures = build(
|
| 427 |
+
reqs_to_build,
|
| 428 |
+
wheel_cache=wheel_cache,
|
| 429 |
+
verify=True,
|
| 430 |
+
build_options=[],
|
| 431 |
+
global_options=global_options,
|
| 432 |
+
)
|
| 433 |
+
|
| 434 |
+
if build_failures:
|
| 435 |
+
raise InstallationError(
|
| 436 |
+
"Failed to build installable wheels for some "
|
| 437 |
+
"pyproject.toml based projects ({})".format(
|
| 438 |
+
", ".join(r.name for r in build_failures) # type: ignore
|
| 439 |
+
)
|
| 440 |
+
)
|
| 441 |
+
|
| 442 |
+
to_install = resolver.get_installation_order(requirement_set)
|
| 443 |
+
|
| 444 |
+
# Check for conflicts in the package set we're installing.
|
| 445 |
+
conflicts: Optional[ConflictDetails] = None
|
| 446 |
+
should_warn_about_conflicts = (
|
| 447 |
+
not options.ignore_dependencies and options.warn_about_conflicts
|
| 448 |
+
)
|
| 449 |
+
if should_warn_about_conflicts:
|
| 450 |
+
conflicts = self._determine_conflicts(to_install)
|
| 451 |
+
|
| 452 |
+
# Don't warn about script install locations if
|
| 453 |
+
# --target or --prefix has been specified
|
| 454 |
+
warn_script_location = options.warn_script_location
|
| 455 |
+
if options.target_dir or options.prefix_path:
|
| 456 |
+
warn_script_location = False
|
| 457 |
+
|
| 458 |
+
installed = install_given_reqs(
|
| 459 |
+
to_install,
|
| 460 |
+
global_options,
|
| 461 |
+
root=options.root_path,
|
| 462 |
+
home=target_temp_dir_path,
|
| 463 |
+
prefix=options.prefix_path,
|
| 464 |
+
warn_script_location=warn_script_location,
|
| 465 |
+
use_user_site=options.use_user_site,
|
| 466 |
+
pycompile=options.compile,
|
| 467 |
+
)
|
| 468 |
+
|
| 469 |
+
lib_locations = get_lib_location_guesses(
|
| 470 |
+
user=options.use_user_site,
|
| 471 |
+
home=target_temp_dir_path,
|
| 472 |
+
root=options.root_path,
|
| 473 |
+
prefix=options.prefix_path,
|
| 474 |
+
isolated=options.isolated_mode,
|
| 475 |
+
)
|
| 476 |
+
env = get_environment(lib_locations)
|
| 477 |
+
|
| 478 |
+
# Display a summary of installed packages, with extra care to
|
| 479 |
+
# display a package name as it was requested by the user.
|
| 480 |
+
installed.sort(key=operator.attrgetter("name"))
|
| 481 |
+
summary = []
|
| 482 |
+
installed_versions = {}
|
| 483 |
+
for distribution in env.iter_all_distributions():
|
| 484 |
+
installed_versions[distribution.canonical_name] = distribution.version
|
| 485 |
+
for package in installed:
|
| 486 |
+
display_name = package.name
|
| 487 |
+
version = installed_versions.get(canonicalize_name(display_name), None)
|
| 488 |
+
if version:
|
| 489 |
+
text = f"{display_name}-{version}"
|
| 490 |
+
else:
|
| 491 |
+
text = display_name
|
| 492 |
+
summary.append(text)
|
| 493 |
+
|
| 494 |
+
if conflicts is not None:
|
| 495 |
+
self._warn_about_conflicts(
|
| 496 |
+
conflicts,
|
| 497 |
+
resolver_variant=self.determine_resolver_variant(options),
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
+
installed_desc = " ".join(summary)
|
| 501 |
+
if installed_desc:
|
| 502 |
+
write_output(
|
| 503 |
+
"Successfully installed %s",
|
| 504 |
+
installed_desc,
|
| 505 |
+
)
|
| 506 |
+
except OSError as error:
|
| 507 |
+
show_traceback = self.verbosity >= 1
|
| 508 |
+
|
| 509 |
+
message = create_os_error_message(
|
| 510 |
+
error,
|
| 511 |
+
show_traceback,
|
| 512 |
+
options.use_user_site,
|
| 513 |
+
)
|
| 514 |
+
logger.error(message, exc_info=show_traceback)
|
| 515 |
+
|
| 516 |
+
return ERROR
|
| 517 |
+
|
| 518 |
+
if options.target_dir:
|
| 519 |
+
assert target_temp_dir
|
| 520 |
+
self._handle_target_dir(
|
| 521 |
+
options.target_dir, target_temp_dir, options.upgrade
|
| 522 |
+
)
|
| 523 |
+
if options.root_user_action == "warn":
|
| 524 |
+
warn_if_run_as_root()
|
| 525 |
+
return SUCCESS
|
| 526 |
+
|
| 527 |
+
def _handle_target_dir(
|
| 528 |
+
self, target_dir: str, target_temp_dir: TempDirectory, upgrade: bool
|
| 529 |
+
) -> None:
|
| 530 |
+
ensure_dir(target_dir)
|
| 531 |
+
|
| 532 |
+
# Checking both purelib and platlib directories for installed
|
| 533 |
+
# packages to be moved to target directory
|
| 534 |
+
lib_dir_list = []
|
| 535 |
+
|
| 536 |
+
# Checking both purelib and platlib directories for installed
|
| 537 |
+
# packages to be moved to target directory
|
| 538 |
+
scheme = get_scheme("", home=target_temp_dir.path)
|
| 539 |
+
purelib_dir = scheme.purelib
|
| 540 |
+
platlib_dir = scheme.platlib
|
| 541 |
+
data_dir = scheme.data
|
| 542 |
+
|
| 543 |
+
if os.path.exists(purelib_dir):
|
| 544 |
+
lib_dir_list.append(purelib_dir)
|
| 545 |
+
if os.path.exists(platlib_dir) and platlib_dir != purelib_dir:
|
| 546 |
+
lib_dir_list.append(platlib_dir)
|
| 547 |
+
if os.path.exists(data_dir):
|
| 548 |
+
lib_dir_list.append(data_dir)
|
| 549 |
+
|
| 550 |
+
for lib_dir in lib_dir_list:
|
| 551 |
+
for item in os.listdir(lib_dir):
|
| 552 |
+
if lib_dir == data_dir:
|
| 553 |
+
ddir = os.path.join(data_dir, item)
|
| 554 |
+
if any(s.startswith(ddir) for s in lib_dir_list[:-1]):
|
| 555 |
+
continue
|
| 556 |
+
target_item_dir = os.path.join(target_dir, item)
|
| 557 |
+
if os.path.exists(target_item_dir):
|
| 558 |
+
if not upgrade:
|
| 559 |
+
logger.warning(
|
| 560 |
+
"Target directory %s already exists. Specify "
|
| 561 |
+
"--upgrade to force replacement.",
|
| 562 |
+
target_item_dir,
|
| 563 |
+
)
|
| 564 |
+
continue
|
| 565 |
+
if os.path.islink(target_item_dir):
|
| 566 |
+
logger.warning(
|
| 567 |
+
"Target directory %s already exists and is "
|
| 568 |
+
"a link. pip will not automatically replace "
|
| 569 |
+
"links, please remove if replacement is "
|
| 570 |
+
"desired.",
|
| 571 |
+
target_item_dir,
|
| 572 |
+
)
|
| 573 |
+
continue
|
| 574 |
+
if os.path.isdir(target_item_dir):
|
| 575 |
+
shutil.rmtree(target_item_dir)
|
| 576 |
+
else:
|
| 577 |
+
os.remove(target_item_dir)
|
| 578 |
+
|
| 579 |
+
shutil.move(os.path.join(lib_dir, item), target_item_dir)
|
| 580 |
+
|
| 581 |
+
def _determine_conflicts(
|
| 582 |
+
self, to_install: List[InstallRequirement]
|
| 583 |
+
) -> Optional[ConflictDetails]:
|
| 584 |
+
try:
|
| 585 |
+
return check_install_conflicts(to_install)
|
| 586 |
+
except Exception:
|
| 587 |
+
logger.exception(
|
| 588 |
+
"Error while checking for conflicts. Please file an issue on "
|
| 589 |
+
"pip's issue tracker: https://github.com/pypa/pip/issues/new"
|
| 590 |
+
)
|
| 591 |
+
return None
|
| 592 |
+
|
| 593 |
+
def _warn_about_conflicts(
|
| 594 |
+
self, conflict_details: ConflictDetails, resolver_variant: str
|
| 595 |
+
) -> None:
|
| 596 |
+
package_set, (missing, conflicting) = conflict_details
|
| 597 |
+
if not missing and not conflicting:
|
| 598 |
+
return
|
| 599 |
+
|
| 600 |
+
parts: List[str] = []
|
| 601 |
+
if resolver_variant == "legacy":
|
| 602 |
+
parts.append(
|
| 603 |
+
"pip's legacy dependency resolver does not consider dependency "
|
| 604 |
+
"conflicts when selecting packages. This behaviour is the "
|
| 605 |
+
"source of the following dependency conflicts."
|
| 606 |
+
)
|
| 607 |
+
else:
|
| 608 |
+
assert resolver_variant == "resolvelib"
|
| 609 |
+
parts.append(
|
| 610 |
+
"pip's dependency resolver does not currently take into account "
|
| 611 |
+
"all the packages that are installed. This behaviour is the "
|
| 612 |
+
"source of the following dependency conflicts."
|
| 613 |
+
)
|
| 614 |
+
|
| 615 |
+
# NOTE: There is some duplication here, with commands/check.py
|
| 616 |
+
for project_name in missing:
|
| 617 |
+
version = package_set[project_name][0]
|
| 618 |
+
for dependency in missing[project_name]:
|
| 619 |
+
message = (
|
| 620 |
+
f"{project_name} {version} requires {dependency[1]}, "
|
| 621 |
+
"which is not installed."
|
| 622 |
+
)
|
| 623 |
+
parts.append(message)
|
| 624 |
+
|
| 625 |
+
for project_name in conflicting:
|
| 626 |
+
version = package_set[project_name][0]
|
| 627 |
+
for dep_name, dep_version, req in conflicting[project_name]:
|
| 628 |
+
message = (
|
| 629 |
+
"{name} {version} requires {requirement}, but {you} have "
|
| 630 |
+
"{dep_name} {dep_version} which is incompatible."
|
| 631 |
+
).format(
|
| 632 |
+
name=project_name,
|
| 633 |
+
version=version,
|
| 634 |
+
requirement=req,
|
| 635 |
+
dep_name=dep_name,
|
| 636 |
+
dep_version=dep_version,
|
| 637 |
+
you=("you" if resolver_variant == "resolvelib" else "you'll"),
|
| 638 |
+
)
|
| 639 |
+
parts.append(message)
|
| 640 |
+
|
| 641 |
+
logger.critical("\n".join(parts))
|
| 642 |
+
|
| 643 |
+
|
| 644 |
+
def get_lib_location_guesses(
|
| 645 |
+
user: bool = False,
|
| 646 |
+
home: Optional[str] = None,
|
| 647 |
+
root: Optional[str] = None,
|
| 648 |
+
isolated: bool = False,
|
| 649 |
+
prefix: Optional[str] = None,
|
| 650 |
+
) -> List[str]:
|
| 651 |
+
scheme = get_scheme(
|
| 652 |
+
"",
|
| 653 |
+
user=user,
|
| 654 |
+
home=home,
|
| 655 |
+
root=root,
|
| 656 |
+
isolated=isolated,
|
| 657 |
+
prefix=prefix,
|
| 658 |
+
)
|
| 659 |
+
return [scheme.purelib, scheme.platlib]
|
| 660 |
+
|
| 661 |
+
|
| 662 |
+
def site_packages_writable(root: Optional[str], isolated: bool) -> bool:
|
| 663 |
+
return all(
|
| 664 |
+
test_writable_dir(d)
|
| 665 |
+
for d in set(get_lib_location_guesses(root=root, isolated=isolated))
|
| 666 |
+
)
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
def decide_user_install(
|
| 670 |
+
use_user_site: Optional[bool],
|
| 671 |
+
prefix_path: Optional[str] = None,
|
| 672 |
+
target_dir: Optional[str] = None,
|
| 673 |
+
root_path: Optional[str] = None,
|
| 674 |
+
isolated_mode: bool = False,
|
| 675 |
+
) -> bool:
|
| 676 |
+
"""Determine whether to do a user install based on the input options.
|
| 677 |
+
|
| 678 |
+
If use_user_site is False, no additional checks are done.
|
| 679 |
+
If use_user_site is True, it is checked for compatibility with other
|
| 680 |
+
options.
|
| 681 |
+
If use_user_site is None, the default behaviour depends on the environment,
|
| 682 |
+
which is provided by the other arguments.
|
| 683 |
+
"""
|
| 684 |
+
# In some cases (config from tox), use_user_site can be set to an integer
|
| 685 |
+
# rather than a bool, which 'use_user_site is False' wouldn't catch.
|
| 686 |
+
if (use_user_site is not None) and (not use_user_site):
|
| 687 |
+
logger.debug("Non-user install by explicit request")
|
| 688 |
+
return False
|
| 689 |
+
|
| 690 |
+
if use_user_site:
|
| 691 |
+
if prefix_path:
|
| 692 |
+
raise CommandError(
|
| 693 |
+
"Can not combine '--user' and '--prefix' as they imply "
|
| 694 |
+
"different installation locations"
|
| 695 |
+
)
|
| 696 |
+
if virtualenv_no_global():
|
| 697 |
+
raise InstallationError(
|
| 698 |
+
"Can not perform a '--user' install. User site-packages "
|
| 699 |
+
"are not visible in this virtualenv."
|
| 700 |
+
)
|
| 701 |
+
logger.debug("User install by explicit request")
|
| 702 |
+
return True
|
| 703 |
+
|
| 704 |
+
# If we are here, user installs have not been explicitly requested/avoided
|
| 705 |
+
assert use_user_site is None
|
| 706 |
+
|
| 707 |
+
# user install incompatible with --prefix/--target
|
| 708 |
+
if prefix_path or target_dir:
|
| 709 |
+
logger.debug("Non-user install due to --prefix or --target option")
|
| 710 |
+
return False
|
| 711 |
+
|
| 712 |
+
# If user installs are not enabled, choose a non-user install
|
| 713 |
+
if not site.ENABLE_USER_SITE:
|
| 714 |
+
logger.debug("Non-user install because user site-packages disabled")
|
| 715 |
+
return False
|
| 716 |
+
|
| 717 |
+
# If we have permission for a non-user install, do that,
|
| 718 |
+
# otherwise do a user install.
|
| 719 |
+
if site_packages_writable(root=root_path, isolated=isolated_mode):
|
| 720 |
+
logger.debug("Non-user install because site-packages writeable")
|
| 721 |
+
return False
|
| 722 |
+
|
| 723 |
+
logger.info(
|
| 724 |
+
"Defaulting to user installation because normal site-packages "
|
| 725 |
+
"is not writeable"
|
| 726 |
+
)
|
| 727 |
+
return True
|
| 728 |
+
|
| 729 |
+
|
| 730 |
+
def create_os_error_message(
|
| 731 |
+
error: OSError, show_traceback: bool, using_user_site: bool
|
| 732 |
+
) -> str:
|
| 733 |
+
"""Format an error message for an OSError
|
| 734 |
+
|
| 735 |
+
It may occur anytime during the execution of the install command.
|
| 736 |
+
"""
|
| 737 |
+
parts = []
|
| 738 |
+
|
| 739 |
+
# Mention the error if we are not going to show a traceback
|
| 740 |
+
parts.append("Could not install packages due to an OSError")
|
| 741 |
+
if not show_traceback:
|
| 742 |
+
parts.append(": ")
|
| 743 |
+
parts.append(str(error))
|
| 744 |
+
else:
|
| 745 |
+
parts.append(".")
|
| 746 |
+
|
| 747 |
+
# Spilt the error indication from a helper message (if any)
|
| 748 |
+
parts[-1] += "\n"
|
| 749 |
+
|
| 750 |
+
# Suggest useful actions to the user:
|
| 751 |
+
# (1) using user site-packages or (2) verifying the permissions
|
| 752 |
+
if error.errno == errno.EACCES:
|
| 753 |
+
user_option_part = "Consider using the `--user` option"
|
| 754 |
+
permissions_part = "Check the permissions"
|
| 755 |
+
|
| 756 |
+
if not running_under_virtualenv() and not using_user_site:
|
| 757 |
+
parts.extend(
|
| 758 |
+
[
|
| 759 |
+
user_option_part,
|
| 760 |
+
" or ",
|
| 761 |
+
permissions_part.lower(),
|
| 762 |
+
]
|
| 763 |
+
)
|
| 764 |
+
else:
|
| 765 |
+
parts.append(permissions_part)
|
| 766 |
+
parts.append(".\n")
|
| 767 |
+
|
| 768 |
+
# Suggest the user to enable Long Paths if path length is
|
| 769 |
+
# more than 260
|
| 770 |
+
if (
|
| 771 |
+
WINDOWS
|
| 772 |
+
and error.errno == errno.ENOENT
|
| 773 |
+
and error.filename
|
| 774 |
+
and len(error.filename) > 260
|
| 775 |
+
):
|
| 776 |
+
parts.append(
|
| 777 |
+
"HINT: This error might have occurred since "
|
| 778 |
+
"this system does not have Windows Long Path "
|
| 779 |
+
"support enabled. You can find information on "
|
| 780 |
+
"how to enable this at "
|
| 781 |
+
"https://pip.pypa.io/warnings/enable-long-paths\n"
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import logging
|
| 3 |
+
from optparse import Values
|
| 4 |
+
from typing import TYPE_CHECKING, Generator, List, Optional, Sequence, Tuple, cast
|
| 5 |
+
|
| 6 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 7 |
+
from pip._vendor.packaging.version import Version
|
| 8 |
+
|
| 9 |
+
from pip._internal.cli import cmdoptions
|
| 10 |
+
from pip._internal.cli.index_command import IndexGroupCommand
|
| 11 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 12 |
+
from pip._internal.exceptions import CommandError
|
| 13 |
+
from pip._internal.metadata import BaseDistribution, get_environment
|
| 14 |
+
from pip._internal.models.selection_prefs import SelectionPreferences
|
| 15 |
+
from pip._internal.utils.compat import stdlib_pkgs
|
| 16 |
+
from pip._internal.utils.misc import tabulate, write_output
|
| 17 |
+
|
| 18 |
+
if TYPE_CHECKING:
|
| 19 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 20 |
+
from pip._internal.network.session import PipSession
|
| 21 |
+
|
| 22 |
+
class _DistWithLatestInfo(BaseDistribution):
|
| 23 |
+
"""Give the distribution object a couple of extra fields.
|
| 24 |
+
|
| 25 |
+
These will be populated during ``get_outdated()``. This is dirty but
|
| 26 |
+
makes the rest of the code much cleaner.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
latest_version: Version
|
| 30 |
+
latest_filetype: str
|
| 31 |
+
|
| 32 |
+
_ProcessedDists = Sequence[_DistWithLatestInfo]
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
logger = logging.getLogger(__name__)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class ListCommand(IndexGroupCommand):
|
| 39 |
+
"""
|
| 40 |
+
List installed packages, including editables.
|
| 41 |
+
|
| 42 |
+
Packages are listed in a case-insensitive sorted order.
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
ignore_require_venv = True
|
| 46 |
+
usage = """
|
| 47 |
+
%prog [options]"""
|
| 48 |
+
|
| 49 |
+
def add_options(self) -> None:
|
| 50 |
+
self.cmd_opts.add_option(
|
| 51 |
+
"-o",
|
| 52 |
+
"--outdated",
|
| 53 |
+
action="store_true",
|
| 54 |
+
default=False,
|
| 55 |
+
help="List outdated packages",
|
| 56 |
+
)
|
| 57 |
+
self.cmd_opts.add_option(
|
| 58 |
+
"-u",
|
| 59 |
+
"--uptodate",
|
| 60 |
+
action="store_true",
|
| 61 |
+
default=False,
|
| 62 |
+
help="List uptodate packages",
|
| 63 |
+
)
|
| 64 |
+
self.cmd_opts.add_option(
|
| 65 |
+
"-e",
|
| 66 |
+
"--editable",
|
| 67 |
+
action="store_true",
|
| 68 |
+
default=False,
|
| 69 |
+
help="List editable projects.",
|
| 70 |
+
)
|
| 71 |
+
self.cmd_opts.add_option(
|
| 72 |
+
"-l",
|
| 73 |
+
"--local",
|
| 74 |
+
action="store_true",
|
| 75 |
+
default=False,
|
| 76 |
+
help=(
|
| 77 |
+
"If in a virtualenv that has global access, do not list "
|
| 78 |
+
"globally-installed packages."
|
| 79 |
+
),
|
| 80 |
+
)
|
| 81 |
+
self.cmd_opts.add_option(
|
| 82 |
+
"--user",
|
| 83 |
+
dest="user",
|
| 84 |
+
action="store_true",
|
| 85 |
+
default=False,
|
| 86 |
+
help="Only output packages installed in user-site.",
|
| 87 |
+
)
|
| 88 |
+
self.cmd_opts.add_option(cmdoptions.list_path())
|
| 89 |
+
self.cmd_opts.add_option(
|
| 90 |
+
"--pre",
|
| 91 |
+
action="store_true",
|
| 92 |
+
default=False,
|
| 93 |
+
help=(
|
| 94 |
+
"Include pre-release and development versions. By default, "
|
| 95 |
+
"pip only finds stable versions."
|
| 96 |
+
),
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
self.cmd_opts.add_option(
|
| 100 |
+
"--format",
|
| 101 |
+
action="store",
|
| 102 |
+
dest="list_format",
|
| 103 |
+
default="columns",
|
| 104 |
+
choices=("columns", "freeze", "json"),
|
| 105 |
+
help=(
|
| 106 |
+
"Select the output format among: columns (default), freeze, or json. "
|
| 107 |
+
"The 'freeze' format cannot be used with the --outdated option."
|
| 108 |
+
),
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
self.cmd_opts.add_option(
|
| 112 |
+
"--not-required",
|
| 113 |
+
action="store_true",
|
| 114 |
+
dest="not_required",
|
| 115 |
+
help="List packages that are not dependencies of installed packages.",
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
self.cmd_opts.add_option(
|
| 119 |
+
"--exclude-editable",
|
| 120 |
+
action="store_false",
|
| 121 |
+
dest="include_editable",
|
| 122 |
+
help="Exclude editable package from output.",
|
| 123 |
+
)
|
| 124 |
+
self.cmd_opts.add_option(
|
| 125 |
+
"--include-editable",
|
| 126 |
+
action="store_true",
|
| 127 |
+
dest="include_editable",
|
| 128 |
+
help="Include editable package from output.",
|
| 129 |
+
default=True,
|
| 130 |
+
)
|
| 131 |
+
self.cmd_opts.add_option(cmdoptions.list_exclude())
|
| 132 |
+
index_opts = cmdoptions.make_option_group(cmdoptions.index_group, self.parser)
|
| 133 |
+
|
| 134 |
+
self.parser.insert_option_group(0, index_opts)
|
| 135 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 136 |
+
|
| 137 |
+
def handle_pip_version_check(self, options: Values) -> None:
|
| 138 |
+
if options.outdated or options.uptodate:
|
| 139 |
+
super().handle_pip_version_check(options)
|
| 140 |
+
|
| 141 |
+
def _build_package_finder(
|
| 142 |
+
self, options: Values, session: "PipSession"
|
| 143 |
+
) -> "PackageFinder":
|
| 144 |
+
"""
|
| 145 |
+
Create a package finder appropriate to this list command.
|
| 146 |
+
"""
|
| 147 |
+
# Lazy import the heavy index modules as most list invocations won't need 'em.
|
| 148 |
+
from pip._internal.index.collector import LinkCollector
|
| 149 |
+
from pip._internal.index.package_finder import PackageFinder
|
| 150 |
+
|
| 151 |
+
link_collector = LinkCollector.create(session, options=options)
|
| 152 |
+
|
| 153 |
+
# Pass allow_yanked=False to ignore yanked versions.
|
| 154 |
+
selection_prefs = SelectionPreferences(
|
| 155 |
+
allow_yanked=False,
|
| 156 |
+
allow_all_prereleases=options.pre,
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
return PackageFinder.create(
|
| 160 |
+
link_collector=link_collector,
|
| 161 |
+
selection_prefs=selection_prefs,
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 165 |
+
if options.outdated and options.uptodate:
|
| 166 |
+
raise CommandError("Options --outdated and --uptodate cannot be combined.")
|
| 167 |
+
|
| 168 |
+
if options.outdated and options.list_format == "freeze":
|
| 169 |
+
raise CommandError(
|
| 170 |
+
"List format 'freeze' cannot be used with the --outdated option."
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
cmdoptions.check_list_path_option(options)
|
| 174 |
+
|
| 175 |
+
skip = set(stdlib_pkgs)
|
| 176 |
+
if options.excludes:
|
| 177 |
+
skip.update(canonicalize_name(n) for n in options.excludes)
|
| 178 |
+
|
| 179 |
+
packages: _ProcessedDists = [
|
| 180 |
+
cast("_DistWithLatestInfo", d)
|
| 181 |
+
for d in get_environment(options.path).iter_installed_distributions(
|
| 182 |
+
local_only=options.local,
|
| 183 |
+
user_only=options.user,
|
| 184 |
+
editables_only=options.editable,
|
| 185 |
+
include_editables=options.include_editable,
|
| 186 |
+
skip=skip,
|
| 187 |
+
)
|
| 188 |
+
]
|
| 189 |
+
|
| 190 |
+
# get_not_required must be called firstly in order to find and
|
| 191 |
+
# filter out all dependencies correctly. Otherwise a package
|
| 192 |
+
# can't be identified as requirement because some parent packages
|
| 193 |
+
# could be filtered out before.
|
| 194 |
+
if options.not_required:
|
| 195 |
+
packages = self.get_not_required(packages, options)
|
| 196 |
+
|
| 197 |
+
if options.outdated:
|
| 198 |
+
packages = self.get_outdated(packages, options)
|
| 199 |
+
elif options.uptodate:
|
| 200 |
+
packages = self.get_uptodate(packages, options)
|
| 201 |
+
|
| 202 |
+
self.output_package_listing(packages, options)
|
| 203 |
+
return SUCCESS
|
| 204 |
+
|
| 205 |
+
def get_outdated(
|
| 206 |
+
self, packages: "_ProcessedDists", options: Values
|
| 207 |
+
) -> "_ProcessedDists":
|
| 208 |
+
return [
|
| 209 |
+
dist
|
| 210 |
+
for dist in self.iter_packages_latest_infos(packages, options)
|
| 211 |
+
if dist.latest_version > dist.version
|
| 212 |
+
]
|
| 213 |
+
|
| 214 |
+
def get_uptodate(
|
| 215 |
+
self, packages: "_ProcessedDists", options: Values
|
| 216 |
+
) -> "_ProcessedDists":
|
| 217 |
+
return [
|
| 218 |
+
dist
|
| 219 |
+
for dist in self.iter_packages_latest_infos(packages, options)
|
| 220 |
+
if dist.latest_version == dist.version
|
| 221 |
+
]
|
| 222 |
+
|
| 223 |
+
def get_not_required(
|
| 224 |
+
self, packages: "_ProcessedDists", options: Values
|
| 225 |
+
) -> "_ProcessedDists":
|
| 226 |
+
dep_keys = {
|
| 227 |
+
canonicalize_name(dep.name)
|
| 228 |
+
for dist in packages
|
| 229 |
+
for dep in (dist.iter_dependencies() or ())
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
# Create a set to remove duplicate packages, and cast it to a list
|
| 233 |
+
# to keep the return type consistent with get_outdated and
|
| 234 |
+
# get_uptodate
|
| 235 |
+
return list({pkg for pkg in packages if pkg.canonical_name not in dep_keys})
|
| 236 |
+
|
| 237 |
+
def iter_packages_latest_infos(
|
| 238 |
+
self, packages: "_ProcessedDists", options: Values
|
| 239 |
+
) -> Generator["_DistWithLatestInfo", None, None]:
|
| 240 |
+
with self._build_session(options) as session:
|
| 241 |
+
finder = self._build_package_finder(options, session)
|
| 242 |
+
|
| 243 |
+
def latest_info(
|
| 244 |
+
dist: "_DistWithLatestInfo",
|
| 245 |
+
) -> Optional["_DistWithLatestInfo"]:
|
| 246 |
+
all_candidates = finder.find_all_candidates(dist.canonical_name)
|
| 247 |
+
if not options.pre:
|
| 248 |
+
# Remove prereleases
|
| 249 |
+
all_candidates = [
|
| 250 |
+
candidate
|
| 251 |
+
for candidate in all_candidates
|
| 252 |
+
if not candidate.version.is_prerelease
|
| 253 |
+
]
|
| 254 |
+
|
| 255 |
+
evaluator = finder.make_candidate_evaluator(
|
| 256 |
+
project_name=dist.canonical_name,
|
| 257 |
+
)
|
| 258 |
+
best_candidate = evaluator.sort_best_candidate(all_candidates)
|
| 259 |
+
if best_candidate is None:
|
| 260 |
+
return None
|
| 261 |
+
|
| 262 |
+
remote_version = best_candidate.version
|
| 263 |
+
if best_candidate.link.is_wheel:
|
| 264 |
+
typ = "wheel"
|
| 265 |
+
else:
|
| 266 |
+
typ = "sdist"
|
| 267 |
+
dist.latest_version = remote_version
|
| 268 |
+
dist.latest_filetype = typ
|
| 269 |
+
return dist
|
| 270 |
+
|
| 271 |
+
for dist in map(latest_info, packages):
|
| 272 |
+
if dist is not None:
|
| 273 |
+
yield dist
|
| 274 |
+
|
| 275 |
+
def output_package_listing(
|
| 276 |
+
self, packages: "_ProcessedDists", options: Values
|
| 277 |
+
) -> None:
|
| 278 |
+
packages = sorted(
|
| 279 |
+
packages,
|
| 280 |
+
key=lambda dist: dist.canonical_name,
|
| 281 |
+
)
|
| 282 |
+
if options.list_format == "columns" and packages:
|
| 283 |
+
data, header = format_for_columns(packages, options)
|
| 284 |
+
self.output_package_listing_columns(data, header)
|
| 285 |
+
elif options.list_format == "freeze":
|
| 286 |
+
for dist in packages:
|
| 287 |
+
if options.verbose >= 1:
|
| 288 |
+
write_output(
|
| 289 |
+
"%s==%s (%s)", dist.raw_name, dist.version, dist.location
|
| 290 |
+
)
|
| 291 |
+
else:
|
| 292 |
+
write_output("%s==%s", dist.raw_name, dist.version)
|
| 293 |
+
elif options.list_format == "json":
|
| 294 |
+
write_output(format_for_json(packages, options))
|
| 295 |
+
|
| 296 |
+
def output_package_listing_columns(
|
| 297 |
+
self, data: List[List[str]], header: List[str]
|
| 298 |
+
) -> None:
|
| 299 |
+
# insert the header first: we need to know the size of column names
|
| 300 |
+
if len(data) > 0:
|
| 301 |
+
data.insert(0, header)
|
| 302 |
+
|
| 303 |
+
pkg_strings, sizes = tabulate(data)
|
| 304 |
+
|
| 305 |
+
# Create and add a separator.
|
| 306 |
+
if len(data) > 0:
|
| 307 |
+
pkg_strings.insert(1, " ".join("-" * x for x in sizes))
|
| 308 |
+
|
| 309 |
+
for val in pkg_strings:
|
| 310 |
+
write_output(val)
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def format_for_columns(
|
| 314 |
+
pkgs: "_ProcessedDists", options: Values
|
| 315 |
+
) -> Tuple[List[List[str]], List[str]]:
|
| 316 |
+
"""
|
| 317 |
+
Convert the package data into something usable
|
| 318 |
+
by output_package_listing_columns.
|
| 319 |
+
"""
|
| 320 |
+
header = ["Package", "Version"]
|
| 321 |
+
|
| 322 |
+
running_outdated = options.outdated
|
| 323 |
+
if running_outdated:
|
| 324 |
+
header.extend(["Latest", "Type"])
|
| 325 |
+
|
| 326 |
+
has_editables = any(x.editable for x in pkgs)
|
| 327 |
+
if has_editables:
|
| 328 |
+
header.append("Editable project location")
|
| 329 |
+
|
| 330 |
+
if options.verbose >= 1:
|
| 331 |
+
header.append("Location")
|
| 332 |
+
if options.verbose >= 1:
|
| 333 |
+
header.append("Installer")
|
| 334 |
+
|
| 335 |
+
data = []
|
| 336 |
+
for proj in pkgs:
|
| 337 |
+
# if we're working on the 'outdated' list, separate out the
|
| 338 |
+
# latest_version and type
|
| 339 |
+
row = [proj.raw_name, proj.raw_version]
|
| 340 |
+
|
| 341 |
+
if running_outdated:
|
| 342 |
+
row.append(str(proj.latest_version))
|
| 343 |
+
row.append(proj.latest_filetype)
|
| 344 |
+
|
| 345 |
+
if has_editables:
|
| 346 |
+
row.append(proj.editable_project_location or "")
|
| 347 |
+
|
| 348 |
+
if options.verbose >= 1:
|
| 349 |
+
row.append(proj.location or "")
|
| 350 |
+
if options.verbose >= 1:
|
| 351 |
+
row.append(proj.installer)
|
| 352 |
+
|
| 353 |
+
data.append(row)
|
| 354 |
+
|
| 355 |
+
return data, header
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
def format_for_json(packages: "_ProcessedDists", options: Values) -> str:
|
| 359 |
+
data = []
|
| 360 |
+
for dist in packages:
|
| 361 |
+
info = {
|
| 362 |
+
"name": dist.raw_name,
|
| 363 |
+
"version": str(dist.version),
|
| 364 |
+
}
|
| 365 |
+
if options.verbose >= 1:
|
| 366 |
+
info["location"] = dist.location or ""
|
| 367 |
+
info["installer"] = dist.installer
|
| 368 |
+
if options.outdated:
|
| 369 |
+
info["latest_version"] = str(dist.latest_version)
|
| 370 |
+
info["latest_filetype"] = dist.latest_filetype
|
| 371 |
+
editable_project_location = dist.editable_project_location
|
| 372 |
+
if editable_project_location:
|
| 373 |
+
info["editable_project_location"] = editable_project_location
|
| 374 |
+
data.append(info)
|
| 375 |
+
return json.dumps(data)
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/show.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
from optparse import Values
|
| 3 |
+
from typing import Generator, Iterable, Iterator, List, NamedTuple, Optional
|
| 4 |
+
|
| 5 |
+
from pip._vendor.packaging.requirements import InvalidRequirement
|
| 6 |
+
from pip._vendor.packaging.utils import canonicalize_name
|
| 7 |
+
|
| 8 |
+
from pip._internal.cli.base_command import Command
|
| 9 |
+
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
| 10 |
+
from pip._internal.metadata import BaseDistribution, get_default_environment
|
| 11 |
+
from pip._internal.utils.misc import write_output
|
| 12 |
+
|
| 13 |
+
logger = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class ShowCommand(Command):
|
| 17 |
+
"""
|
| 18 |
+
Show information about one or more installed packages.
|
| 19 |
+
|
| 20 |
+
The output is in RFC-compliant mail header format.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
usage = """
|
| 24 |
+
%prog [options] <package> ..."""
|
| 25 |
+
ignore_require_venv = True
|
| 26 |
+
|
| 27 |
+
def add_options(self) -> None:
|
| 28 |
+
self.cmd_opts.add_option(
|
| 29 |
+
"-f",
|
| 30 |
+
"--files",
|
| 31 |
+
dest="files",
|
| 32 |
+
action="store_true",
|
| 33 |
+
default=False,
|
| 34 |
+
help="Show the full list of installed files for each package.",
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 38 |
+
|
| 39 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 40 |
+
if not args:
|
| 41 |
+
logger.warning("ERROR: Please provide a package name or names.")
|
| 42 |
+
return ERROR
|
| 43 |
+
query = args
|
| 44 |
+
|
| 45 |
+
results = search_packages_info(query)
|
| 46 |
+
if not print_results(
|
| 47 |
+
results, list_files=options.files, verbose=options.verbose
|
| 48 |
+
):
|
| 49 |
+
return ERROR
|
| 50 |
+
return SUCCESS
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class _PackageInfo(NamedTuple):
|
| 54 |
+
name: str
|
| 55 |
+
version: str
|
| 56 |
+
location: str
|
| 57 |
+
editable_project_location: Optional[str]
|
| 58 |
+
requires: List[str]
|
| 59 |
+
required_by: List[str]
|
| 60 |
+
installer: str
|
| 61 |
+
metadata_version: str
|
| 62 |
+
classifiers: List[str]
|
| 63 |
+
summary: str
|
| 64 |
+
homepage: str
|
| 65 |
+
project_urls: List[str]
|
| 66 |
+
author: str
|
| 67 |
+
author_email: str
|
| 68 |
+
license: str
|
| 69 |
+
license_expression: str
|
| 70 |
+
entry_points: List[str]
|
| 71 |
+
files: Optional[List[str]]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def search_packages_info(query: List[str]) -> Generator[_PackageInfo, None, None]:
|
| 75 |
+
"""
|
| 76 |
+
Gather details from installed distributions. Print distribution name,
|
| 77 |
+
version, location, and installed files. Installed files requires a
|
| 78 |
+
pip generated 'installed-files.txt' in the distributions '.egg-info'
|
| 79 |
+
directory.
|
| 80 |
+
"""
|
| 81 |
+
env = get_default_environment()
|
| 82 |
+
|
| 83 |
+
installed = {dist.canonical_name: dist for dist in env.iter_all_distributions()}
|
| 84 |
+
query_names = [canonicalize_name(name) for name in query]
|
| 85 |
+
missing = sorted(
|
| 86 |
+
[name for name, pkg in zip(query, query_names) if pkg not in installed]
|
| 87 |
+
)
|
| 88 |
+
if missing:
|
| 89 |
+
logger.warning("Package(s) not found: %s", ", ".join(missing))
|
| 90 |
+
|
| 91 |
+
def _get_requiring_packages(current_dist: BaseDistribution) -> Iterator[str]:
|
| 92 |
+
return (
|
| 93 |
+
dist.metadata["Name"] or "UNKNOWN"
|
| 94 |
+
for dist in installed.values()
|
| 95 |
+
if current_dist.canonical_name
|
| 96 |
+
in {canonicalize_name(d.name) for d in dist.iter_dependencies()}
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
for query_name in query_names:
|
| 100 |
+
try:
|
| 101 |
+
dist = installed[query_name]
|
| 102 |
+
except KeyError:
|
| 103 |
+
continue
|
| 104 |
+
|
| 105 |
+
try:
|
| 106 |
+
requires = sorted(
|
| 107 |
+
# Avoid duplicates in requirements (e.g. due to environment markers).
|
| 108 |
+
{req.name for req in dist.iter_dependencies()},
|
| 109 |
+
key=str.lower,
|
| 110 |
+
)
|
| 111 |
+
except InvalidRequirement:
|
| 112 |
+
requires = sorted(dist.iter_raw_dependencies(), key=str.lower)
|
| 113 |
+
|
| 114 |
+
try:
|
| 115 |
+
required_by = sorted(_get_requiring_packages(dist), key=str.lower)
|
| 116 |
+
except InvalidRequirement:
|
| 117 |
+
required_by = ["#N/A"]
|
| 118 |
+
|
| 119 |
+
try:
|
| 120 |
+
entry_points_text = dist.read_text("entry_points.txt")
|
| 121 |
+
entry_points = entry_points_text.splitlines(keepends=False)
|
| 122 |
+
except FileNotFoundError:
|
| 123 |
+
entry_points = []
|
| 124 |
+
|
| 125 |
+
files_iter = dist.iter_declared_entries()
|
| 126 |
+
if files_iter is None:
|
| 127 |
+
files: Optional[List[str]] = None
|
| 128 |
+
else:
|
| 129 |
+
files = sorted(files_iter)
|
| 130 |
+
|
| 131 |
+
metadata = dist.metadata
|
| 132 |
+
|
| 133 |
+
project_urls = metadata.get_all("Project-URL", [])
|
| 134 |
+
homepage = metadata.get("Home-page", "")
|
| 135 |
+
if not homepage:
|
| 136 |
+
# It's common that there is a "homepage" Project-URL, but Home-page
|
| 137 |
+
# remains unset (especially as PEP 621 doesn't surface the field).
|
| 138 |
+
#
|
| 139 |
+
# This logic was taken from PyPI's codebase.
|
| 140 |
+
for url in project_urls:
|
| 141 |
+
url_label, url = url.split(",", maxsplit=1)
|
| 142 |
+
normalized_label = (
|
| 143 |
+
url_label.casefold().replace("-", "").replace("_", "").strip()
|
| 144 |
+
)
|
| 145 |
+
if normalized_label == "homepage":
|
| 146 |
+
homepage = url.strip()
|
| 147 |
+
break
|
| 148 |
+
|
| 149 |
+
yield _PackageInfo(
|
| 150 |
+
name=dist.raw_name,
|
| 151 |
+
version=dist.raw_version,
|
| 152 |
+
location=dist.location or "",
|
| 153 |
+
editable_project_location=dist.editable_project_location,
|
| 154 |
+
requires=requires,
|
| 155 |
+
required_by=required_by,
|
| 156 |
+
installer=dist.installer,
|
| 157 |
+
metadata_version=dist.metadata_version or "",
|
| 158 |
+
classifiers=metadata.get_all("Classifier", []),
|
| 159 |
+
summary=metadata.get("Summary", ""),
|
| 160 |
+
homepage=homepage,
|
| 161 |
+
project_urls=project_urls,
|
| 162 |
+
author=metadata.get("Author", ""),
|
| 163 |
+
author_email=metadata.get("Author-email", ""),
|
| 164 |
+
license=metadata.get("License", ""),
|
| 165 |
+
license_expression=metadata.get("License-Expression", ""),
|
| 166 |
+
entry_points=entry_points,
|
| 167 |
+
files=files,
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def print_results(
|
| 172 |
+
distributions: Iterable[_PackageInfo],
|
| 173 |
+
list_files: bool,
|
| 174 |
+
verbose: bool,
|
| 175 |
+
) -> bool:
|
| 176 |
+
"""
|
| 177 |
+
Print the information from installed distributions found.
|
| 178 |
+
"""
|
| 179 |
+
results_printed = False
|
| 180 |
+
for i, dist in enumerate(distributions):
|
| 181 |
+
results_printed = True
|
| 182 |
+
if i > 0:
|
| 183 |
+
write_output("---")
|
| 184 |
+
|
| 185 |
+
metadata_version_tuple = tuple(map(int, dist.metadata_version.split(".")))
|
| 186 |
+
|
| 187 |
+
write_output("Name: %s", dist.name)
|
| 188 |
+
write_output("Version: %s", dist.version)
|
| 189 |
+
write_output("Summary: %s", dist.summary)
|
| 190 |
+
write_output("Home-page: %s", dist.homepage)
|
| 191 |
+
write_output("Author: %s", dist.author)
|
| 192 |
+
write_output("Author-email: %s", dist.author_email)
|
| 193 |
+
if metadata_version_tuple >= (2, 4) and dist.license_expression:
|
| 194 |
+
write_output("License-Expression: %s", dist.license_expression)
|
| 195 |
+
else:
|
| 196 |
+
write_output("License: %s", dist.license)
|
| 197 |
+
write_output("Location: %s", dist.location)
|
| 198 |
+
if dist.editable_project_location is not None:
|
| 199 |
+
write_output(
|
| 200 |
+
"Editable project location: %s", dist.editable_project_location
|
| 201 |
+
)
|
| 202 |
+
write_output("Requires: %s", ", ".join(dist.requires))
|
| 203 |
+
write_output("Required-by: %s", ", ".join(dist.required_by))
|
| 204 |
+
|
| 205 |
+
if verbose:
|
| 206 |
+
write_output("Metadata-Version: %s", dist.metadata_version)
|
| 207 |
+
write_output("Installer: %s", dist.installer)
|
| 208 |
+
write_output("Classifiers:")
|
| 209 |
+
for classifier in dist.classifiers:
|
| 210 |
+
write_output(" %s", classifier)
|
| 211 |
+
write_output("Entry-points:")
|
| 212 |
+
for entry in dist.entry_points:
|
| 213 |
+
write_output(" %s", entry.strip())
|
| 214 |
+
write_output("Project-URLs:")
|
| 215 |
+
for project_url in dist.project_urls:
|
| 216 |
+
write_output(" %s", project_url)
|
| 217 |
+
if list_files:
|
| 218 |
+
write_output("Files:")
|
| 219 |
+
if dist.files is None:
|
| 220 |
+
write_output("Cannot locate RECORD or installed-files.txt")
|
| 221 |
+
else:
|
| 222 |
+
for line in dist.files:
|
| 223 |
+
write_output(" %s", line.strip())
|
| 224 |
+
return results_printed
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/commands/wheel.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import logging
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
from optparse import Values
|
| 5 |
+
from typing import List
|
| 6 |
+
|
| 7 |
+
from pip._internal.cache import WheelCache
|
| 8 |
+
from pip._internal.cli import cmdoptions
|
| 9 |
+
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
|
| 10 |
+
from pip._internal.cli.status_codes import SUCCESS
|
| 11 |
+
from pip._internal.exceptions import CommandError
|
| 12 |
+
from pip._internal.operations.build.build_tracker import get_build_tracker
|
| 13 |
+
from pip._internal.req.req_install import (
|
| 14 |
+
InstallRequirement,
|
| 15 |
+
check_legacy_setup_py_options,
|
| 16 |
+
)
|
| 17 |
+
from pip._internal.utils.misc import ensure_dir, normalize_path
|
| 18 |
+
from pip._internal.utils.temp_dir import TempDirectory
|
| 19 |
+
from pip._internal.wheel_builder import build, should_build_for_wheel_command
|
| 20 |
+
|
| 21 |
+
logger = logging.getLogger(__name__)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class WheelCommand(RequirementCommand):
|
| 25 |
+
"""
|
| 26 |
+
Build Wheel archives for your requirements and dependencies.
|
| 27 |
+
|
| 28 |
+
Wheel is a built-package format, and offers the advantage of not
|
| 29 |
+
recompiling your software during every install. For more details, see the
|
| 30 |
+
wheel docs: https://wheel.readthedocs.io/en/latest/
|
| 31 |
+
|
| 32 |
+
'pip wheel' uses the build system interface as described here:
|
| 33 |
+
https://pip.pypa.io/en/stable/reference/build-system/
|
| 34 |
+
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
usage = """
|
| 38 |
+
%prog [options] <requirement specifier> ...
|
| 39 |
+
%prog [options] -r <requirements file> ...
|
| 40 |
+
%prog [options] [-e] <vcs project url> ...
|
| 41 |
+
%prog [options] [-e] <local project path> ...
|
| 42 |
+
%prog [options] <archive url/path> ..."""
|
| 43 |
+
|
| 44 |
+
def add_options(self) -> None:
|
| 45 |
+
self.cmd_opts.add_option(
|
| 46 |
+
"-w",
|
| 47 |
+
"--wheel-dir",
|
| 48 |
+
dest="wheel_dir",
|
| 49 |
+
metavar="dir",
|
| 50 |
+
default=os.curdir,
|
| 51 |
+
help=(
|
| 52 |
+
"Build wheels into <dir>, where the default is the "
|
| 53 |
+
"current working directory."
|
| 54 |
+
),
|
| 55 |
+
)
|
| 56 |
+
self.cmd_opts.add_option(cmdoptions.no_binary())
|
| 57 |
+
self.cmd_opts.add_option(cmdoptions.only_binary())
|
| 58 |
+
self.cmd_opts.add_option(cmdoptions.prefer_binary())
|
| 59 |
+
self.cmd_opts.add_option(cmdoptions.no_build_isolation())
|
| 60 |
+
self.cmd_opts.add_option(cmdoptions.use_pep517())
|
| 61 |
+
self.cmd_opts.add_option(cmdoptions.no_use_pep517())
|
| 62 |
+
self.cmd_opts.add_option(cmdoptions.check_build_deps())
|
| 63 |
+
self.cmd_opts.add_option(cmdoptions.constraints())
|
| 64 |
+
self.cmd_opts.add_option(cmdoptions.editable())
|
| 65 |
+
self.cmd_opts.add_option(cmdoptions.requirements())
|
| 66 |
+
self.cmd_opts.add_option(cmdoptions.src())
|
| 67 |
+
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
| 68 |
+
self.cmd_opts.add_option(cmdoptions.no_deps())
|
| 69 |
+
self.cmd_opts.add_option(cmdoptions.progress_bar())
|
| 70 |
+
|
| 71 |
+
self.cmd_opts.add_option(
|
| 72 |
+
"--no-verify",
|
| 73 |
+
dest="no_verify",
|
| 74 |
+
action="store_true",
|
| 75 |
+
default=False,
|
| 76 |
+
help="Don't verify if built wheel is valid.",
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
self.cmd_opts.add_option(cmdoptions.config_settings())
|
| 80 |
+
self.cmd_opts.add_option(cmdoptions.build_options())
|
| 81 |
+
self.cmd_opts.add_option(cmdoptions.global_options())
|
| 82 |
+
|
| 83 |
+
self.cmd_opts.add_option(
|
| 84 |
+
"--pre",
|
| 85 |
+
action="store_true",
|
| 86 |
+
default=False,
|
| 87 |
+
help=(
|
| 88 |
+
"Include pre-release and development versions. By default, "
|
| 89 |
+
"pip only finds stable versions."
|
| 90 |
+
),
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
self.cmd_opts.add_option(cmdoptions.require_hashes())
|
| 94 |
+
|
| 95 |
+
index_opts = cmdoptions.make_option_group(
|
| 96 |
+
cmdoptions.index_group,
|
| 97 |
+
self.parser,
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
self.parser.insert_option_group(0, index_opts)
|
| 101 |
+
self.parser.insert_option_group(0, self.cmd_opts)
|
| 102 |
+
|
| 103 |
+
@with_cleanup
|
| 104 |
+
def run(self, options: Values, args: List[str]) -> int:
|
| 105 |
+
session = self.get_default_session(options)
|
| 106 |
+
|
| 107 |
+
finder = self._build_package_finder(options, session)
|
| 108 |
+
|
| 109 |
+
options.wheel_dir = normalize_path(options.wheel_dir)
|
| 110 |
+
ensure_dir(options.wheel_dir)
|
| 111 |
+
|
| 112 |
+
build_tracker = self.enter_context(get_build_tracker())
|
| 113 |
+
|
| 114 |
+
directory = TempDirectory(
|
| 115 |
+
delete=not options.no_clean,
|
| 116 |
+
kind="wheel",
|
| 117 |
+
globally_managed=True,
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
reqs = self.get_requirements(args, options, finder, session)
|
| 121 |
+
check_legacy_setup_py_options(options, reqs)
|
| 122 |
+
|
| 123 |
+
wheel_cache = WheelCache(options.cache_dir)
|
| 124 |
+
|
| 125 |
+
preparer = self.make_requirement_preparer(
|
| 126 |
+
temp_build_dir=directory,
|
| 127 |
+
options=options,
|
| 128 |
+
build_tracker=build_tracker,
|
| 129 |
+
session=session,
|
| 130 |
+
finder=finder,
|
| 131 |
+
download_dir=options.wheel_dir,
|
| 132 |
+
use_user_site=False,
|
| 133 |
+
verbosity=self.verbosity,
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
resolver = self.make_resolver(
|
| 137 |
+
preparer=preparer,
|
| 138 |
+
finder=finder,
|
| 139 |
+
options=options,
|
| 140 |
+
wheel_cache=wheel_cache,
|
| 141 |
+
ignore_requires_python=options.ignore_requires_python,
|
| 142 |
+
use_pep517=options.use_pep517,
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
self.trace_basic_info(finder)
|
| 146 |
+
|
| 147 |
+
requirement_set = resolver.resolve(reqs, check_supported_wheels=True)
|
| 148 |
+
|
| 149 |
+
reqs_to_build: List[InstallRequirement] = []
|
| 150 |
+
for req in requirement_set.requirements.values():
|
| 151 |
+
if req.is_wheel:
|
| 152 |
+
preparer.save_linked_requirement(req)
|
| 153 |
+
elif should_build_for_wheel_command(req):
|
| 154 |
+
reqs_to_build.append(req)
|
| 155 |
+
|
| 156 |
+
preparer.prepare_linked_requirements_more(requirement_set.requirements.values())
|
| 157 |
+
|
| 158 |
+
# build wheels
|
| 159 |
+
build_successes, build_failures = build(
|
| 160 |
+
reqs_to_build,
|
| 161 |
+
wheel_cache=wheel_cache,
|
| 162 |
+
verify=(not options.no_verify),
|
| 163 |
+
build_options=options.build_options or [],
|
| 164 |
+
global_options=options.global_options or [],
|
| 165 |
+
)
|
| 166 |
+
for req in build_successes:
|
| 167 |
+
assert req.link and req.link.is_wheel
|
| 168 |
+
assert req.local_file_path
|
| 169 |
+
# copy from cache to target directory
|
| 170 |
+
try:
|
| 171 |
+
shutil.copy(req.local_file_path, options.wheel_dir)
|
| 172 |
+
except OSError as e:
|
| 173 |
+
logger.warning(
|
| 174 |
+
"Building wheel for %s failed: %s",
|
| 175 |
+
req.name,
|
| 176 |
+
e,
|
| 177 |
+
)
|
| 178 |
+
build_failures.append(req)
|
| 179 |
+
if len(build_failures) != 0:
|
| 180 |
+
raise CommandError("Failed to build one or more wheels")
|
| 181 |
+
|
| 182 |
+
return SUCCESS
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/index/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Index interaction code
|
| 2 |
+
"""
|
evalkit_llava/lib/python3.10/site-packages/pip/_internal/index/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (213 Bytes). View file
|
|
|