You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmdoptions.py 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. """
  2. shared options and groups
  3. The principle here is to define options once, but *not* instantiate them
  4. globally. One reason being that options with action='append' can carry state
  5. between parses. pip parses general options twice internally, and shouldn't
  6. pass on state. To be consistent, all options will follow this design.
  7. """
  8. from __future__ import absolute_import
  9. import textwrap
  10. import warnings
  11. from distutils.util import strtobool
  12. from functools import partial
  13. from optparse import SUPPRESS_HELP, Option, OptionGroup
  14. from pip._internal.exceptions import CommandError
  15. from pip._internal.locations import USER_CACHE_DIR, src_prefix
  16. from pip._internal.models.format_control import FormatControl
  17. from pip._internal.models.index import PyPI
  18. from pip._internal.utils.hashes import STRONG_HASHES
  19. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  20. from pip._internal.utils.ui import BAR_TYPES
  21. if MYPY_CHECK_RUNNING:
  22. from typing import Any, Callable, Dict, List, Optional, Union # noqa: F401
  23. from optparse import OptionParser, Values # noqa: F401
  24. from pip._internal.cli.parser import ConfigOptionParser # noqa: F401
  25. def raise_option_error(parser, option, msg):
  26. """
  27. Raise an option parsing error using parser.error().
  28. Args:
  29. parser: an OptionParser instance.
  30. option: an Option instance.
  31. msg: the error text.
  32. """
  33. msg = '{} error: {}'.format(option, msg)
  34. msg = textwrap.fill(' '.join(msg.split()))
  35. parser.error(msg)
  36. def make_option_group(group, parser):
  37. # type: (Dict[str, Any], ConfigOptionParser) -> OptionGroup
  38. """
  39. Return an OptionGroup object
  40. group -- assumed to be dict with 'name' and 'options' keys
  41. parser -- an optparse Parser
  42. """
  43. option_group = OptionGroup(parser, group['name'])
  44. for option in group['options']:
  45. option_group.add_option(option())
  46. return option_group
  47. def check_install_build_global(options, check_options=None):
  48. # type: (Values, Optional[Values]) -> None
  49. """Disable wheels if per-setup.py call options are set.
  50. :param options: The OptionParser options to update.
  51. :param check_options: The options to check, if not supplied defaults to
  52. options.
  53. """
  54. if check_options is None:
  55. check_options = options
  56. def getname(n):
  57. return getattr(check_options, n, None)
  58. names = ["build_options", "global_options", "install_options"]
  59. if any(map(getname, names)):
  60. control = options.format_control
  61. control.disallow_binaries()
  62. warnings.warn(
  63. 'Disabling all use of wheels due to the use of --build-options '
  64. '/ --global-options / --install-options.', stacklevel=2,
  65. )
  66. def check_dist_restriction(options, check_target=False):
  67. # type: (Values, bool) -> None
  68. """Function for determining if custom platform options are allowed.
  69. :param options: The OptionParser options.
  70. :param check_target: Whether or not to check if --target is being used.
  71. """
  72. dist_restriction_set = any([
  73. options.python_version,
  74. options.platform,
  75. options.abi,
  76. options.implementation,
  77. ])
  78. binary_only = FormatControl(set(), {':all:'})
  79. sdist_dependencies_allowed = (
  80. options.format_control != binary_only and
  81. not options.ignore_dependencies
  82. )
  83. # Installations or downloads using dist restrictions must not combine
  84. # source distributions and dist-specific wheels, as they are not
  85. # gauranteed to be locally compatible.
  86. if dist_restriction_set and sdist_dependencies_allowed:
  87. raise CommandError(
  88. "When restricting platform and interpreter constraints using "
  89. "--python-version, --platform, --abi, or --implementation, "
  90. "either --no-deps must be set, or --only-binary=:all: must be "
  91. "set and --no-binary must not be set (or must be set to "
  92. ":none:)."
  93. )
  94. if check_target:
  95. if dist_restriction_set and not options.target_dir:
  96. raise CommandError(
  97. "Can not use any platform or abi specific options unless "
  98. "installing via '--target'"
  99. )
  100. ###########
  101. # options #
  102. ###########
  103. help_ = partial(
  104. Option,
  105. '-h', '--help',
  106. dest='help',
  107. action='help',
  108. help='Show help.',
  109. ) # type: Callable[..., Option]
  110. isolated_mode = partial(
  111. Option,
  112. "--isolated",
  113. dest="isolated_mode",
  114. action="store_true",
  115. default=False,
  116. help=(
  117. "Run pip in an isolated mode, ignoring environment variables and user "
  118. "configuration."
  119. ),
  120. ) # type: Callable[..., Option]
  121. require_virtualenv = partial(
  122. Option,
  123. # Run only if inside a virtualenv, bail if not.
  124. '--require-virtualenv', '--require-venv',
  125. dest='require_venv',
  126. action='store_true',
  127. default=False,
  128. help=SUPPRESS_HELP
  129. ) # type: Callable[..., Option]
  130. verbose = partial(
  131. Option,
  132. '-v', '--verbose',
  133. dest='verbose',
  134. action='count',
  135. default=0,
  136. help='Give more output. Option is additive, and can be used up to 3 times.'
  137. ) # type: Callable[..., Option]
  138. no_color = partial(
  139. Option,
  140. '--no-color',
  141. dest='no_color',
  142. action='store_true',
  143. default=False,
  144. help="Suppress colored output",
  145. ) # type: Callable[..., Option]
  146. version = partial(
  147. Option,
  148. '-V', '--version',
  149. dest='version',
  150. action='store_true',
  151. help='Show version and exit.',
  152. ) # type: Callable[..., Option]
  153. quiet = partial(
  154. Option,
  155. '-q', '--quiet',
  156. dest='quiet',
  157. action='count',
  158. default=0,
  159. help=(
  160. 'Give less output. Option is additive, and can be used up to 3'
  161. ' times (corresponding to WARNING, ERROR, and CRITICAL logging'
  162. ' levels).'
  163. ),
  164. ) # type: Callable[..., Option]
  165. progress_bar = partial(
  166. Option,
  167. '--progress-bar',
  168. dest='progress_bar',
  169. type='choice',
  170. choices=list(BAR_TYPES.keys()),
  171. default='on',
  172. help=(
  173. 'Specify type of progress to be displayed [' +
  174. '|'.join(BAR_TYPES.keys()) + '] (default: %default)'
  175. ),
  176. ) # type: Callable[..., Option]
  177. log = partial(
  178. Option,
  179. "--log", "--log-file", "--local-log",
  180. dest="log",
  181. metavar="path",
  182. help="Path to a verbose appending log."
  183. ) # type: Callable[..., Option]
  184. no_input = partial(
  185. Option,
  186. # Don't ask for input
  187. '--no-input',
  188. dest='no_input',
  189. action='store_true',
  190. default=False,
  191. help=SUPPRESS_HELP
  192. ) # type: Callable[..., Option]
  193. proxy = partial(
  194. Option,
  195. '--proxy',
  196. dest='proxy',
  197. type='str',
  198. default='',
  199. help="Specify a proxy in the form [user:passwd@]proxy.server:port."
  200. ) # type: Callable[..., Option]
  201. retries = partial(
  202. Option,
  203. '--retries',
  204. dest='retries',
  205. type='int',
  206. default=5,
  207. help="Maximum number of retries each connection should attempt "
  208. "(default %default times).",
  209. ) # type: Callable[..., Option]
  210. timeout = partial(
  211. Option,
  212. '--timeout', '--default-timeout',
  213. metavar='sec',
  214. dest='timeout',
  215. type='float',
  216. default=15,
  217. help='Set the socket timeout (default %default seconds).',
  218. ) # type: Callable[..., Option]
  219. skip_requirements_regex = partial(
  220. Option,
  221. # A regex to be used to skip requirements
  222. '--skip-requirements-regex',
  223. dest='skip_requirements_regex',
  224. type='str',
  225. default='',
  226. help=SUPPRESS_HELP,
  227. ) # type: Callable[..., Option]
  228. def exists_action():
  229. # type: () -> Option
  230. return Option(
  231. # Option when path already exist
  232. '--exists-action',
  233. dest='exists_action',
  234. type='choice',
  235. choices=['s', 'i', 'w', 'b', 'a'],
  236. default=[],
  237. action='append',
  238. metavar='action',
  239. help="Default action when a path already exists: "
  240. "(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort).",
  241. )
  242. cert = partial(
  243. Option,
  244. '--cert',
  245. dest='cert',
  246. type='str',
  247. metavar='path',
  248. help="Path to alternate CA bundle.",
  249. ) # type: Callable[..., Option]
  250. client_cert = partial(
  251. Option,
  252. '--client-cert',
  253. dest='client_cert',
  254. type='str',
  255. default=None,
  256. metavar='path',
  257. help="Path to SSL client certificate, a single file containing the "
  258. "private key and the certificate in PEM format.",
  259. ) # type: Callable[..., Option]
  260. index_url = partial(
  261. Option,
  262. '-i', '--index-url', '--pypi-url',
  263. dest='index_url',
  264. metavar='URL',
  265. default=PyPI.simple_url,
  266. help="Base URL of Python Package Index (default %default). "
  267. "This should point to a repository compliant with PEP 503 "
  268. "(the simple repository API) or a local directory laid out "
  269. "in the same format.",
  270. ) # type: Callable[..., Option]
  271. def extra_index_url():
  272. return Option(
  273. '--extra-index-url',
  274. dest='extra_index_urls',
  275. metavar='URL',
  276. action='append',
  277. default=[],
  278. help="Extra URLs of package indexes to use in addition to "
  279. "--index-url. Should follow the same rules as "
  280. "--index-url.",
  281. )
  282. no_index = partial(
  283. Option,
  284. '--no-index',
  285. dest='no_index',
  286. action='store_true',
  287. default=False,
  288. help='Ignore package index (only looking at --find-links URLs instead).',
  289. ) # type: Callable[..., Option]
  290. def find_links():
  291. # type: () -> Option
  292. return Option(
  293. '-f', '--find-links',
  294. dest='find_links',
  295. action='append',
  296. default=[],
  297. metavar='url',
  298. help="If a url or path to an html file, then parse for links to "
  299. "archives. If a local path or file:// url that's a directory, "
  300. "then look for archives in the directory listing.",
  301. )
  302. def trusted_host():
  303. # type: () -> Option
  304. return Option(
  305. "--trusted-host",
  306. dest="trusted_hosts",
  307. action="append",
  308. metavar="HOSTNAME",
  309. default=[],
  310. help="Mark this host as trusted, even though it does not have valid "
  311. "or any HTTPS.",
  312. )
  313. def constraints():
  314. # type: () -> Option
  315. return Option(
  316. '-c', '--constraint',
  317. dest='constraints',
  318. action='append',
  319. default=[],
  320. metavar='file',
  321. help='Constrain versions using the given constraints file. '
  322. 'This option can be used multiple times.'
  323. )
  324. def requirements():
  325. # type: () -> Option
  326. return Option(
  327. '-r', '--requirement',
  328. dest='requirements',
  329. action='append',
  330. default=[],
  331. metavar='file',
  332. help='Install from the given requirements file. '
  333. 'This option can be used multiple times.'
  334. )
  335. def editable():
  336. # type: () -> Option
  337. return Option(
  338. '-e', '--editable',
  339. dest='editables',
  340. action='append',
  341. default=[],
  342. metavar='path/url',
  343. help=('Install a project in editable mode (i.e. setuptools '
  344. '"develop mode") from a local project path or a VCS url.'),
  345. )
  346. src = partial(
  347. Option,
  348. '--src', '--source', '--source-dir', '--source-directory',
  349. dest='src_dir',
  350. metavar='dir',
  351. default=src_prefix,
  352. help='Directory to check out editable projects into. '
  353. 'The default in a virtualenv is "<venv path>/src". '
  354. 'The default for global installs is "<current dir>/src".'
  355. ) # type: Callable[..., Option]
  356. def _get_format_control(values, option):
  357. # type: (Values, Option) -> Any
  358. """Get a format_control object."""
  359. return getattr(values, option.dest)
  360. def _handle_no_binary(option, opt_str, value, parser):
  361. # type: (Option, str, str, OptionParser) -> None
  362. existing = _get_format_control(parser.values, option)
  363. FormatControl.handle_mutual_excludes(
  364. value, existing.no_binary, existing.only_binary,
  365. )
  366. def _handle_only_binary(option, opt_str, value, parser):
  367. # type: (Option, str, str, OptionParser) -> None
  368. existing = _get_format_control(parser.values, option)
  369. FormatControl.handle_mutual_excludes(
  370. value, existing.only_binary, existing.no_binary,
  371. )
  372. def no_binary():
  373. # type: () -> Option
  374. format_control = FormatControl(set(), set())
  375. return Option(
  376. "--no-binary", dest="format_control", action="callback",
  377. callback=_handle_no_binary, type="str",
  378. default=format_control,
  379. help="Do not use binary packages. Can be supplied multiple times, and "
  380. "each time adds to the existing value. Accepts either :all: to "
  381. "disable all binary packages, :none: to empty the set, or one or "
  382. "more package names with commas between them. Note that some "
  383. "packages are tricky to compile and may fail to install when "
  384. "this option is used on them.",
  385. )
  386. def only_binary():
  387. # type: () -> Option
  388. format_control = FormatControl(set(), set())
  389. return Option(
  390. "--only-binary", dest="format_control", action="callback",
  391. callback=_handle_only_binary, type="str",
  392. default=format_control,
  393. help="Do not use source packages. Can be supplied multiple times, and "
  394. "each time adds to the existing value. Accepts either :all: to "
  395. "disable all source packages, :none: to empty the set, or one or "
  396. "more package names with commas between them. Packages without "
  397. "binary distributions will fail to install when this option is "
  398. "used on them.",
  399. )
  400. platform = partial(
  401. Option,
  402. '--platform',
  403. dest='platform',
  404. metavar='platform',
  405. default=None,
  406. help=("Only use wheels compatible with <platform>. "
  407. "Defaults to the platform of the running system."),
  408. ) # type: Callable[..., Option]
  409. python_version = partial(
  410. Option,
  411. '--python-version',
  412. dest='python_version',
  413. metavar='python_version',
  414. default=None,
  415. help=("Only use wheels compatible with Python "
  416. "interpreter version <version>. If not specified, then the "
  417. "current system interpreter minor version is used. A major "
  418. "version (e.g. '2') can be specified to match all "
  419. "minor revs of that major version. A minor version "
  420. "(e.g. '34') can also be specified."),
  421. ) # type: Callable[..., Option]
  422. implementation = partial(
  423. Option,
  424. '--implementation',
  425. dest='implementation',
  426. metavar='implementation',
  427. default=None,
  428. help=("Only use wheels compatible with Python "
  429. "implementation <implementation>, e.g. 'pp', 'jy', 'cp', "
  430. " or 'ip'. If not specified, then the current "
  431. "interpreter implementation is used. Use 'py' to force "
  432. "implementation-agnostic wheels."),
  433. ) # type: Callable[..., Option]
  434. abi = partial(
  435. Option,
  436. '--abi',
  437. dest='abi',
  438. metavar='abi',
  439. default=None,
  440. help=("Only use wheels compatible with Python "
  441. "abi <abi>, e.g. 'pypy_41'. If not specified, then the "
  442. "current interpreter abi tag is used. Generally "
  443. "you will need to specify --implementation, "
  444. "--platform, and --python-version when using "
  445. "this option."),
  446. ) # type: Callable[..., Option]
  447. def prefer_binary():
  448. # type: () -> Option
  449. return Option(
  450. "--prefer-binary",
  451. dest="prefer_binary",
  452. action="store_true",
  453. default=False,
  454. help="Prefer older binary packages over newer source packages."
  455. )
  456. cache_dir = partial(
  457. Option,
  458. "--cache-dir",
  459. dest="cache_dir",
  460. default=USER_CACHE_DIR,
  461. metavar="dir",
  462. help="Store the cache data in <dir>."
  463. ) # type: Callable[..., Option]
  464. def no_cache_dir_callback(option, opt, value, parser):
  465. """
  466. Process a value provided for the --no-cache-dir option.
  467. This is an optparse.Option callback for the --no-cache-dir option.
  468. """
  469. # The value argument will be None if --no-cache-dir is passed via the
  470. # command-line, since the option doesn't accept arguments. However,
  471. # the value can be non-None if the option is triggered e.g. by an
  472. # environment variable, like PIP_NO_CACHE_DIR=true.
  473. if value is not None:
  474. # Then parse the string value to get argument error-checking.
  475. try:
  476. strtobool(value)
  477. except ValueError as exc:
  478. raise_option_error(parser, option=option, msg=str(exc))
  479. # Originally, setting PIP_NO_CACHE_DIR to a value that strtobool()
  480. # converted to 0 (like "false" or "no") caused cache_dir to be disabled
  481. # rather than enabled (logic would say the latter). Thus, we disable
  482. # the cache directory not just on values that parse to True, but (for
  483. # backwards compatibility reasons) also on values that parse to False.
  484. # In other words, always set it to False if the option is provided in
  485. # some (valid) form.
  486. parser.values.cache_dir = False
  487. no_cache = partial(
  488. Option,
  489. "--no-cache-dir",
  490. dest="cache_dir",
  491. action="callback",
  492. callback=no_cache_dir_callback,
  493. help="Disable the cache.",
  494. ) # type: Callable[..., Option]
  495. no_deps = partial(
  496. Option,
  497. '--no-deps', '--no-dependencies',
  498. dest='ignore_dependencies',
  499. action='store_true',
  500. default=False,
  501. help="Don't install package dependencies.",
  502. ) # type: Callable[..., Option]
  503. build_dir = partial(
  504. Option,
  505. '-b', '--build', '--build-dir', '--build-directory',
  506. dest='build_dir',
  507. metavar='dir',
  508. help='Directory to unpack packages into and build in. Note that '
  509. 'an initial build still takes place in a temporary directory. '
  510. 'The location of temporary directories can be controlled by setting '
  511. 'the TMPDIR environment variable (TEMP on Windows) appropriately. '
  512. 'When passed, build directories are not cleaned in case of failures.'
  513. ) # type: Callable[..., Option]
  514. ignore_requires_python = partial(
  515. Option,
  516. '--ignore-requires-python',
  517. dest='ignore_requires_python',
  518. action='store_true',
  519. help='Ignore the Requires-Python information.'
  520. ) # type: Callable[..., Option]
  521. no_build_isolation = partial(
  522. Option,
  523. '--no-build-isolation',
  524. dest='build_isolation',
  525. action='store_false',
  526. default=True,
  527. help='Disable isolation when building a modern source distribution. '
  528. 'Build dependencies specified by PEP 518 must be already installed '
  529. 'if this option is used.'
  530. ) # type: Callable[..., Option]
  531. def no_use_pep517_callback(option, opt, value, parser):
  532. """
  533. Process a value provided for the --no-use-pep517 option.
  534. This is an optparse.Option callback for the no_use_pep517 option.
  535. """
  536. # Since --no-use-pep517 doesn't accept arguments, the value argument
  537. # will be None if --no-use-pep517 is passed via the command-line.
  538. # However, the value can be non-None if the option is triggered e.g.
  539. # by an environment variable, for example "PIP_NO_USE_PEP517=true".
  540. if value is not None:
  541. msg = """A value was passed for --no-use-pep517,
  542. probably using either the PIP_NO_USE_PEP517 environment variable
  543. or the "no-use-pep517" config file option. Use an appropriate value
  544. of the PIP_USE_PEP517 environment variable or the "use-pep517"
  545. config file option instead.
  546. """
  547. raise_option_error(parser, option=option, msg=msg)
  548. # Otherwise, --no-use-pep517 was passed via the command-line.
  549. parser.values.use_pep517 = False
  550. use_pep517 = partial(
  551. Option,
  552. '--use-pep517',
  553. dest='use_pep517',
  554. action='store_true',
  555. default=None,
  556. help='Use PEP 517 for building source distributions '
  557. '(use --no-use-pep517 to force legacy behaviour).'
  558. ) # type: Any
  559. no_use_pep517 = partial(
  560. Option,
  561. '--no-use-pep517',
  562. dest='use_pep517',
  563. action='callback',
  564. callback=no_use_pep517_callback,
  565. default=None,
  566. help=SUPPRESS_HELP
  567. ) # type: Any
  568. install_options = partial(
  569. Option,
  570. '--install-option',
  571. dest='install_options',
  572. action='append',
  573. metavar='options',
  574. help="Extra arguments to be supplied to the setup.py install "
  575. "command (use like --install-option=\"--install-scripts=/usr/local/"
  576. "bin\"). Use multiple --install-option options to pass multiple "
  577. "options to setup.py install. If you are using an option with a "
  578. "directory path, be sure to use absolute path.",
  579. ) # type: Callable[..., Option]
  580. global_options = partial(
  581. Option,
  582. '--global-option',
  583. dest='global_options',
  584. action='append',
  585. metavar='options',
  586. help="Extra global options to be supplied to the setup.py "
  587. "call before the install command.",
  588. ) # type: Callable[..., Option]
  589. no_clean = partial(
  590. Option,
  591. '--no-clean',
  592. action='store_true',
  593. default=False,
  594. help="Don't clean up build directories."
  595. ) # type: Callable[..., Option]
  596. pre = partial(
  597. Option,
  598. '--pre',
  599. action='store_true',
  600. default=False,
  601. help="Include pre-release and development versions. By default, "
  602. "pip only finds stable versions.",
  603. ) # type: Callable[..., Option]
  604. disable_pip_version_check = partial(
  605. Option,
  606. "--disable-pip-version-check",
  607. dest="disable_pip_version_check",
  608. action="store_true",
  609. default=False,
  610. help="Don't periodically check PyPI to determine whether a new version "
  611. "of pip is available for download. Implied with --no-index.",
  612. ) # type: Callable[..., Option]
  613. # Deprecated, Remove later
  614. always_unzip = partial(
  615. Option,
  616. '-Z', '--always-unzip',
  617. dest='always_unzip',
  618. action='store_true',
  619. help=SUPPRESS_HELP,
  620. ) # type: Callable[..., Option]
  621. def _merge_hash(option, opt_str, value, parser):
  622. # type: (Option, str, str, OptionParser) -> None
  623. """Given a value spelled "algo:digest", append the digest to a list
  624. pointed to in a dict by the algo name."""
  625. if not parser.values.hashes:
  626. parser.values.hashes = {} # type: ignore
  627. try:
  628. algo, digest = value.split(':', 1)
  629. except ValueError:
  630. parser.error('Arguments to %s must be a hash name '
  631. 'followed by a value, like --hash=sha256:abcde...' %
  632. opt_str)
  633. if algo not in STRONG_HASHES:
  634. parser.error('Allowed hash algorithms for %s are %s.' %
  635. (opt_str, ', '.join(STRONG_HASHES)))
  636. parser.values.hashes.setdefault(algo, []).append(digest)
  637. hash = partial(
  638. Option,
  639. '--hash',
  640. # Hash values eventually end up in InstallRequirement.hashes due to
  641. # __dict__ copying in process_line().
  642. dest='hashes',
  643. action='callback',
  644. callback=_merge_hash,
  645. type='string',
  646. help="Verify that the package's archive matches this "
  647. 'hash before installing. Example: --hash=sha256:abcdef...',
  648. ) # type: Callable[..., Option]
  649. require_hashes = partial(
  650. Option,
  651. '--require-hashes',
  652. dest='require_hashes',
  653. action='store_true',
  654. default=False,
  655. help='Require a hash to check each requirement against, for '
  656. 'repeatable installs. This option is implied when any package in a '
  657. 'requirements file has a --hash option.',
  658. ) # type: Callable[..., Option]
  659. ##########
  660. # groups #
  661. ##########
  662. general_group = {
  663. 'name': 'General Options',
  664. 'options': [
  665. help_,
  666. isolated_mode,
  667. require_virtualenv,
  668. verbose,
  669. version,
  670. quiet,
  671. log,
  672. no_input,
  673. proxy,
  674. retries,
  675. timeout,
  676. skip_requirements_regex,
  677. exists_action,
  678. trusted_host,
  679. cert,
  680. client_cert,
  681. cache_dir,
  682. no_cache,
  683. disable_pip_version_check,
  684. no_color,
  685. ]
  686. } # type: Dict[str, Any]
  687. index_group = {
  688. 'name': 'Package Index Options',
  689. 'options': [
  690. index_url,
  691. extra_index_url,
  692. no_index,
  693. find_links,
  694. ]
  695. } # type: Dict[str, Any]