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
|
|
|
|
|
|
|
"""
|
2014-08-31 01:52:28 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2015-04-22 01:53:05 +02:00
|
|
|
import warnings
|
2018-10-14 10:27:21 +02:00
|
|
|
from distutils.util import strtobool
|
2017-05-16 12:16:30 +02:00
|
|
|
from functools import partial
|
|
|
|
from optparse import SUPPRESS_HELP, Option, OptionGroup
|
2015-04-17 05:03:34 +02:00
|
|
|
|
2018-07-24 17:09:32 +02:00
|
|
|
from pip._internal.exceptions import CommandError
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.locations import USER_CACHE_DIR, 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
|
2017-08-31 17:48:18 +02:00
|
|
|
from pip._internal.utils.hashes import STRONG_HASHES
|
2017-09-02 13:22:19 +02:00
|
|
|
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
2017-09-02 13:32:48 +02:00
|
|
|
from pip._internal.utils.ui import BAR_TYPES
|
2017-09-02 13:22:19 +02:00
|
|
|
|
|
|
|
if MYPY_CHECK_RUNNING:
|
2018-10-28 17:42:15 +01:00
|
|
|
from typing import Any, Callable, Dict, List, Optional, Union # noqa: F401
|
|
|
|
from optparse import OptionParser, Values # noqa: F401
|
|
|
|
from pip._internal.cli.parser import ConfigOptionParser # noqa: F401
|
2012-12-18 06:35:09 +01:00
|
|
|
|
2013-02-16 19:02:41 +01:00
|
|
|
|
2012-12-18 06:35:09 +01:00
|
|
|
def make_option_group(group, parser):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (Dict[str, Any], 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
|
|
|
|
"""
|
|
|
|
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
|
|
|
|
2015-04-22 01:53:05 +02:00
|
|
|
def check_install_build_global(options, check_options=None):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (Values, Optional[Values]) -> 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
|
|
|
|
|
|
|
|
def getname(n):
|
|
|
|
return getattr(check_options, n, None)
|
|
|
|
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(
|
|
|
|
'Disabling all use of wheels due to the use of --build-options '
|
2017-12-25 10:53:27 +01:00
|
|
|
'/ --global-options / --install-options.', stacklevel=2,
|
|
|
|
)
|
2015-04-22 01:53:05 +02:00
|
|
|
|
|
|
|
|
2018-07-24 17:09:32 +02:00
|
|
|
def check_dist_restriction(options, check_target=False):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (Values, bool) -> 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.
|
|
|
|
"""
|
|
|
|
dist_restriction_set = any([
|
|
|
|
options.python_version,
|
|
|
|
options.platform,
|
|
|
|
options.abi,
|
|
|
|
options.implementation,
|
|
|
|
])
|
|
|
|
|
|
|
|
binary_only = FormatControl(set(), {':all:'})
|
|
|
|
sdist_dependencies_allowed = (
|
|
|
|
options.format_control != binary_only and
|
|
|
|
not options.ignore_dependencies
|
|
|
|
)
|
|
|
|
|
|
|
|
# Installations or downloads using dist restrictions must not combine
|
|
|
|
# source distributions and dist-specific wheels, as they are not
|
|
|
|
# gauranteed to be locally compatible.
|
|
|
|
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'"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2012-12-18 06:35:09 +01:00
|
|
|
###########
|
|
|
|
# options #
|
|
|
|
###########
|
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
help_ = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
'-h', '--help',
|
|
|
|
dest='help',
|
|
|
|
action='help',
|
2017-09-02 13:22:19 +02:00
|
|
|
help='Show help.',
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
isolated_mode = partial(
|
|
|
|
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."
|
|
|
|
),
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2014-11-24 03:07:53 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
require_virtualenv = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
# Run only if inside a virtualenv, bail if not.
|
|
|
|
'--require-virtualenv', '--require-venv',
|
|
|
|
dest='require_venv',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2017-09-02 13:22:19 +02:00
|
|
|
help=SUPPRESS_HELP
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
verbose = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
'-v', '--verbose',
|
|
|
|
dest='verbose',
|
|
|
|
action='count',
|
|
|
|
default=0,
|
2014-01-27 15:07:10 +01:00
|
|
|
help='Give more output. Option is additive, and can be used up to 3 times.'
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2017-11-05 10:53:57 +01:00
|
|
|
no_color = partial(
|
|
|
|
Option,
|
|
|
|
'--no-color',
|
|
|
|
dest='no_color',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Suppress colored output",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2017-11-05 10:53:57 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
version = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
'-V', '--version',
|
|
|
|
dest='version',
|
|
|
|
action='store_true',
|
2017-09-02 13:22:19 +02:00
|
|
|
help='Show version and exit.',
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
quiet = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
'-q', '--quiet',
|
|
|
|
dest='quiet',
|
|
|
|
action='count',
|
|
|
|
default=0,
|
2017-09-02 13:22:19 +02:00
|
|
|
help=(
|
|
|
|
'Give less output. Option is additive, and can be used up to 3'
|
|
|
|
' times (corresponding to WARNING, ERROR, and CRITICAL logging'
|
|
|
|
' levels).'
|
|
|
|
),
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2016-12-22 15:59:55 +01:00
|
|
|
progress_bar = partial(
|
|
|
|
Option,
|
|
|
|
'--progress-bar',
|
|
|
|
dest='progress_bar',
|
|
|
|
type='choice',
|
|
|
|
choices=list(BAR_TYPES.keys()),
|
|
|
|
default='on',
|
2017-09-02 13:22:19 +02:00
|
|
|
help=(
|
|
|
|
'Specify type of progress to be displayed [' +
|
|
|
|
'|'.join(BAR_TYPES.keys()) + '] (default: %default)'
|
|
|
|
),
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2016-12-22 15:59:55 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
log = partial(
|
|
|
|
Option,
|
2014-08-31 01:52:28 +02:00
|
|
|
"--log", "--log-file", "--local-log",
|
|
|
|
dest="log",
|
|
|
|
metavar="path",
|
|
|
|
help="Path to a verbose appending log."
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
no_input = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
# Don't ask for input
|
|
|
|
'--no-input',
|
|
|
|
dest='no_input',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2017-09-02 13:22:19 +02:00
|
|
|
help=SUPPRESS_HELP
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
proxy = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
'--proxy',
|
|
|
|
dest='proxy',
|
|
|
|
type='str',
|
|
|
|
default='',
|
2017-09-02 13:22:19 +02:00
|
|
|
help="Specify a proxy in the form [user:passwd@]proxy.server:port."
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
retries = partial(
|
|
|
|
Option,
|
2014-01-09 10:07:51 +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 "
|
2017-09-02 13:22:19 +02:00
|
|
|
"(default %default times).",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2014-01-09 10:07:51 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
timeout = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
'--timeout', '--default-timeout',
|
|
|
|
metavar='sec',
|
|
|
|
dest='timeout',
|
|
|
|
type='float',
|
|
|
|
default=15,
|
2017-09-02 13:22:19 +02:00
|
|
|
help='Set the socket timeout (default %default seconds).',
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
skip_requirements_regex = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
# A regex to be used to skip requirements
|
|
|
|
'--skip-requirements-regex',
|
|
|
|
dest='skip_requirements_regex',
|
|
|
|
type='str',
|
|
|
|
default='',
|
2017-09-02 13:22:19 +02:00
|
|
|
help=SUPPRESS_HELP,
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
def exists_action():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2015-04-17 04:41:36 +02:00
|
|
|
return Option(
|
|
|
|
# Option when path already exist
|
|
|
|
'--exists-action',
|
|
|
|
dest='exists_action',
|
|
|
|
type='choice',
|
2016-08-30 04:21:31 +02:00
|
|
|
choices=['s', 'i', 'w', 'b', 'a'],
|
2015-04-17 04:41:36 +02:00
|
|
|
default=[],
|
|
|
|
action='append',
|
|
|
|
metavar='action',
|
|
|
|
help="Default action when a path already exists: "
|
2017-09-02 13:22:19 +02:00
|
|
|
"(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).",
|
|
|
|
)
|
2015-04-17 04:41:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
cert = partial(
|
|
|
|
Option,
|
2013-09-17 07:21:15 +02:00
|
|
|
'--cert',
|
|
|
|
dest='cert',
|
|
|
|
type='str',
|
|
|
|
metavar='path',
|
2017-09-02 13:22:19 +02:00
|
|
|
help="Path to alternate CA bundle.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
client_cert = partial(
|
|
|
|
Option,
|
2014-03-07 13:41:15 +01:00
|
|
|
'--client-cert',
|
|
|
|
dest='client_cert',
|
|
|
|
type='str',
|
|
|
|
default=None,
|
|
|
|
metavar='path',
|
|
|
|
help="Path to SSL client certificate, a single file containing the "
|
2017-09-02 13:22:19 +02:00
|
|
|
"private key and the certificate in PEM format.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2014-03-07 13:41:15 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
index_url = partial(
|
|
|
|
Option,
|
2012-12-18 06:35:09 +01:00
|
|
|
'-i', '--index-url', '--pypi-url',
|
|
|
|
dest='index_url',
|
|
|
|
metavar='URL',
|
2014-12-16 07:04:00 +01:00
|
|
|
default=PyPI.simple_url,
|
2016-05-20 22:19:30 +02:00
|
|
|
help="Base URL of Python Package Index (default %default). "
|
|
|
|
"This should point to a repository compliant with PEP 503 "
|
|
|
|
"(the simple repository API) or a local directory laid out "
|
2017-09-02 13:22:19 +02:00
|
|
|
"in the same format.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2012-12-18 06:35:09 +01:00
|
|
|
|
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
def extra_index_url():
|
|
|
|
return Option(
|
|
|
|
'--extra-index-url',
|
|
|
|
dest='extra_index_urls',
|
|
|
|
metavar='URL',
|
|
|
|
action='append',
|
|
|
|
default=[],
|
2016-05-20 22:19:30 +02:00
|
|
|
help="Extra URLs of package indexes to use in addition to "
|
|
|
|
"--index-url. Should follow the same rules as "
|
2017-09-02 13:22:19 +02:00
|
|
|
"--index-url.",
|
2015-04-17 04:41:36 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
no_index = partial(
|
|
|
|
Option,
|
2012-12-18 06:35:09 +01:00
|
|
|
'--no-index',
|
|
|
|
dest='no_index',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2017-09-02 13:22:19 +02:00
|
|
|
help='Ignore package index (only looking at --find-links URLs instead).',
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-01-18 22:25:15 +01:00
|
|
|
|
2013-06-07 15:48:34 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
def find_links():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2015-04-17 04:41:36 +02:00
|
|
|
return Option(
|
|
|
|
'-f', '--find-links',
|
|
|
|
dest='find_links',
|
|
|
|
action='append',
|
|
|
|
default=[],
|
|
|
|
metavar='url',
|
|
|
|
help="If a url or path to an html file, then parse for links to "
|
2016-03-14 21:20:17 +01:00
|
|
|
"archives. If a local path or file:// url that's a directory, "
|
2017-09-02 13:22:19 +02:00
|
|
|
"then look for archives in the directory listing.",
|
|
|
|
)
|
2015-04-17 04:41:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
def trusted_host():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2015-04-17 04:41:36 +02:00
|
|
|
return Option(
|
|
|
|
"--trusted-host",
|
|
|
|
dest="trusted_hosts",
|
|
|
|
action="append",
|
|
|
|
metavar="HOSTNAME",
|
|
|
|
default=[],
|
|
|
|
help="Mark this host as trusted, even though it does not have valid "
|
|
|
|
"or any HTTPS.",
|
|
|
|
)
|
|
|
|
|
2014-12-10 01:40:05 +01:00
|
|
|
|
2015-06-02 05:39:10 +02:00
|
|
|
def constraints():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2015-06-02 05:39:10 +02:00
|
|
|
return Option(
|
|
|
|
'-c', '--constraint',
|
|
|
|
dest='constraints',
|
|
|
|
action='append',
|
|
|
|
default=[],
|
|
|
|
metavar='file',
|
|
|
|
help='Constrain versions using the given constraints file. '
|
2017-09-02 13:22:19 +02:00
|
|
|
'This option can be used multiple times.'
|
|
|
|
)
|
2015-06-02 05:39:10 +02:00
|
|
|
|
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
def requirements():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2015-04-17 04:41:36 +02:00
|
|
|
return Option(
|
|
|
|
'-r', '--requirement',
|
|
|
|
dest='requirements',
|
|
|
|
action='append',
|
|
|
|
default=[],
|
|
|
|
metavar='file',
|
|
|
|
help='Install from the given requirements file. '
|
2017-09-02 13:22:19 +02:00
|
|
|
'This option can be used multiple times.'
|
|
|
|
)
|
2015-04-17 04:41:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
def editable():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2015-04-17 04:41:36 +02:00
|
|
|
return Option(
|
|
|
|
'-e', '--editable',
|
|
|
|
dest='editables',
|
|
|
|
action='append',
|
|
|
|
default=[],
|
|
|
|
metavar='path/url',
|
|
|
|
help=('Install a project in editable mode (i.e. setuptools '
|
|
|
|
'"develop mode") from a local project path or a VCS url.'),
|
|
|
|
)
|
|
|
|
|
2017-03-20 01:49:09 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
src = partial(
|
|
|
|
Option,
|
2014-05-09 06:29:01 +02:00
|
|
|
'--src', '--source', '--source-dir', '--source-directory',
|
|
|
|
dest='src_dir',
|
|
|
|
metavar='dir',
|
|
|
|
default=src_prefix,
|
|
|
|
help='Directory to check out editable projects into. '
|
|
|
|
'The default in a virtualenv is "<venv path>/src". '
|
|
|
|
'The default for global installs is "<current dir>/src".'
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2014-05-09 06:29:01 +02:00
|
|
|
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
def _get_format_control(values, option):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (Values, Option) -> Any
|
2015-04-17 05:03:34 +02:00
|
|
|
"""Get a format_control object."""
|
|
|
|
return getattr(values, option.dest)
|
|
|
|
|
|
|
|
|
|
|
|
def _handle_no_binary(option, opt_str, value, parser):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (Option, str, str, 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(
|
2017-12-25 10:53:27 +01:00
|
|
|
value, existing.no_binary, existing.only_binary,
|
|
|
|
)
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _handle_only_binary(option, opt_str, value, parser):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (Option, str, str, 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(
|
2017-12-25 10:53:27 +01:00
|
|
|
value, existing.only_binary, existing.no_binary,
|
|
|
|
)
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def no_binary():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2018-08-04 21:07:13 +02:00
|
|
|
format_control = FormatControl(set(), set())
|
2015-04-17 05:03:34 +02:00
|
|
|
return Option(
|
|
|
|
"--no-binary", dest="format_control", action="callback",
|
|
|
|
callback=_handle_no_binary, type="str",
|
2018-08-04 21:07:13 +02:00
|
|
|
default=format_control,
|
2015-04-17 05:03:34 +02: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, or one or "
|
|
|
|
"more package names with commas between them. Note that some "
|
|
|
|
"packages are tricky to compile and may fail to install when "
|
2017-09-02 13:22:19 +02:00
|
|
|
"this option is used on them.",
|
|
|
|
)
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
def only_binary():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2018-08-04 21:07:13 +02:00
|
|
|
format_control = FormatControl(set(), set())
|
2015-04-17 05:03:34 +02:00
|
|
|
return Option(
|
|
|
|
"--only-binary", dest="format_control", action="callback",
|
|
|
|
callback=_handle_only_binary, type="str",
|
2018-08-04 21:07:13 +02:00
|
|
|
default=format_control,
|
2015-04-17 05:03:34 +02: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 "
|
2017-09-02 13:22:19 +02:00
|
|
|
"used on them.",
|
|
|
|
)
|
2015-04-17 05:03:34 +02:00
|
|
|
|
|
|
|
|
2018-07-24 17:09:32 +02:00
|
|
|
platform = partial(
|
|
|
|
Option,
|
|
|
|
'--platform',
|
|
|
|
dest='platform',
|
|
|
|
metavar='platform',
|
|
|
|
default=None,
|
|
|
|
help=("Only use wheels compatible with <platform>. "
|
|
|
|
"Defaults to the platform of the running system."),
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2018-07-24 17:09:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
python_version = partial(
|
|
|
|
Option,
|
|
|
|
'--python-version',
|
|
|
|
dest='python_version',
|
|
|
|
metavar='python_version',
|
|
|
|
default=None,
|
|
|
|
help=("Only use wheels compatible with Python "
|
|
|
|
"interpreter version <version>. If not specified, then the "
|
|
|
|
"current system interpreter minor version is used. A major "
|
|
|
|
"version (e.g. '2') can be specified to match all "
|
|
|
|
"minor revs of that major version. A minor version "
|
|
|
|
"(e.g. '34') can also be specified."),
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2018-07-24 17:09:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
implementation = partial(
|
|
|
|
Option,
|
|
|
|
'--implementation',
|
|
|
|
dest='implementation',
|
|
|
|
metavar='implementation',
|
|
|
|
default=None,
|
|
|
|
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."),
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2018-07-24 17:09:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
abi = partial(
|
|
|
|
Option,
|
|
|
|
'--abi',
|
|
|
|
dest='abi',
|
|
|
|
metavar='abi',
|
|
|
|
default=None,
|
|
|
|
help=("Only use wheels compatible with Python "
|
|
|
|
"abi <abi>, e.g. 'pypy_41'. If not specified, then the "
|
|
|
|
"current interpreter abi tag is used. Generally "
|
|
|
|
"you will need to specify --implementation, "
|
|
|
|
"--platform, and --python-version when using "
|
|
|
|
"this option."),
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2018-07-24 17:09:32 +02:00
|
|
|
|
|
|
|
|
2018-05-11 07:47:32 +02:00
|
|
|
def prefer_binary():
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: () -> Option
|
2018-05-11 07:47:32 +02:00
|
|
|
return Option(
|
|
|
|
"--prefer-binary",
|
|
|
|
dest="prefer_binary",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Prefer older binary packages over newer source packages."
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
cache_dir = partial(
|
|
|
|
Option,
|
2014-04-24 13:29:57 +02:00
|
|
|
"--cache-dir",
|
|
|
|
dest="cache_dir",
|
|
|
|
default=USER_CACHE_DIR,
|
|
|
|
metavar="dir",
|
|
|
|
help="Store the cache data in <dir>."
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2014-04-24 13:29:57 +02:00
|
|
|
|
2018-10-14 10:27:21 +02:00
|
|
|
|
|
|
|
def no_cache_dir_callback(option, opt, value, parser):
|
|
|
|
"""
|
|
|
|
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.
|
|
|
|
strtobool(value)
|
|
|
|
|
|
|
|
# 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
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
no_cache = partial(
|
|
|
|
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",
|
|
|
|
callback=no_cache_dir_callback,
|
2014-04-24 13:29:57 +02:00
|
|
|
help="Disable the cache.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2014-04-24 13:29:57 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
no_deps = partial(
|
|
|
|
Option,
|
2013-02-03 07:40:30 +01:00
|
|
|
'--no-deps', '--no-dependencies',
|
|
|
|
dest='ignore_dependencies',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2018-01-28 14:53:27 +01:00
|
|
|
help="Don't install package dependencies.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-02-03 07:40:30 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
build_dir = partial(
|
|
|
|
Option,
|
2013-02-03 07:40:30 +01:00
|
|
|
'-b', '--build', '--build-dir', '--build-directory',
|
|
|
|
dest='build_dir',
|
|
|
|
metavar='dir',
|
2018-01-01 19:16:50 +01:00
|
|
|
help='Directory to unpack packages into and build in. Note that '
|
|
|
|
'an initial build still takes place in a temporary directory. '
|
|
|
|
'The location of temporary directories can be controlled by setting '
|
2018-03-04 20:03:40 +01:00
|
|
|
'the TMPDIR environment variable (TEMP on Windows) appropriately. '
|
|
|
|
'When passed, build directories are not cleaned in case of failures.'
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-02-03 07:40:30 +01:00
|
|
|
|
2016-07-17 11:29:02 +02:00
|
|
|
ignore_requires_python = partial(
|
|
|
|
Option,
|
|
|
|
'--ignore-requires-python',
|
|
|
|
dest='ignore_requires_python',
|
|
|
|
action='store_true',
|
2017-09-02 13:22:19 +02:00
|
|
|
help='Ignore the Requires-Python information.'
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2016-07-17 11:29:02 +02:00
|
|
|
|
2018-03-04 12:40:09 +01:00
|
|
|
no_build_isolation = partial(
|
|
|
|
Option,
|
|
|
|
'--no-build-isolation',
|
|
|
|
dest='build_isolation',
|
|
|
|
action='store_false',
|
|
|
|
default=True,
|
|
|
|
help='Disable isolation when building a modern source distribution. '
|
|
|
|
'Build dependencies specified by PEP 518 must be already installed '
|
|
|
|
'if this option is used.'
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2018-03-04 12:40:09 +01:00
|
|
|
|
2018-10-09 16:18:00 +02:00
|
|
|
use_pep517 = partial(
|
|
|
|
Option,
|
|
|
|
'--use-pep517',
|
|
|
|
dest='use_pep517',
|
|
|
|
action='store_true',
|
|
|
|
default=None,
|
|
|
|
help='Use PEP 517 for building source distributions '
|
|
|
|
'(use --no-use-pep517 to force legacy behaviour).'
|
|
|
|
) # type: Any
|
|
|
|
|
|
|
|
no_use_pep517 = partial(
|
|
|
|
Option,
|
|
|
|
'--no-use-pep517',
|
|
|
|
dest='use_pep517',
|
|
|
|
action='store_false',
|
|
|
|
default=None,
|
|
|
|
help=SUPPRESS_HELP
|
|
|
|
) # type: Any
|
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
install_options = partial(
|
|
|
|
Option,
|
2013-02-03 07:40:30 +01:00
|
|
|
'--install-option',
|
|
|
|
dest='install_options',
|
|
|
|
action='append',
|
|
|
|
metavar='options',
|
|
|
|
help="Extra arguments to be supplied to the setup.py install "
|
2014-01-27 15:07:10 +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 "
|
2017-09-02 13:22:19 +02:00
|
|
|
"directory path, be sure to use absolute path.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-02-03 07:40:30 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
global_options = partial(
|
|
|
|
Option,
|
2013-02-03 07:40:30 +01:00
|
|
|
'--global-option',
|
|
|
|
dest='global_options',
|
|
|
|
action='append',
|
|
|
|
metavar='options',
|
|
|
|
help="Extra global options to be supplied to the setup.py "
|
2017-09-02 13:22:19 +02:00
|
|
|
"call before the install command.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-02-03 07:40:30 +01:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
no_clean = partial(
|
|
|
|
Option,
|
2013-05-25 02:11:15 +02:00
|
|
|
'--no-clean',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2018-09-02 16:43:14 +02:00
|
|
|
help="Don't clean up build directories."
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2013-05-25 02:11:15 +02:00
|
|
|
|
2015-08-03 23:07:07 +02:00
|
|
|
pre = partial(
|
|
|
|
Option,
|
|
|
|
'--pre',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help="Include pre-release and development versions. By default, "
|
2017-09-02 13:22:19 +02:00
|
|
|
"pip only finds stable versions.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2015-08-03 23:07:07 +02:00
|
|
|
|
2015-04-17 04:41:36 +02:00
|
|
|
disable_pip_version_check = partial(
|
|
|
|
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 "
|
2017-09-02 13:22:19 +02:00
|
|
|
"of pip is available for download. Implied with --no-index.",
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2012-12-18 06:35:09 +01:00
|
|
|
|
2016-12-22 15:59:55 +01:00
|
|
|
|
2015-04-17 07:10:46 +02:00
|
|
|
# Deprecated, Remove later
|
|
|
|
always_unzip = partial(
|
|
|
|
Option,
|
|
|
|
'-Z', '--always-unzip',
|
|
|
|
dest='always_unzip',
|
|
|
|
action='store_true',
|
|
|
|
help=SUPPRESS_HELP,
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2015-04-17 07:10:46 +02:00
|
|
|
|
2015-09-25 00:53:39 +02:00
|
|
|
|
2015-09-25 00:31:14 +02:00
|
|
|
def _merge_hash(option, opt_str, value, parser):
|
2018-10-28 17:42:15 +01:00
|
|
|
# type: (Option, str, str, 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:
|
2018-12-03 13:47:11 +01:00
|
|
|
parser.values.hashes = {} # type: ignore
|
2015-09-25 00:31:14 +02:00
|
|
|
try:
|
|
|
|
algo, digest = value.split(':', 1)
|
|
|
|
except ValueError:
|
|
|
|
parser.error('Arguments to %s must be a hash name '
|
|
|
|
'followed by a value, like --hash=sha256:abcde...' %
|
|
|
|
opt_str)
|
2015-10-12 22:29:08 +02:00
|
|
|
if algo not in STRONG_HASHES:
|
2015-09-25 00:31:14 +02:00
|
|
|
parser.error('Allowed hash algorithms for %s are %s.' %
|
2015-10-12 22:29:08 +02:00
|
|
|
(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
|
|
|
|
2015-09-25 00:31:14 +02:00
|
|
|
hash = partial(
|
|
|
|
Option,
|
2015-09-25 21:32:33 +02: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().
|
|
|
|
dest='hashes',
|
|
|
|
action='callback',
|
|
|
|
callback=_merge_hash,
|
|
|
|
type='string',
|
|
|
|
help="Verify that the package's archive matches this "
|
2017-09-02 13:22:19 +02:00
|
|
|
'hash before installing. Example: --hash=sha256:abcdef...',
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2015-09-03 23:37:29 +02:00
|
|
|
|
2015-04-17 07:10:46 +02:00
|
|
|
|
2015-10-07 23:33:57 +02:00
|
|
|
require_hashes = partial(
|
|
|
|
Option,
|
|
|
|
'--require-hashes',
|
|
|
|
dest='require_hashes',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Require a hash to check each requirement against, for '
|
2015-10-20 05:38:07 +02:00
|
|
|
'repeatable installs. This option is implied when any package in a '
|
2017-09-02 13:22:19 +02:00
|
|
|
'requirements file has a --hash option.',
|
2018-12-03 13:47:11 +01:00
|
|
|
) # type: Callable[..., Option]
|
2015-10-07 23:33:57 +02:00
|
|
|
|
|
|
|
|
2012-12-18 06:35:09 +01:00
|
|
|
##########
|
|
|
|
# groups #
|
|
|
|
##########
|
|
|
|
|
2013-09-17 07:21:15 +02:00
|
|
|
general_group = {
|
|
|
|
'name': 'General Options',
|
|
|
|
'options': [
|
|
|
|
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,
|
|
|
|
skip_requirements_regex,
|
|
|
|
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,
|
2014-02-24 22:52:23 +01:00
|
|
|
]
|
2018-10-28 17:42:15 +01:00
|
|
|
} # type: Dict[str, Any]
|
2013-09-17 07:21:15 +02:00
|
|
|
|
2017-03-20 01:49:09 +01:00
|
|
|
index_group = {
|
2012-12-18 06:35:09 +01:00
|
|
|
'name': 'Package Index Options',
|
|
|
|
'options': [
|
|
|
|
index_url,
|
|
|
|
extra_index_url,
|
|
|
|
no_index,
|
2013-01-18 22:25:15 +01:00
|
|
|
find_links,
|
2015-07-29 22:25:13 +02:00
|
|
|
]
|
2018-10-28 17:42:15 +01:00
|
|
|
} # type: Dict[str, Any]
|