shared options and groups
The principle here is to define options once, but *not* instantiate them
globally. One reason being that options with action='append' can carry state
between parses. pip parses general options twice internally, and shouldn't
pass on state. To be consistent, all options will follow this design.
from __future__ import absolute_import
from functools import partial
from optparse import OptionGroup, SUPPRESS_HELP, Option
FormatControl, fmt_ctl_handle_mutual_exclude, fmt_ctl_no_binary,
from pip.models import PyPI
from pip.locations import USER_CACHE_DIR, src_prefix
from pip.utils.hashes import STRONG_HASHES
def make_option_group(group, parser):
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']:
option_group.add_option(option())
def resolve_wheel_no_use_binary(options):
if not options.use_wheel:
control = options.format_control
fmt_ctl_no_use_wheel(control)
def check_install_build_global(options, check_options=None):
"""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
if check_options is None:
return getattr(check_options, n, None)
names = ["build_options", "global_options", "install_options"]
if any(map(getname, names)):
control = options.format_control
fmt_ctl_no_binary(control)
'Disabling all use of wheels due to the use of --build-options '
'/ --global-options / --install-options.', stacklevel=2)
"Run pip in an isolated mode, ignoring environment variables and user "
require_virtualenv = partial(
# Run only if inside a virtualenv, bail if not.
'--require-virtualenv', '--require-venv',
help='Give more output. Option is additive, and can be used up to 3 times.'
help='Show version and exit.')
help=('Give less output. Option is additive, and can be used up to 3'
' times (corresponding to WARNING, ERROR, and CRITICAL logging'
"--log", "--log-file", "--local-log",
help="Path to a verbose appending log."
help="Specify a proxy in the form [user:passwd@]proxy.server:port.")
help="Maximum number of retries each connection should attempt "
"(default %default times).")
'--timeout', '--default-timeout',
help='Set the socket timeout (default %default seconds).')
# The default version control system for editables, e.g. 'svn'
skip_requirements_regex = partial(
# A regex to be used to skip requirements
'--skip-requirements-regex',
dest='skip_requirements_regex',
# Option when path already exist
choices=['s', 'i', 'w', 'b', 'a'],
help="Default action when a path already exists: "
"(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.")
help="Path to alternate CA bundle.")
help="Path to SSL client certificate, a single file containing the "
"private key and the certificate in PEM format.")
'-i', '--index-url', '--pypi-url',
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 "
help="Extra URLs of package indexes to use in addition to "
"--index-url. Should follow the same rules as "
help='Ignore package index (only looking at --find-links URLs instead).')
help="If a url or path to an html file, then parse for links to "
"archives. If a local path or file:// url that's a directory, "
"then look for archives in the directory listing.")
allow_all_external = partial(
dest="allow_all_external",
help="Mark this host as trusted, even though it does not have valid "
no_allow_external = partial(
dest="allow_all_external",
# Remove --allow-insecure after 7.0
"--allow-unverified", "--allow-insecure",
no_allow_unsafe = partial(
dest="allow_all_insecure",
process_dependency_links = partial(
"--process-dependency-links",
dest="process_dependency_links",
help="Enable the processing of dependency links.",
help='Constrain versions using the given constraints file. '
'This option can be used multiple times.')
help='Install from the given requirements file. '
'This option can be used multiple times.')
help=('Install a project in editable mode (i.e. setuptools '
'"develop mode") from a local project path or a VCS url.'),
'--src', '--source', '--source-dir', '--source-directory',
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".'
# XXX: deprecated, remove in 9.0
# XXX: deprecated, remove in 9.0
help=('Do not Find and prefer wheel archives when searching indexes and '
'find-links locations. DEPRECATED in favour of --no-binary.'),
def _get_format_control(values, option):
"""Get a format_control object."""
return getattr(values, option.dest)
def _handle_no_binary(option, opt_str, value, parser):
existing = getattr(parser.values, option.dest)
fmt_ctl_handle_mutual_exclude(
value, existing.no_binary, existing.only_binary)
def _handle_only_binary(option, opt_str, value, parser):
existing = getattr(parser.values, option.dest)
fmt_ctl_handle_mutual_exclude(
value, existing.only_binary, existing.no_binary)
"--no-binary", dest="format_control", action="callback",
callback=_handle_no_binary, type="str",
default=FormatControl(set(), set()),
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 "
"this option is used on them.")
"--only-binary", dest="format_control", action="callback",
callback=_handle_only_binary, type="str",
default=FormatControl(set(), set()),
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 "
help="Store the cache data in <dir>."
help="Disable the cache.",
'--no-deps', '--no-dependencies',
dest='ignore_dependencies',
help="Don't install package dependencies.")
'-b', '--build', '--build-dir', '--build-directory',
help='Directory to unpack packages into and build in.'
ignore_requires_python = partial(
'--ignore-requires-python',
dest='ignore_requires_python',
help='Ignore the Requires-Python information.')
install_options = partial(
help="Extra arguments to be supplied to the setup.py install "
"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.")
global_options = partial(