2013-09-17 07:21:15 +02:00
|
|
|
"""
|
|
|
|
shared options and groups
|
|
|
|
|
2014-01-27 15:07:10 +01:00
|
|
|
The principle here is to define options once, but *not* instantiate them
|
|
|
|
globally. One reason being that options with action='append' can carry state
|
2015-06-02 07:07:41 +02:00
|
|
|
between parses. pip parses general options twice internally, and shouldn't
|
2014-01-27 15:07:10 +01:00
|
|
|
pass on state. To be consistent, all options will follow this design.
|
2013-09-17 07:21:15 +02:00
|
|
|
"""
|
2019-07-20 08:36:59 +02:00
|
|
|
|
|
|
|
# The following comment should be removed at some point in the future.
|
|
|
|
# mypy: strict-optional=False
|
|
|
|
|
2019-12-12 02:00:22 +01:00
|
|
|
import os
|
2019-01-13 16:59:17 +01:00
|
|
|
import textwrap
|
2015-04-22 01:53:05 +02:00
|
|
|
import warnings
|
2017-05-16 12:16:30 +02:00
|
|
|
from functools import partial
|
2021-02-19 13:56:59 +01:00
|
|
|
from optparse import SUPPRESS_HELP, Option, OptionGroup, OptionParser, Values
|
2019-06-09 04:37:11 +02:00
|
|
|
from textwrap import dedent
|
2021-02-19 13:56:59 +01:00
|
|
|
from typing import Any, Callable, Dict, Optional, Tuple
|
2015-04-17 05:03:34 +02:00
|
|
|
|
2020-10-30 21:50:59 +01:00
|
|
|
from pip._vendor.packaging.utils import canonicalize_name
|
|
|
|
|
2021-02-19 13:56:59 +01:00
|
|
|
from pip._internal.cli.parser import ConfigOptionParser
|
2020-02-21 09:31:13 +01:00
|
|
|
from pip._internal.cli.progress_bars import BAR_TYPES
|
2018-07-24 17:09:32 +02:00
|
|
|
from pip._internal.exceptions import CommandError
|
2019-07-18 22:50:05 +02:00
|
|
|
from pip._internal.locations import USER_CACHE_DIR, get_src_prefix
|
2018-09-02 19:50:54 +02:00
|
|
|
from pip._internal.models.format_control import FormatControl
|
2018-05-29 22:14:51 +02:00
|
|
|
from pip._internal.models.index import PyPI
|
2019-06-22 08:30:34 +02:00
|
|
|
from pip._internal.models.target_python import TargetPython
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.utils.hashes import STRONG_HASHES
|
2021-01-20 16:42:29 +01:00
|
|
|
from pip._internal.utils.misc import strtobool
|
2012-12-18 06:35:09 +01:00
|
|
|
|
2013-02-16 19:02:41 +01:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def raise_option_error(parser: OptionParser, option: Option, msg: str) -> None:
|
2019-01-13 16:59:17 +01:00
|
|
|
"""
|
|
|
|
Raise an option parsing error using parser.error().
|
|
|
|
|
|
|
|
Args:
|
|
|
|
parser: an OptionParser instance.
|
|
|
|
option: an Option instance.
|
|
|
|
msg: the error text.
|
|
|
|
"""
|
2021-02-20 16:13:27 +01:00
|
|
|
msg = f"{option} error: {msg}"
|
|
|
|
msg = textwrap.fill(" ".join(msg.split()))
|
2019-01-13 16:59:17 +01:00
|
|
|
parser.error(msg)
|
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def make_option_group(group: Dict[str, Any], parser: ConfigOptionParser) -> OptionGroup:
|
2012-12-18 06:35:09 +01:00
|
|
|
"""
|
|
|
|
Return an OptionGroup object
|
|
|
|
group -- assumed to be dict with 'name' and 'options' keys
|
|
|
|
parser -- an optparse Parser
|
|
|
|
"""
|
2021-02-20 16:13:27 +01:00
|
|
|
option_group = OptionGroup(parser, group["name"])
|
|
|
|
for option in group["options"]:
|
2015-04-17 04:37:47 +02:00
|
|
|
option_group.add_option(option())
|
2012-12-18 06:35:09 +01:00
|
|
|
return option_group
|
|
|
|
|
2014-01-27 15:07:10 +01:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def check_install_build_global(
|
|
|
|
options: Values, check_options: Optional[Values] = None
|
|
|
|
) -> None:
|
2015-04-22 01:53:05 +02:00
|
|
|
"""Disable wheels if per-setup.py call options are set.
|
|
|
|
|
|
|
|
:param options: The OptionParser options to update.
|
|
|
|
:param check_options: The options to check, if not supplied defaults to
|
|
|
|
options.
|
|
|
|
"""
|
|
|
|
if check_options is None:
|
|
|
|
check_options = options
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def getname(n: str) -> Optional[Any]:
|
2015-04-22 01:53:05 +02:00
|
|
|
return getattr(check_options, n, None)
|
2021-02-20 16:13:27 +01:00
|
|
|
|
2015-04-22 01:53:05 +02:00
|
|
|
names = ["build_options", "global_options", "install_options"]
|
|
|
|
if any(map(getname, names)):
|
|
|
|
control = options.format_control
|
2018-08-28 17:37:45 +02:00
|
|
|
control.disallow_binaries()
|
2015-04-22 01:53:05 +02:00
|
|
|
warnings.warn(
|
2021-02-20 16:13:27 +01:00
|
|
|
"Disabling all use of wheels due to the use of --build-option "
|
|
|
|
"/ --global-option / --install-option.",
|
|
|
|
stacklevel=2,
|
2017-12-25 10:53:27 +01:00
|
|
|
)
|
2015-04-22 01:53:05 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def check_dist_restriction(options: Values, check_target: bool = False) -> None:
|
2018-07-24 17:09:32 +02:00
|
|
|
"""Function for determining if custom platform options are allowed.
|
|
|
|
|
|
|
|
:param options: The OptionParser options.
|
|
|
|
:param check_target: Whether or not to check if --target is being used.
|
|
|
|
"""
|
2021-02-20 16:13:27 +01:00
|
|
|
dist_restriction_set = any(
|
|
|
|
[
|
|
|
|
options.python_version,
|
|
|
|
options.platforms,
|
|
|
|
options.abis,
|
|
|
|
options.implementation,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
binary_only = FormatControl(set(), {":all:"})
|
2018-07-24 17:09:32 +02:00
|
|
|
sdist_dependencies_allowed = (
|
2021-02-20 16:13:27 +01:00
|
|
|
options.format_control != binary_only and not options.ignore_dependencies
|
2018-07-24 17:09:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Installations or downloads using dist restrictions must not combine
|
|
|
|
# source distributions and dist-specific wheels, as they are not
|
2019-03-12 20:25:09 +01:00
|
|
|
# guaranteed to be locally compatible.
|
2018-07-24 17:09:32 +02:00
|
|
|
if dist_restriction_set and sdist_dependencies_allowed:
|
|
|
|
raise CommandError(
|
|
|
|
"When restricting platform and interpreter constraints using "
|
|
|
|
"--python-version, --platform, --abi, or --implementation, "
|
|
|
|
"either --no-deps must be set, or --only-binary=:all: must be "
|
|
|
|
"set and --no-binary must not be set (or must be set to "
|
|
|
|
":none:)."
|
|
|
|
)
|
|
|
|
|
|
|
|
if check_target:
|
|
|
|
if dist_restriction_set and not options.target_dir:
|
|
|
|
raise CommandError(
|
|
|
|
"Can not use any platform or abi specific options unless "
|
|
|
|
"installing via '--target'"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _path_option_check(option: Option, opt: str, value: str) -> str:
|
2020-01-01 16:00:33 +01:00
|
|
|
return os.path.expanduser(value)
|
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _package_name_option_check(option: Option, opt: str, value: str) -> str:
|
2020-10-30 21:50:59 +01:00
|
|
|
return canonicalize_name(value)
|
|
|
|
|
|
|
|
|
2020-01-07 06:20:51 +01:00
|
|
|
class PipOption(Option):
|
2020-10-30 21:50:59 +01:00
|
|
|
TYPES = Option.TYPES + ("path", "package_name")
|
2020-01-01 16:00:33 +01:00
|
|
|
TYPE_CHECKER = Option.TYPE_CHECKER.copy()
|
2020-10-30 21:50:59 +01:00
|
|
|
TYPE_CHECKER["package_name"] = _package_name_option_check
|
2020-01-01 16:00:33 +01:00
|
|
|
TYPE_CHECKER["path"] = _path_option_check
|
|
|
|
|
|
|
|
|
2012-12-18 06:35:09 +01:00
|
|
|
###########
|
|
|
|
# options #
|
|
|
|
###########
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
help_: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"-h",
|
|
|
|
"--help",
|
|
|
|
dest="help",
|
|
|
|
action="help",
|
|
|
|
help="Show help.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
isolated_mode: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2014-11-24 03:07:53 +01:00
|
|
|
"--isolated",
|
|
|
|
dest="isolated_mode",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help=(
|
|
|
|
"Run pip in an isolated mode, ignoring environment variables and user "
|
|
|
|
"configuration."
|
|
|
|
),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2014-11-24 03:07:53 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
require_virtualenv: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
# Run only if inside a virtualenv, bail if not.
|
2021-02-20 16:13:27 +01:00
|
|
|
"--require-virtualenv",
|
|
|
|
"--require-venv",
|
|
|
|
dest="require_venv",
|
|
|
|
action="store_true",
|
2013-09-17 07:21:15 +02:00
|
|
|
default=False,
|
2021-02-20 16:13:27 +01:00
|
|
|
help=SUPPRESS_HELP,
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
verbose: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"-v",
|
|
|
|
"--verbose",
|
|
|
|
dest="verbose",
|
|
|
|
action="count",
|
2013-09-17 07:21:15 +02:00
|
|
|
default=0,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Give more output. Option is additive, and can be used up to 3 times.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_color: Callable[..., Option] = partial(
|
2017-11-05 10:53:57 +01:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-color",
|
|
|
|
dest="no_color",
|
|
|
|
action="store_true",
|
2017-11-05 10:53:57 +01:00
|
|
|
default=False,
|
2020-09-23 06:27:53 +02:00
|
|
|
help="Suppress colored output.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2017-11-05 10:53:57 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
version: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"-V",
|
|
|
|
"--version",
|
|
|
|
dest="version",
|
|
|
|
action="store_true",
|
|
|
|
help="Show version and exit.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
quiet: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"-q",
|
|
|
|
"--quiet",
|
|
|
|
dest="quiet",
|
|
|
|
action="count",
|
2013-09-17 07:21:15 +02:00
|
|
|
default=0,
|
2017-09-02 13:22:19 +02:00
|
|
|
help=(
|
2021-02-20 16:13:27 +01:00
|
|
|
"Give less output. Option is additive, and can be used up to 3"
|
|
|
|
" times (corresponding to WARNING, ERROR, and CRITICAL logging"
|
|
|
|
" levels)."
|
2017-09-02 13:22:19 +02:00
|
|
|
),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
progress_bar: Callable[..., Option] = partial(
|
2016-12-22 15:59:55 +01:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--progress-bar",
|
|
|
|
dest="progress_bar",
|
|
|
|
type="choice",
|
2016-12-22 15:59:55 +01:00
|
|
|
choices=list(BAR_TYPES.keys()),
|
2021-02-20 16:13:27 +01:00
|
|
|
default="on",
|
2017-09-02 13:22:19 +02:00
|
|
|
help=(
|
2021-02-20 16:13:27 +01:00
|
|
|
"Specify type of progress to be displayed ["
|
|
|
|
+ "|".join(BAR_TYPES.keys())
|
|
|
|
+ "] (default: %default)"
|
2017-09-02 13:22:19 +02:00
|
|
|
),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2016-12-22 15:59:55 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
log: Callable[..., Option] = partial(
|
2020-01-07 06:20:51 +01:00
|
|
|
PipOption,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--log",
|
|
|
|
"--log-file",
|
|
|
|
"--local-log",
|
2014-08-31 01:52:28 +02:00
|
|
|
dest="log",
|
|
|
|
metavar="path",
|
2020-01-01 16:00:33 +01:00
|
|
|
type="path",
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Path to a verbose appending log.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_input: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
# Don't ask for input
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-input",
|
|
|
|
dest="no_input",
|
|
|
|
action="store_true",
|
2013-09-17 07:21:15 +02:00
|
|
|
default=False,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Disable prompting for input.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
proxy: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--proxy",
|
|
|
|
dest="proxy",
|
|
|
|
type="str",
|
|
|
|
default="",
|
|
|
|
help="Specify a proxy in the form [user:passwd@]proxy.server:port.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
retries: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--retries",
|
|
|
|
dest="retries",
|
|
|
|
type="int",
|
2014-12-02 08:56:34 +01:00
|
|
|
default=5,
|
2014-01-09 10:07:51 +01:00
|
|
|
help="Maximum number of retries each connection should attempt "
|
2021-02-20 16:13:27 +01:00
|
|
|
"(default %default times).",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2014-01-09 10:07:51 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
timeout: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--timeout",
|
|
|
|
"--default-timeout",
|
|
|
|
metavar="sec",
|
|
|
|
dest="timeout",
|
|
|
|
type="float",
|
2013-09-17 07:21:15 +02:00
|
|
|
default=15,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Set the socket timeout (default %default seconds).",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def exists_action() -> Option:
|
2015-04-17 04:41:36 +02:00
|
|
|
return Option(
|
|
|
|
# Option when path already exist
|
2021-02-20 16:13:27 +01:00
|
|
|
"--exists-action",
|
|
|
|
dest="exists_action",
|
|
|
|
type="choice",
|
|
|
|
choices=["s", "i", "w", "b", "a"],
|
2015-04-17 04:41:36 +02:00
|
|
|
default=[],
|
2021-02-20 16:13:27 +01:00
|
|
|
action="append",
|
|
|
|
metavar="action",
|
2015-04-17 04:41:36 +02:00
|
|
|
help="Default action when a path already exists: "
|
2021-02-20 16:13:27 +01:00
|
|
|
"(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.",
|
2017-09-02 13:22:19 +02:00
|
|
|
)
|
2015-04-17 04:41:36 +02:00
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
cert: Callable[..., Option] = partial(
|
2020-01-07 06:20:51 +01:00
|
|
|
PipOption,
|
2021-02-26 10:32:18 +01:00
|
|
|
"--cert",
|
|
|
|
dest="cert",
|
|
|
|
type="path",
|
|
|
|
metavar="path",
|
2021-02-24 10:07:05 +01:00
|
|
|
help=(
|
|
|
|
"Path to PEM-encoded CA certificate bundle. "
|
|
|
|
"If provided, overrides the default. "
|
|
|
|
"See 'SSL Certificate Verification' in pip documentation "
|
|
|
|
"for more information."
|
|
|
|
),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
client_cert: Callable[..., Option] = partial(
|
2020-01-07 06:20:51 +01:00
|
|
|
PipOption,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--client-cert",
|
|
|
|
dest="client_cert",
|
|
|
|
type="path",
|
2014-03-07 13:41:15 +01:00
|
|
|
default=None,
|
2021-02-20 16:13:27 +01:00
|
|
|
metavar="path",
|
2014-03-07 13:41:15 +01:00
|
|
|
help="Path to SSL client certificate, a single file containing the "
|
2021-02-20 16:13:27 +01:00
|
|
|
"private key and the certificate in PEM format.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2014-03-07 13:41:15 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
index_url: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"-i",
|
|
|
|
"--index-url",
|
|
|
|
"--pypi-url",
|
|
|
|
dest="index_url",
|
|
|
|
metavar="URL",
|
2014-12-16 07:04:00 +01:00
|
|
|
default=PyPI.simple_url,
|
2019-05-07 15:13:56 +02:00
|
|
|
help="Base URL of the Python Package Index (default %default). "
|
2021-02-20 16:13:27 +01:00
|
|
|
"This should point to a repository compliant with PEP 503 "
|
|
|
|
"(the simple repository API) or a local directory laid out "
|
|
|
|
"in the same format.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2012-12-18 06:35:09 +01:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def extra_index_url() -> Option:
|
2015-04-17 04:41:36 +02:00
|
|
|
return Option(
|
2021-02-20 16:13:27 +01:00
|
|
|
"--extra-index-url",
|
|
|
|
dest="extra_index_urls",
|
|
|
|
metavar="URL",
|
|
|
|
action="append",
|
2015-04-17 04:41:36 +02:00
|
|
|
default=[],
|
2016-05-20 22:19:30 +02:00
|
|
|
help="Extra URLs of package indexes to use in addition to "
|
2021-02-20 16:13:27 +01:00
|
|
|
"--index-url. Should follow the same rules as "
|
|
|
|
"--index-url.",
|
2015-04-17 04:41:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_index: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-index",
|
|
|
|
dest="no_index",
|
|
|
|
action="store_true",
|
2012-12-18 06:35:09 +01:00
|
|
|
default=False,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Ignore package index (only looking at --find-links URLs instead).",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-01-18 22:25:15 +01:00
|
|
|
|
2013-06-07 15:48:34 +02:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def find_links() -> Option:
|
2020-01-02 13:46:14 +01:00
|
|
|
return Option(
|
2021-02-20 16:13:27 +01:00
|
|
|
"-f",
|
|
|
|
"--find-links",
|
|
|
|
dest="find_links",
|
|
|
|
action="append",
|
2015-04-17 04:41:36 +02:00
|
|
|
default=[],
|
2021-02-20 16:13:27 +01:00
|
|
|
metavar="url",
|
2020-04-04 14:36:26 +02:00
|
|
|
help="If a URL or path to an html file, then parse for links to "
|
2021-02-20 16:13:27 +01:00
|
|
|
"archives such as sdist (.tar.gz) or wheel (.whl) files. "
|
2021-06-07 11:42:32 +02:00
|
|
|
"If a local path or file:// URL that's a directory, "
|
2021-02-20 16:13:27 +01:00
|
|
|
"then look for archives in the directory listing. "
|
|
|
|
"Links to VCS project URLs are not supported.",
|
2017-09-02 13:22:19 +02:00
|
|
|
)
|
2015-04-17 04:41:36 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def trusted_host() -> Option:
|
2015-04-17 04:41:36 +02:00
|
|
|
return Option(
|
|
|
|
"--trusted-host",
|
|
|
|
dest="trusted_hosts",
|
|
|
|
action="append",
|
|
|
|
metavar="HOSTNAME",
|
|
|
|
default=[],
|
2019-08-26 01:26:01 +02:00
|
|
|
help="Mark this host or host:port pair as trusted, even though it "
|
2021-02-20 16:13:27 +01:00
|
|
|
"does not have valid or any HTTPS.",
|
2015-04-17 04:41:36 +02:00
|
|
|
)
|
|
|
|
|
2014-12-10 01:40:05 +01:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def constraints() -> Option:
|
2020-01-02 13:46:14 +01:00
|
|
|
return Option(
|
2021-02-20 16:13:27 +01:00
|
|
|
"-c",
|
|
|
|
"--constraint",
|
|
|
|
dest="constraints",
|
|
|
|
action="append",
|
2015-06-02 05:39:10 +02:00
|
|
|
default=[],
|
2021-02-20 16:13:27 +01:00
|
|
|
metavar="file",
|
|
|
|
help="Constrain versions using the given constraints file. "
|
|
|
|
"This option can be used multiple times.",
|
2017-09-02 13:22:19 +02:00
|
|
|
)
|
2015-06-02 05:39:10 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def requirements() -> Option:
|
2020-01-02 13:46:14 +01:00
|
|
|
return Option(
|
2021-02-20 16:13:27 +01:00
|
|
|
"-r",
|
|
|
|
"--requirement",
|
|
|
|
dest="requirements",
|
|
|
|
action="append",
|
2015-04-17 04:41:36 +02:00
|
|
|
default=[],
|
2021-02-20 16:13:27 +01:00
|
|
|
metavar="file",
|
|
|
|
help="Install from the given requirements file. "
|
|
|
|
"This option can be used multiple times.",
|
2017-09-02 13:22:19 +02:00
|
|
|
)
|
2015-04-17 04:41:36 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def editable() -> Option:
|
2020-01-02 13:46:14 +01:00
|
|
|
return Option(
|
2021-02-20 16:13:27 +01:00
|
|
|
"-e",
|
|
|
|
"--editable",
|
|
|
|
dest="editables",
|
|
|
|
action="append",
|
2015-04-17 04:41:36 +02:00
|
|
|
default=[],
|
2021-02-20 16:13:27 +01:00
|
|
|
metavar="path/url",
|
|
|
|
help=(
|
|
|
|
"Install a project in editable mode (i.e. setuptools "
|
|
|
|
'"develop mode") from a local project path or a VCS url.'
|
|
|
|
),
|
2015-04-17 04:41:36 +02:00
|
|
|
)
|
|
|
|
|
2017-03-20 01:49:09 +01:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _handle_src(option: Option, opt_str: str, value: str, parser: OptionParser) -> None:
|
2019-12-12 02:00:22 +01:00
|
|
|
value = os.path.abspath(value)
|
|
|
|
setattr(parser.values, option.dest, value)
|
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
src: Callable[..., Option] = partial(
|
2020-01-07 06:20:51 +01:00
|
|
|
PipOption,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--src",
|
|
|
|
"--source",
|
|
|
|
"--source-dir",
|
|
|
|
"--source-directory",
|
|
|
|
dest="src_dir",
|
|
|
|
type="path",
|
|
|
|
metavar="dir",
|
2019-07-18 22:50:05 +02:00
|
|
|
default=get_src_prefix(),
|
2021-02-20 16:13:27 +01:00
|
|
|
action="callback",
|
2019-12-12 02:00:22 +01:00
|
|
|
callback=_handle_src,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Directory to check out editable projects into. "
|
2014-05-09 06:29:01 +02:00
|
|
|
'The default in a virtualenv is "<venv path>/src". '
|
2021-02-20 16:13:27 +01:00
|
|
|
'The default for global installs is "<current dir>/src".',
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2014-05-09 06:29:01 +02:00
|
|
|
|
2015-04-17 05:03:34 +02:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _get_format_control(values: Values, option: Option) -> Any:
|
2015-04-17 05:03:34 +02:00
|
|
|
"""Get a format_control object."""
|
|
|
|
return getattr(values, option.dest)
|
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _handle_no_binary(
|
|
|
|
option: Option, opt_str: str, value: str, parser: OptionParser
|
|
|
|
) -> None:
|
2018-08-28 19:19:09 +02:00
|
|
|
existing = _get_format_control(parser.values, option)
|
2018-08-28 17:37:45 +02:00
|
|
|
FormatControl.handle_mutual_excludes(
|
2021-02-20 16:13:27 +01:00
|
|
|
value,
|
|
|
|
existing.no_binary,
|
|
|
|
existing.only_binary,
|
2017-12-25 10:53:27 +01:00
|
|
|
)
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _handle_only_binary(
|
|
|
|
option: Option, opt_str: str, value: str, parser: OptionParser
|
|
|
|
) -> None:
|
2018-08-28 19:19:09 +02:00
|
|
|
existing = _get_format_control(parser.values, option)
|
2018-08-28 17:37:45 +02:00
|
|
|
FormatControl.handle_mutual_excludes(
|
2021-02-20 16:13:27 +01:00
|
|
|
value,
|
|
|
|
existing.only_binary,
|
|
|
|
existing.no_binary,
|
2017-12-25 10:53:27 +01:00
|
|
|
)
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def no_binary() -> Option:
|
2018-08-04 21:07:13 +02:00
|
|
|
format_control = FormatControl(set(), set())
|
2015-04-17 05:03:34 +02:00
|
|
|
return Option(
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-binary",
|
|
|
|
dest="format_control",
|
|
|
|
action="callback",
|
|
|
|
callback=_handle_no_binary,
|
|
|
|
type="str",
|
2018-08-04 21:07:13 +02:00
|
|
|
default=format_control,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Do not use binary packages. Can be supplied multiple times, and "
|
|
|
|
'each time adds to the existing value. Accepts either ":all:" to '
|
|
|
|
'disable all binary packages, ":none:" to empty the set (notice '
|
|
|
|
"the colons), or one or more package names with commas between "
|
|
|
|
"them (no colons). Note that some packages are tricky to compile "
|
|
|
|
"and may fail to install when this option is used on them.",
|
2017-09-02 13:22:19 +02:00
|
|
|
)
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def only_binary() -> Option:
|
2018-08-04 21:07:13 +02:00
|
|
|
format_control = FormatControl(set(), set())
|
2015-04-17 05:03:34 +02:00
|
|
|
return Option(
|
2021-02-20 16:13:27 +01:00
|
|
|
"--only-binary",
|
|
|
|
dest="format_control",
|
|
|
|
action="callback",
|
|
|
|
callback=_handle_only_binary,
|
|
|
|
type="str",
|
2018-08-04 21:07:13 +02:00
|
|
|
default=format_control,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Do not use source packages. Can be supplied multiple times, and "
|
|
|
|
'each time adds to the existing value. Accepts either ":all:" to '
|
|
|
|
'disable all source packages, ":none:" to empty the set, or one '
|
|
|
|
"or more package names with commas between them. Packages "
|
|
|
|
"without binary distributions will fail to install when this "
|
|
|
|
"option is used on them.",
|
2017-09-02 13:22:19 +02:00
|
|
|
)
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
platforms: Callable[..., Option] = partial(
|
2018-07-24 17:09:32 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--platform",
|
|
|
|
dest="platforms",
|
|
|
|
metavar="platform",
|
|
|
|
action="append",
|
2018-07-24 17:09:32 +02:00
|
|
|
default=None,
|
2021-02-20 16:13:27 +01:00
|
|
|
help=(
|
|
|
|
"Only use wheels compatible with <platform>. Defaults to the "
|
|
|
|
"platform of the running system. Use this option multiple times to "
|
|
|
|
"specify multiple platforms supported by the target interpreter."
|
|
|
|
),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2018-07-24 17:09:32 +02:00
|
|
|
|
|
|
|
|
2019-05-25 20:48:51 +02:00
|
|
|
# This was made a separate function for unit-testing purposes.
|
2021-06-07 15:19:23 +02:00
|
|
|
def _convert_python_version(value: str) -> Tuple[Tuple[int, ...], Optional[str]]:
|
2019-05-25 20:48:51 +02:00
|
|
|
"""
|
2019-06-09 04:37:11 +02:00
|
|
|
Convert a version string like "3", "37", or "3.7.3" into a tuple of ints.
|
|
|
|
|
|
|
|
:return: A 2-tuple (version_info, error_msg), where `error_msg` is
|
|
|
|
non-None if and only if there was a parsing error.
|
2019-05-25 20:48:51 +02:00
|
|
|
"""
|
2019-06-09 04:37:11 +02:00
|
|
|
if not value:
|
|
|
|
# The empty string is the same as not providing a value.
|
|
|
|
return (None, None)
|
|
|
|
|
2021-02-20 16:13:27 +01:00
|
|
|
parts = value.split(".")
|
2019-06-09 04:37:11 +02:00
|
|
|
if len(parts) > 3:
|
2021-02-20 16:13:27 +01:00
|
|
|
return ((), "at most three version parts are allowed")
|
2019-06-09 04:37:11 +02:00
|
|
|
|
|
|
|
if len(parts) == 1:
|
|
|
|
# Then we are in the case of "3" or "37".
|
|
|
|
value = parts[0]
|
|
|
|
if len(value) > 1:
|
|
|
|
parts = [value[0], value[1:]]
|
|
|
|
|
|
|
|
try:
|
|
|
|
version_info = tuple(int(part) for part in parts)
|
|
|
|
except ValueError:
|
2021-02-20 16:13:27 +01:00
|
|
|
return ((), "each version part must be an integer")
|
2019-05-25 20:48:51 +02:00
|
|
|
|
2019-06-09 04:37:11 +02:00
|
|
|
return (version_info, None)
|
2019-05-25 20:48:51 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _handle_python_version(
|
|
|
|
option: Option, opt_str: str, value: str, parser: OptionParser
|
|
|
|
) -> None:
|
2019-05-25 20:48:51 +02:00
|
|
|
"""
|
2019-06-09 04:37:11 +02:00
|
|
|
Handle a provided --python-version value.
|
2019-05-25 20:48:51 +02:00
|
|
|
"""
|
2019-06-09 04:37:11 +02:00
|
|
|
version_info, error_msg = _convert_python_version(value)
|
|
|
|
if error_msg is not None:
|
2021-02-20 16:13:27 +01:00
|
|
|
msg = "invalid --python-version value: {!r}: {}".format(
|
|
|
|
value,
|
|
|
|
error_msg,
|
2019-06-09 04:37:11 +02:00
|
|
|
)
|
|
|
|
raise_option_error(parser, option=option, msg=msg)
|
|
|
|
|
2019-05-25 20:48:51 +02:00
|
|
|
parser.values.python_version = version_info
|
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
python_version: Callable[..., Option] = partial(
|
2018-07-24 17:09:32 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--python-version",
|
|
|
|
dest="python_version",
|
|
|
|
metavar="python_version",
|
|
|
|
action="callback",
|
|
|
|
callback=_handle_python_version,
|
|
|
|
type="str",
|
2018-07-24 17:09:32 +02:00
|
|
|
default=None,
|
2021-02-20 16:13:27 +01:00
|
|
|
help=dedent(
|
|
|
|
"""\
|
2019-06-09 04:37:11 +02:00
|
|
|
The Python interpreter version to use for wheel and "Requires-Python"
|
|
|
|
compatibility checks. Defaults to a version derived from the running
|
|
|
|
interpreter. The version can be specified using up to three dot-separated
|
|
|
|
integers (e.g. "3" for 3.0.0, "3.7" for 3.7.0, or "3.7.3"). A major-minor
|
|
|
|
version can also be given as a string without dots (e.g. "37" for 3.7.0).
|
2021-02-20 16:13:27 +01:00
|
|
|
"""
|
|
|
|
),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2018-07-24 17:09:32 +02:00
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
implementation: Callable[..., Option] = partial(
|
2018-07-24 17:09:32 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--implementation",
|
|
|
|
dest="implementation",
|
|
|
|
metavar="implementation",
|
2018-07-24 17:09:32 +02:00
|
|
|
default=None,
|
2021-02-20 16:13:27 +01:00
|
|
|
help=(
|
|
|
|
"Only use wheels compatible with Python "
|
|
|
|
"implementation <implementation>, e.g. 'pp', 'jy', 'cp', "
|
|
|
|
" or 'ip'. If not specified, then the current "
|
|
|
|
"interpreter implementation is used. Use 'py' to force "
|
|
|
|
"implementation-agnostic wheels."
|
|
|
|
),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2018-07-24 17:09:32 +02:00
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
abis: Callable[..., Option] = partial(
|
2018-07-24 17:09:32 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--abi",
|
|
|
|
dest="abis",
|
|
|
|
metavar="abi",
|
|
|
|
action="append",
|
2018-07-24 17:09:32 +02:00
|
|
|
default=None,
|
2021-02-20 16:13:27 +01:00
|
|
|
help=(
|
|
|
|
"Only use wheels compatible with Python abi <abi>, e.g. 'pypy_41'. "
|
|
|
|
"If not specified, then the current interpreter abi tag is used. "
|
|
|
|
"Use this option multiple times to specify multiple abis supported "
|
|
|
|
"by the target interpreter. Generally you will need to specify "
|
|
|
|
"--implementation, --platform, and --python-version when using this "
|
|
|
|
"option."
|
|
|
|
),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2018-07-24 17:09:32 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def add_target_python_options(cmd_opts: OptionGroup) -> None:
|
2020-10-27 02:08:39 +01:00
|
|
|
cmd_opts.add_option(platforms())
|
2019-06-22 08:30:34 +02:00
|
|
|
cmd_opts.add_option(python_version())
|
|
|
|
cmd_opts.add_option(implementation())
|
2020-10-27 02:08:39 +01:00
|
|
|
cmd_opts.add_option(abis())
|
2019-06-22 08:30:34 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def make_target_python(options: Values) -> TargetPython:
|
2019-06-22 08:30:34 +02:00
|
|
|
target_python = TargetPython(
|
2020-10-27 02:08:39 +01:00
|
|
|
platforms=options.platforms,
|
2019-06-22 08:30:34 +02:00
|
|
|
py_version_info=options.python_version,
|
2020-10-27 02:08:39 +01:00
|
|
|
abis=options.abis,
|
2019-06-22 08:30:34 +02:00
|
|
|
implementation=options.implementation,
|
|
|
|
)
|
|
|
|
|
|
|
|
return target_python
|
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def prefer_binary() -> Option:
|
2018-05-11 07:47:32 +02:00
|
|
|
return Option(
|
|
|
|
"--prefer-binary",
|
|
|
|
dest="prefer_binary",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Prefer older binary packages over newer source packages.",
|
2018-05-11 07:47:32 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
cache_dir: Callable[..., Option] = partial(
|
2020-01-07 06:20:51 +01:00
|
|
|
PipOption,
|
2014-04-24 13:29:57 +02:00
|
|
|
"--cache-dir",
|
|
|
|
dest="cache_dir",
|
|
|
|
default=USER_CACHE_DIR,
|
|
|
|
metavar="dir",
|
2021-02-20 16:13:27 +01:00
|
|
|
type="path",
|
|
|
|
help="Store the cache data in <dir>.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2014-04-24 13:29:57 +02:00
|
|
|
|
2018-10-14 10:27:21 +02:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _handle_no_cache_dir(
|
|
|
|
option: Option, opt: str, value: str, parser: OptionParser
|
|
|
|
) -> None:
|
2018-10-14 10:27:21 +02:00
|
|
|
"""
|
|
|
|
Process a value provided for the --no-cache-dir option.
|
|
|
|
|
|
|
|
This is an optparse.Option callback for the --no-cache-dir option.
|
|
|
|
"""
|
|
|
|
# The value argument will be None if --no-cache-dir is passed via the
|
|
|
|
# command-line, since the option doesn't accept arguments. However,
|
|
|
|
# the value can be non-None if the option is triggered e.g. by an
|
|
|
|
# environment variable, like PIP_NO_CACHE_DIR=true.
|
|
|
|
if value is not None:
|
|
|
|
# Then parse the string value to get argument error-checking.
|
2019-01-13 11:06:34 +01:00
|
|
|
try:
|
|
|
|
strtobool(value)
|
|
|
|
except ValueError as exc:
|
|
|
|
raise_option_error(parser, option=option, msg=str(exc))
|
2018-10-14 10:27:21 +02:00
|
|
|
|
|
|
|
# Originally, setting PIP_NO_CACHE_DIR to a value that strtobool()
|
|
|
|
# converted to 0 (like "false" or "no") caused cache_dir to be disabled
|
|
|
|
# rather than enabled (logic would say the latter). Thus, we disable
|
|
|
|
# the cache directory not just on values that parse to True, but (for
|
|
|
|
# backwards compatibility reasons) also on values that parse to False.
|
|
|
|
# In other words, always set it to False if the option is provided in
|
|
|
|
# some (valid) form.
|
|
|
|
parser.values.cache_dir = False
|
|
|
|
|
2014-04-24 13:29:57 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_cache: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2014-04-24 13:29:57 +02:00
|
|
|
"--no-cache-dir",
|
|
|
|
dest="cache_dir",
|
2018-10-14 10:27:21 +02:00
|
|
|
action="callback",
|
2019-05-25 18:55:49 +02:00
|
|
|
callback=_handle_no_cache_dir,
|
2014-04-24 13:29:57 +02:00
|
|
|
help="Disable the cache.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2014-04-24 13:29:57 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_deps: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-deps",
|
|
|
|
"--no-dependencies",
|
|
|
|
dest="ignore_dependencies",
|
|
|
|
action="store_true",
|
2013-02-03 07:40:30 +01:00
|
|
|
default=False,
|
2018-01-28 14:53:27 +01:00
|
|
|
help="Don't install package dependencies.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-02-03 07:40:30 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
build_dir: Callable[..., Option] = partial(
|
2020-12-01 23:12:51 +01:00
|
|
|
PipOption,
|
2021-02-20 16:13:27 +01:00
|
|
|
"-b",
|
|
|
|
"--build",
|
|
|
|
"--build-dir",
|
|
|
|
"--build-directory",
|
|
|
|
dest="build_dir",
|
|
|
|
type="path",
|
|
|
|
metavar="dir",
|
2020-12-01 23:12:51 +01:00
|
|
|
help=SUPPRESS_HELP,
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2019-12-12 02:07:08 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
ignore_requires_python: Callable[..., Option] = partial(
|
2016-07-17 11:29:02 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--ignore-requires-python",
|
|
|
|
dest="ignore_requires_python",
|
|
|
|
action="store_true",
|
|
|
|
help="Ignore the Requires-Python information.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2016-07-17 11:29:02 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_build_isolation: Callable[..., Option] = partial(
|
2018-03-04 12:40:09 +01:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-build-isolation",
|
|
|
|
dest="build_isolation",
|
|
|
|
action="store_false",
|
2018-03-04 12:40:09 +01:00
|
|
|
default=True,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Disable isolation when building a modern source distribution. "
|
|
|
|
"Build dependencies specified by PEP 518 must be already installed "
|
|
|
|
"if this option is used.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2018-03-04 12:40:09 +01:00
|
|
|
|
2019-01-13 16:59:17 +01:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _handle_no_use_pep517(
|
|
|
|
option: Option, opt: str, value: str, parser: OptionParser
|
|
|
|
) -> None:
|
2019-01-13 16:59:17 +01:00
|
|
|
"""
|
|
|
|
Process a value provided for the --no-use-pep517 option.
|
|
|
|
|
|
|
|
This is an optparse.Option callback for the no_use_pep517 option.
|
|
|
|
"""
|
|
|
|
# Since --no-use-pep517 doesn't accept arguments, the value argument
|
|
|
|
# will be None if --no-use-pep517 is passed via the command-line.
|
|
|
|
# However, the value can be non-None if the option is triggered e.g.
|
|
|
|
# by an environment variable, for example "PIP_NO_USE_PEP517=true".
|
|
|
|
if value is not None:
|
|
|
|
msg = """A value was passed for --no-use-pep517,
|
|
|
|
probably using either the PIP_NO_USE_PEP517 environment variable
|
|
|
|
or the "no-use-pep517" config file option. Use an appropriate value
|
|
|
|
of the PIP_USE_PEP517 environment variable or the "use-pep517"
|
|
|
|
config file option instead.
|
|
|
|
"""
|
|
|
|
raise_option_error(parser, option=option, msg=msg)
|
|
|
|
|
|
|
|
# Otherwise, --no-use-pep517 was passed via the command-line.
|
|
|
|
parser.values.use_pep517 = False
|
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
use_pep517: Any = partial(
|
2018-10-09 16:18:00 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--use-pep517",
|
|
|
|
dest="use_pep517",
|
|
|
|
action="store_true",
|
2018-10-09 16:18:00 +02:00
|
|
|
default=None,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Use PEP 517 for building source distributions "
|
|
|
|
"(use --no-use-pep517 to force legacy behaviour).",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2018-10-09 16:18:00 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_use_pep517: Any = partial(
|
2018-10-09 16:18:00 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-use-pep517",
|
|
|
|
dest="use_pep517",
|
|
|
|
action="callback",
|
2019-05-25 18:55:49 +02:00
|
|
|
callback=_handle_no_use_pep517,
|
2018-10-09 16:18:00 +02:00
|
|
|
default=None,
|
2021-02-20 16:13:27 +01:00
|
|
|
help=SUPPRESS_HELP,
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2018-10-09 16:18:00 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
install_options: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--install-option",
|
|
|
|
dest="install_options",
|
|
|
|
action="append",
|
|
|
|
metavar="options",
|
2013-02-03 07:40:30 +01:00
|
|
|
help="Extra arguments to be supplied to the setup.py install "
|
2021-02-20 16:13:27 +01:00
|
|
|
'command (use like --install-option="--install-scripts=/usr/local/'
|
|
|
|
'bin"). Use multiple --install-option options to pass multiple '
|
|
|
|
"options to setup.py install. If you are using an option with a "
|
|
|
|
"directory path, be sure to use absolute path.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-02-03 07:40:30 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
build_options: Callable[..., Option] = partial(
|
2021-01-03 13:26:28 +01:00
|
|
|
Option,
|
|
|
|
"--build-option",
|
|
|
|
dest="build_options",
|
|
|
|
metavar="options",
|
|
|
|
action="append",
|
|
|
|
help="Extra arguments to be supplied to 'setup.py bdist_wheel'.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2021-01-03 13:26:28 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
global_options: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--global-option",
|
|
|
|
dest="global_options",
|
|
|
|
action="append",
|
|
|
|
metavar="options",
|
2013-02-03 07:40:30 +01:00
|
|
|
help="Extra global options to be supplied to the setup.py "
|
2021-04-04 17:07:31 +02:00
|
|
|
"call before the install or bdist_wheel command.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-02-03 07:40:30 +01:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_clean: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-clean",
|
|
|
|
action="store_true",
|
2013-05-25 02:11:15 +02:00
|
|
|
default=False,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Don't clean up build directories.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2013-05-25 02:11:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
pre: Callable[..., Option] = partial(
|
2015-08-03 23:07:07 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--pre",
|
|
|
|
action="store_true",
|
2015-08-03 23:07:07 +02:00
|
|
|
default=False,
|
|
|
|
help="Include pre-release and development versions. By default, "
|
2021-02-20 16:13:27 +01:00
|
|
|
"pip only finds stable versions.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2015-08-03 23:07:07 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
disable_pip_version_check: Callable[..., Option] = partial(
|
2015-04-17 04:41:36 +02:00
|
|
|
Option,
|
2014-09-18 13:36:40 +02:00
|
|
|
"--disable-pip-version-check",
|
|
|
|
dest="disable_pip_version_check",
|
2014-08-12 03:15:55 +02:00
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Don't periodically check PyPI to determine whether a new version "
|
2021-02-20 16:13:27 +01:00
|
|
|
"of pip is available for download. Implied with --no-index.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2012-12-18 06:35:09 +01:00
|
|
|
|
2016-12-22 15:59:55 +01:00
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def _handle_merge_hash(
|
|
|
|
option: Option, opt_str: str, value: str, parser: OptionParser
|
|
|
|
) -> None:
|
2015-09-25 00:31:14 +02:00
|
|
|
"""Given a value spelled "algo:digest", append the digest to a list
|
|
|
|
pointed to in a dict by the algo name."""
|
2015-09-03 23:37:29 +02:00
|
|
|
if not parser.values.hashes:
|
2019-02-21 22:40:57 +01:00
|
|
|
parser.values.hashes = {}
|
2015-09-25 00:31:14 +02:00
|
|
|
try:
|
2021-02-20 16:13:27 +01:00
|
|
|
algo, digest = value.split(":", 1)
|
2015-09-25 00:31:14 +02:00
|
|
|
except ValueError:
|
2021-02-20 16:13:27 +01:00
|
|
|
parser.error(
|
|
|
|
"Arguments to {} must be a hash name " # noqa
|
|
|
|
"followed by a value, like --hash=sha256:"
|
|
|
|
"abcde...".format(opt_str)
|
|
|
|
)
|
2015-10-12 22:29:08 +02:00
|
|
|
if algo not in STRONG_HASHES:
|
2021-02-20 16:13:27 +01:00
|
|
|
parser.error(
|
|
|
|
"Allowed hash algorithms for {} are {}.".format( # noqa
|
|
|
|
opt_str, ", ".join(STRONG_HASHES)
|
|
|
|
)
|
|
|
|
)
|
2015-09-25 00:31:14 +02:00
|
|
|
parser.values.hashes.setdefault(algo, []).append(digest)
|
|
|
|
|
2015-09-25 00:53:39 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
hash: Callable[..., Option] = partial(
|
2015-09-25 00:31:14 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--hash",
|
2015-09-25 00:31:14 +02:00
|
|
|
# Hash values eventually end up in InstallRequirement.hashes due to
|
|
|
|
# __dict__ copying in process_line().
|
2021-02-20 16:13:27 +01:00
|
|
|
dest="hashes",
|
|
|
|
action="callback",
|
2019-05-25 18:55:49 +02:00
|
|
|
callback=_handle_merge_hash,
|
2021-02-20 16:13:27 +01:00
|
|
|
type="string",
|
2015-09-25 00:31:14 +02:00
|
|
|
help="Verify that the package's archive matches this "
|
2021-02-20 16:13:27 +01:00
|
|
|
"hash before installing. Example: --hash=sha256:abcdef...",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2015-09-03 23:37:29 +02:00
|
|
|
|
2015-04-17 07:10:46 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
require_hashes: Callable[..., Option] = partial(
|
2015-10-07 23:33:57 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--require-hashes",
|
|
|
|
dest="require_hashes",
|
|
|
|
action="store_true",
|
2015-10-07 23:33:57 +02:00
|
|
|
default=False,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Require a hash to check each requirement against, for "
|
|
|
|
"repeatable installs. This option is implied when any package in a "
|
|
|
|
"requirements file has a --hash option.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2015-10-07 23:33:57 +02:00
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
list_path: Callable[..., Option] = partial(
|
2020-01-07 06:20:51 +01:00
|
|
|
PipOption,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--path",
|
|
|
|
dest="path",
|
|
|
|
type="path",
|
|
|
|
action="append",
|
|
|
|
help="Restrict to the specified installation path for listing "
|
|
|
|
"packages (can be used multiple times).",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2019-06-12 23:09:00 +02:00
|
|
|
|
|
|
|
|
2021-06-07 15:19:23 +02:00
|
|
|
def check_list_path_option(options: Values) -> None:
|
2019-06-12 23:09:00 +02:00
|
|
|
if options.path and (options.user or options.local):
|
2021-02-20 16:13:27 +01:00
|
|
|
raise CommandError("Cannot combine '--path' with '--user' or '--local'")
|
2019-06-12 23:09:00 +02:00
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
list_exclude: Callable[..., Option] = partial(
|
2020-10-30 21:50:59 +01:00
|
|
|
PipOption,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--exclude",
|
|
|
|
dest="excludes",
|
|
|
|
action="append",
|
|
|
|
metavar="package",
|
|
|
|
type="package_name",
|
2020-10-30 21:50:59 +01:00
|
|
|
help="Exclude specified package from the output",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2020-10-30 21:50:59 +01:00
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
no_python_version_warning: Callable[..., Option] = partial(
|
2019-12-15 02:59:34 +01:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--no-python-version-warning",
|
|
|
|
dest="no_python_version_warning",
|
|
|
|
action="store_true",
|
2019-12-15 02:59:34 +01:00
|
|
|
default=False,
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Silence deprecation warnings for upcoming unsupported Pythons.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2019-12-15 02:59:34 +01:00
|
|
|
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
use_new_feature: Callable[..., Option] = partial(
|
2020-07-03 15:14:02 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--use-feature",
|
|
|
|
dest="features_enabled",
|
|
|
|
metavar="feature",
|
|
|
|
action="append",
|
2020-07-03 15:14:02 +02:00
|
|
|
default=[],
|
2020-11-03 10:13:02 +01:00
|
|
|
choices=["2020-resolver", "fast-deps", "in-tree-build"],
|
2021-02-20 16:13:27 +01:00
|
|
|
help="Enable new functionality, that may be backward incompatible.",
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2020-07-03 15:14:02 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
use_deprecated_feature: Callable[..., Option] = partial(
|
2020-07-03 15:14:02 +02:00
|
|
|
Option,
|
2021-02-20 16:13:27 +01:00
|
|
|
"--use-deprecated",
|
|
|
|
dest="deprecated_features_enabled",
|
|
|
|
metavar="feature",
|
|
|
|
action="append",
|
2020-07-03 15:14:02 +02:00
|
|
|
default=[],
|
2021-02-20 16:13:27 +01:00
|
|
|
choices=["legacy-resolver"],
|
|
|
|
help=("Enable deprecated functionality, that will be removed in the future."),
|
2021-07-23 05:39:53 +02:00
|
|
|
)
|
2020-03-11 10:16:11 +01:00
|
|
|
|
|
|
|
|
2012-12-18 06:35:09 +01:00
|
|
|
##########
|
|
|
|
# groups #
|
|
|
|
##########
|
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
general_group: Dict[str, Any] = {
|
2021-02-20 16:13:27 +01:00
|
|
|
"name": "General Options",
|
|
|
|
"options": [
|
2013-09-17 07:21:15 +02:00
|
|
|
help_,
|
2014-11-24 03:07:53 +01:00
|
|
|
isolated_mode,
|
2013-09-17 07:21:15 +02:00
|
|
|
require_virtualenv,
|
|
|
|
verbose,
|
|
|
|
version,
|
|
|
|
quiet,
|
|
|
|
log,
|
|
|
|
no_input,
|
|
|
|
proxy,
|
2014-01-09 10:07:51 +01:00
|
|
|
retries,
|
2013-09-17 07:21:15 +02:00
|
|
|
timeout,
|
|
|
|
exists_action,
|
2014-12-21 00:03:33 +01:00
|
|
|
trusted_host,
|
2013-09-17 07:21:15 +02:00
|
|
|
cert,
|
2014-03-07 13:41:15 +01:00
|
|
|
client_cert,
|
2014-04-24 13:29:57 +02:00
|
|
|
cache_dir,
|
|
|
|
no_cache,
|
2014-09-18 13:36:40 +02:00
|
|
|
disable_pip_version_check,
|
2017-11-05 10:53:57 +01:00
|
|
|
no_color,
|
2019-12-15 02:59:34 +01:00
|
|
|
no_python_version_warning,
|
2020-07-03 15:14:02 +02:00
|
|
|
use_new_feature,
|
|
|
|
use_deprecated_feature,
|
2021-02-20 16:13:27 +01:00
|
|
|
],
|
2021-07-23 05:39:53 +02:00
|
|
|
}
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2021-07-23 05:39:53 +02:00
|
|
|
index_group: Dict[str, Any] = {
|
2021-02-20 16:13:27 +01:00
|
|
|
"name": "Package Index Options",
|
|
|
|
"options": [
|
2012-12-18 06:35:09 +01:00
|
|
|
index_url,
|
|
|
|
extra_index_url,
|
|
|
|
no_index,
|
2013-01-18 22:25:15 +01:00
|
|
|
find_links,
|
2021-02-20 16:13:27 +01:00
|
|
|
],
|
2021-07-23 05:39:53 +02:00
|
|
|
}
|