2
shared options and groups
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.
10
from __future__ import absolute_import
12
from functools import partial
13
from optparse import OptionGroup, SUPPRESS_HELP, Option
16
from pip.index import (
17
FormatControl, fmt_ctl_handle_mutual_exclude, fmt_ctl_no_binary,
19
from pip.models import PyPI
20
from pip.locations import USER_CACHE_DIR, src_prefix
21
from pip.utils.hashes import STRONG_HASHES
24
def make_option_group(group, parser):
26
Return an OptionGroup object
27
group -- assumed to be dict with 'name' and 'options' keys
28
parser -- an optparse Parser
30
option_group = OptionGroup(parser, group['name'])
31
for option in group['options']:
32
option_group.add_option(option())
36
def resolve_wheel_no_use_binary(options):
37
if not options.use_wheel:
38
control = options.format_control
39
fmt_ctl_no_use_wheel(control)
42
def check_install_build_global(options, check_options=None):
43
"""Disable wheels if per-setup.py call options are set.
45
:param options: The OptionParser options to update.
46
:param check_options: The options to check, if not supplied defaults to
49
if check_options is None:
50
check_options = options
53
return getattr(check_options, n, None)
54
names = ["build_options", "global_options", "install_options"]
55
if any(map(getname, names)):
56
control = options.format_control
57
fmt_ctl_no_binary(control)
59
'Disabling all use of wheels due to the use of --build-options '
60
'/ --global-options / --install-options.', stacklevel=2)
74
isolated_mode = partial(
81
"Run pip in an isolated mode, ignoring environment variables and user "
86
require_virtualenv = partial(
88
# Run only if inside a virtualenv, bail if not.
89
'--require-virtualenv', '--require-venv',
101
help='Give more output. Option is additive, and can be used up to 3 times.'
109
help='Show version and exit.')
117
help=('Give less output. Option is additive, and can be used up to 3'
118
' times (corresponding to WARNING, ERROR, and CRITICAL logging'
124
"--log", "--log-file", "--local-log",
127
help="Path to a verbose appending log."
132
# Don't ask for input
145
help="Specify a proxy in the form [user:passwd@]proxy.server:port.")
153
help="Maximum number of retries each connection should attempt "
154
"(default %default times).")
158
'--timeout', '--default-timeout',
163
help='Set the socket timeout (default %default seconds).')
165
default_vcs = partial(
167
# The default version control system for editables, e.g. 'svn'
174
skip_requirements_regex = partial(
176
# A regex to be used to skip requirements
177
'--skip-requirements-regex',
178
dest='skip_requirements_regex',
186
# Option when path already exist
188
dest='exists_action',
190
choices=['s', 'i', 'w', 'b', 'a'],
194
help="Default action when a path already exists: "
195
"(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.")
204
help="Path to alternate CA bundle.")
206
client_cert = partial(
213
help="Path to SSL client certificate, a single file containing the "
214
"private key and the certificate in PEM format.")
218
'-i', '--index-url', '--pypi-url',
221
default=PyPI.simple_url,
222
help="Base URL of Python Package Index (default %default). "
223
"This should point to a repository compliant with PEP 503 "
224
"(the simple repository API) or a local directory laid out "
225
"in the same format.")
228
def extra_index_url():
231
dest='extra_index_urls',
235
help="Extra URLs of package indexes to use in addition to "
236
"--index-url. Should follow the same rules as "
247
help='Ignore package index (only looking at --find-links URLs instead).')
252
'-f', '--find-links',
257
help="If a url or path to an html file, then parse for links to "
258
"archives. If a local path or file:// url that's a directory, "
259
"then look for archives in the directory listing.")
262
def allow_external():
265
dest="allow_external",
273
allow_all_external = partial(
275
"--allow-all-external",
276
dest="allow_all_external",
286
dest="trusted_hosts",
290
help="Mark this host as trusted, even though it does not have valid "
296
no_allow_external = partial(
298
"--no-allow-external",
299
dest="allow_all_external",
300
action="store_false",
306
# Remove --allow-insecure after 7.0
309
"--allow-unverified", "--allow-insecure",
310
dest="allow_unverified",
318
no_allow_unsafe = partial(
320
"--no-allow-insecure",
321
dest="allow_all_insecure",
322
action="store_false",
328
process_dependency_links = partial(
330
"--process-dependency-links",
331
dest="process_dependency_links",
334
help="Enable the processing of dependency links.",
340
'-c', '--constraint',
345
help='Constrain versions using the given constraints file. '
346
'This option can be used multiple times.')
351
'-r', '--requirement',
356
help='Install from the given requirements file. '
357
'This option can be used multiple times.')
367
help=('Install a project in editable mode (i.e. setuptools '
368
'"develop mode") from a local project path or a VCS url.'),
373
'--src', '--source', '--source-dir', '--source-directory',
377
help='Directory to check out editable projects into. '
378
'The default in a virtualenv is "<venv path>/src". '
379
'The default for global installs is "<current dir>/src".'
382
# XXX: deprecated, remove in 9.0
392
# XXX: deprecated, remove in 9.0
393
no_use_wheel = partial(
397
action='store_false',
399
help=('Do not Find and prefer wheel archives when searching indexes and '
400
'find-links locations. DEPRECATED in favour of --no-binary.'),
404
def _get_format_control(values, option):
405
"""Get a format_control object."""
406
return getattr(values, option.dest)
409
def _handle_no_binary(option, opt_str, value, parser):
410
existing = getattr(parser.values, option.dest)
411
fmt_ctl_handle_mutual_exclude(
412
value, existing.no_binary, existing.only_binary)
415
def _handle_only_binary(option, opt_str, value, parser):
416
existing = getattr(parser.values, option.dest)
417
fmt_ctl_handle_mutual_exclude(
418
value, existing.only_binary, existing.no_binary)
423
"--no-binary", dest="format_control", action="callback",
424
callback=_handle_no_binary, type="str",
425
default=FormatControl(set(), set()),
426
help="Do not use binary packages. Can be supplied multiple times, and "
427
"each time adds to the existing value. Accepts either :all: to "
428
"disable all binary packages, :none: to empty the set, or one or "
429
"more package names with commas between them. Note that some "
430
"packages are tricky to compile and may fail to install when "
431
"this option is used on them.")
436
"--only-binary", dest="format_control", action="callback",
437
callback=_handle_only_binary, type="str",
438
default=FormatControl(set(), set()),
439
help="Do not use source packages. Can be supplied multiple times, and "
440
"each time adds to the existing value. Accepts either :all: to "
441
"disable all source packages, :none: to empty the set, or one or "
442
"more package names with commas between them. Packages without "
443
"binary distributions will fail to install when this option is "
451
default=USER_CACHE_DIR,
453
help="Store the cache data in <dir>."
460
action="store_false",
461
help="Disable the cache.",
466
'--no-deps', '--no-dependencies',
467
dest='ignore_dependencies',
470
help="Don't install package dependencies.")
474
'-b', '--build', '--build-dir', '--build-directory',
477
help='Directory to unpack packages into and build in.'
480
ignore_requires_python = partial(
482
'--ignore-requires-python',
483
dest='ignore_requires_python',
485
help='Ignore the Requires-Python information.')
487
install_options = partial(
490
dest='install_options',
493
help="Extra arguments to be supplied to the setup.py install "
494
"command (use like --install-option=\"--install-scripts=/usr/local/"
495
"bin\"). Use multiple --install-option options to pass multiple "
496
"options to setup.py install. If you are using an option with a "
497
"directory path, be sure to use absolute path.")
499
global_options = partial(
502
dest='global_options',
505
help="Extra global options to be supplied to the setup.py "
506
"call before the install command.")
513
help="Don't clean up build directories.")
520
help="Include pre-release and development versions. By default, "
521
"pip only finds stable versions.")
523
disable_pip_version_check = partial(
525
"--disable-pip-version-check",
526
dest="disable_pip_version_check",
529
help="Don't periodically check PyPI to determine whether a new version "
530
"of pip is available for download. Implied with --no-index.")
532
# Deprecated, Remove later
533
always_unzip = partial(
535
'-Z', '--always-unzip',
542
def _merge_hash(option, opt_str, value, parser):
543
"""Given a value spelled "algo:digest", append the digest to a list
544
pointed to in a dict by the algo name."""
545
if not parser.values.hashes:
546
parser.values.hashes = {}
548
algo, digest = value.split(':', 1)
550
parser.error('Arguments to %s must be a hash name '
551
'followed by a value, like --hash=sha256:abcde...' %
553
if algo not in STRONG_HASHES:
554
parser.error('Allowed hash algorithms for %s are %s.' %
555
(opt_str, ', '.join(STRONG_HASHES)))
556
parser.values.hashes.setdefault(algo, []).append(digest)
562
# Hash values eventually end up in InstallRequirement.hashes due to
563
# __dict__ copying in process_line().
566
callback=_merge_hash,
568
help="Verify that the package's archive matches this "
569
'hash before installing. Example: --hash=sha256:abcdef...')
572
require_hashes = partial(
575
dest='require_hashes',
578
help='Require a hash to check each requirement against, for '
579
'repeatable installs. This option is implied when any package in a '
580
'requirements file has a --hash option.')
588
'name': 'General Options',
602
skip_requirements_regex,
609
disable_pip_version_check,
613
non_deprecated_index_group = {
614
'name': 'Package Index Options',
620
process_dependency_links,
625
'name': 'Package Index Options (including deprecated options)',
626
'options': non_deprecated_index_group['options'] + [