diff --git a/news/9891612D-8317-4A33-B373-9AAAD1CDA4DA.trivial b/news/9891612D-8317-4A33-B373-9AAAD1CDA4DA.trivial new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index 3033cd4b5e6..7a2fcbff6b2 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -22,10 +22,13 @@ from pip._internal.utils.ui import BAR_TYPES if MYPY_CHECK_RUNNING: - from typing import Any # noqa: F401 + 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 def make_option_group(group, parser): + # type: (Dict[str, Any], ConfigOptionParser) -> OptionGroup """ Return an OptionGroup object group -- assumed to be dict with 'name' and 'options' keys @@ -38,6 +41,7 @@ def make_option_group(group, parser): def check_install_build_global(options, check_options=None): + # type: (Values, Optional[Values]) -> None """Disable wheels if per-setup.py call options are set. :param options: The OptionParser options to update. @@ -60,6 +64,7 @@ def getname(n): def check_dist_restriction(options, check_target=False): + # type: (Values, bool) -> None """Function for determining if custom platform options are allowed. :param options: The OptionParser options. @@ -108,7 +113,7 @@ def check_dist_restriction(options, check_target=False): dest='help', action='help', help='Show help.', -) # type: Any +) # type: partial[Option] isolated_mode = partial( Option, @@ -120,7 +125,7 @@ def check_dist_restriction(options, check_target=False): "Run pip in an isolated mode, ignoring environment variables and user " "configuration." ), -) +) # type: partial[Option] require_virtualenv = partial( Option, @@ -130,7 +135,7 @@ def check_dist_restriction(options, check_target=False): action='store_true', default=False, help=SUPPRESS_HELP -) # type: Any +) # type: partial[Option] verbose = partial( Option, @@ -139,7 +144,7 @@ def check_dist_restriction(options, check_target=False): action='count', default=0, help='Give more output. Option is additive, and can be used up to 3 times.' -) +) # type: partial[Option] no_color = partial( Option, @@ -148,7 +153,7 @@ def check_dist_restriction(options, check_target=False): action='store_true', default=False, help="Suppress colored output", -) +) # type: partial[Option] version = partial( Option, @@ -156,7 +161,7 @@ def check_dist_restriction(options, check_target=False): dest='version', action='store_true', help='Show version and exit.', -) # type: Any +) # type: partial[Option] quiet = partial( Option, @@ -169,7 +174,7 @@ def check_dist_restriction(options, check_target=False): ' times (corresponding to WARNING, ERROR, and CRITICAL logging' ' levels).' ), -) # type: Any +) # type: partial[Option] progress_bar = partial( Option, @@ -182,7 +187,7 @@ def check_dist_restriction(options, check_target=False): 'Specify type of progress to be displayed [' + '|'.join(BAR_TYPES.keys()) + '] (default: %default)' ), -) # type: Any +) # type: partial[Option] log = partial( Option, @@ -190,7 +195,7 @@ def check_dist_restriction(options, check_target=False): dest="log", metavar="path", help="Path to a verbose appending log." -) # type: Any +) # type: partial[Option] no_input = partial( Option, @@ -200,7 +205,7 @@ def check_dist_restriction(options, check_target=False): action='store_true', default=False, help=SUPPRESS_HELP -) # type: Any +) # type: partial[Option] proxy = partial( Option, @@ -209,7 +214,7 @@ def check_dist_restriction(options, check_target=False): type='str', default='', help="Specify a proxy in the form [user:passwd@]proxy.server:port." -) # type: Any +) # type: partial[Option] retries = partial( Option, @@ -219,7 +224,7 @@ def check_dist_restriction(options, check_target=False): default=5, help="Maximum number of retries each connection should attempt " "(default %default times).", -) # type: Any +) # type: partial[Option] timeout = partial( Option, @@ -229,7 +234,7 @@ def check_dist_restriction(options, check_target=False): type='float', default=15, help='Set the socket timeout (default %default seconds).', -) # type: Any +) # type: partial[Option] skip_requirements_regex = partial( Option, @@ -239,10 +244,11 @@ def check_dist_restriction(options, check_target=False): type='str', default='', help=SUPPRESS_HELP, -) # type: Any +) # type: partial[Option] def exists_action(): + # type: () -> Option return Option( # Option when path already exist '--exists-action', @@ -264,7 +270,7 @@ def exists_action(): type='str', metavar='path', help="Path to alternate CA bundle.", -) # type: Any +) # type: partial[Option] client_cert = partial( Option, @@ -275,7 +281,7 @@ def exists_action(): metavar='path', help="Path to SSL client certificate, a single file containing the " "private key and the certificate in PEM format.", -) # type: Any +) # type: partial[Option] index_url = partial( Option, @@ -287,7 +293,7 @@ def exists_action(): "This should point to a repository compliant with PEP 503 " "(the simple repository API) or a local directory laid out " "in the same format.", -) # type: Any +) # type: partial[Option] def extra_index_url(): @@ -310,10 +316,11 @@ def extra_index_url(): action='store_true', default=False, help='Ignore package index (only looking at --find-links URLs instead).', -) # type: Any +) # type: partial[Option] def find_links(): + # type: () -> Option return Option( '-f', '--find-links', dest='find_links', @@ -327,6 +334,7 @@ def find_links(): def trusted_host(): + # type: () -> Option return Option( "--trusted-host", dest="trusted_hosts", @@ -346,10 +354,11 @@ def trusted_host(): action="store_true", default=False, help="Enable the processing of dependency links.", -) # type: Any +) # type: partial[Option] def constraints(): + # type: () -> Option return Option( '-c', '--constraint', dest='constraints', @@ -362,6 +371,7 @@ def constraints(): def requirements(): + # type: () -> Option return Option( '-r', '--requirement', dest='requirements', @@ -374,6 +384,7 @@ def requirements(): def editable(): + # type: () -> Option return Option( '-e', '--editable', dest='editables', @@ -394,15 +405,17 @@ def editable(): help='Directory to check out editable projects into. ' 'The default in a virtualenv is "/src". ' 'The default for global installs is "/src".' -) # type: Any +) # type: partial[Option] def _get_format_control(values, option): + # type: (Values, Option) -> Any """Get a format_control object.""" return getattr(values, option.dest) def _handle_no_binary(option, opt_str, value, parser): + # type: (Option, str, str, OptionParser) -> None existing = _get_format_control(parser.values, option) FormatControl.handle_mutual_excludes( value, existing.no_binary, existing.only_binary, @@ -410,6 +423,7 @@ def _handle_no_binary(option, opt_str, value, parser): def _handle_only_binary(option, opt_str, value, parser): + # type: (Option, str, str, OptionParser) -> None existing = _get_format_control(parser.values, option) FormatControl.handle_mutual_excludes( value, existing.only_binary, existing.no_binary, @@ -417,6 +431,7 @@ def _handle_only_binary(option, opt_str, value, parser): def no_binary(): + # type: () -> Option format_control = FormatControl(set(), set()) return Option( "--no-binary", dest="format_control", action="callback", @@ -432,6 +447,7 @@ def no_binary(): def only_binary(): + # type: () -> Option format_control = FormatControl(set(), set()) return Option( "--only-binary", dest="format_control", action="callback", @@ -454,7 +470,7 @@ def only_binary(): default=None, help=("Only use wheels compatible with . " "Defaults to the platform of the running system."), -) +) # type: partial[Option] python_version = partial( @@ -469,7 +485,7 @@ def only_binary(): "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."), -) +) # type: partial[Option] implementation = partial( @@ -483,7 +499,7 @@ def only_binary(): " or 'ip'. If not specified, then the current " "interpreter implementation is used. Use 'py' to force " "implementation-agnostic wheels."), -) +) # type: partial[Option] abi = partial( @@ -498,10 +514,11 @@ def only_binary(): "you will need to specify --implementation, " "--platform, and --python-version when using " "this option."), -) +) # type: partial[Option] def prefer_binary(): + # type: () -> Option return Option( "--prefer-binary", dest="prefer_binary", @@ -518,7 +535,7 @@ def prefer_binary(): default=USER_CACHE_DIR, metavar="dir", help="Store the cache data in ." -) +) # type: partial[Option] no_cache = partial( Option, @@ -526,7 +543,7 @@ def prefer_binary(): dest="cache_dir", action="store_false", help="Disable the cache.", -) +) # type: partial[Option] no_deps = partial( Option, @@ -535,7 +552,7 @@ def prefer_binary(): action='store_true', default=False, help="Don't install package dependencies.", -) # type: Any +) # type: partial[Option] build_dir = partial( Option, @@ -547,7 +564,7 @@ def prefer_binary(): 'The location of temporary directories can be controlled by setting ' 'the TMPDIR environment variable (TEMP on Windows) appropriately. ' 'When passed, build directories are not cleaned in case of failures.' -) # type: Any +) # type: partial[Option] ignore_requires_python = partial( Option, @@ -555,7 +572,7 @@ def prefer_binary(): dest='ignore_requires_python', action='store_true', help='Ignore the Requires-Python information.' -) # type: Any +) # type: partial[Option] no_build_isolation = partial( Option, @@ -566,7 +583,7 @@ def prefer_binary(): help='Disable isolation when building a modern source distribution. ' 'Build dependencies specified by PEP 518 must be already installed ' 'if this option is used.' -) # type: Any +) # type: partial[Option] install_options = partial( Option, @@ -579,7 +596,7 @@ def prefer_binary(): "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.", -) # type: Any +) # type: partial[Option] global_options = partial( Option, @@ -589,7 +606,7 @@ def prefer_binary(): metavar='options', help="Extra global options to be supplied to the setup.py " "call before the install command.", -) # type: Any +) # type: partial[Option] no_clean = partial( Option, @@ -597,7 +614,7 @@ def prefer_binary(): action='store_true', default=False, help="Don't clean up build directories." -) # type: Any +) # type: partial[Option] pre = partial( Option, @@ -606,7 +623,7 @@ def prefer_binary(): default=False, help="Include pre-release and development versions. By default, " "pip only finds stable versions.", -) # type: Any +) # type: partial[Option] disable_pip_version_check = partial( Option, @@ -616,7 +633,7 @@ def prefer_binary(): default=False, help="Don't periodically check PyPI to determine whether a new version " "of pip is available for download. Implied with --no-index.", -) # type: Any +) # type: partial[Option] # Deprecated, Remove later @@ -626,10 +643,11 @@ def prefer_binary(): dest='always_unzip', action='store_true', help=SUPPRESS_HELP, -) # type: Any +) # type: partial[Option] def _merge_hash(option, opt_str, value, parser): + # type: (Option, str, str, OptionParser) -> None """Given a value spelled "algo:digest", append the digest to a list pointed to in a dict by the algo name.""" if not parser.values.hashes: @@ -657,7 +675,7 @@ def _merge_hash(option, opt_str, value, parser): type='string', help="Verify that the package's archive matches this " 'hash before installing. Example: --hash=sha256:abcdef...', -) # type: Any +) # type: partial[Option] require_hashes = partial( @@ -669,7 +687,7 @@ def _merge_hash(option, opt_str, value, parser): 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.', -) # type: Any +) # type: partial[Option] ########## @@ -700,7 +718,7 @@ def _merge_hash(option, opt_str, value, parser): disable_pip_version_check, no_color, ] -} +} # type: Dict[str, Any] index_group = { 'name': 'Package Index Options', @@ -711,4 +729,4 @@ def _merge_hash(option, opt_str, value, parser): find_links, process_dependency_links, ] -} +} # type: Dict[str, Any] diff --git a/src/pip/_internal/models/format_control.py b/src/pip/_internal/models/format_control.py index 27488563669..126519827cc 100644 --- a/src/pip/_internal/models/format_control.py +++ b/src/pip/_internal/models/format_control.py @@ -1,5 +1,10 @@ from pip._vendor.packaging.utils import canonicalize_name +from pip._internal.utils.typing import MYPY_CHECK_RUNNING + +if MYPY_CHECK_RUNNING: + from typing import Optional, Set # noqa: F401 + class FormatControl(object): """A helper class for controlling formats from which packages are installed. @@ -9,6 +14,7 @@ class FormatControl(object): are listed, with any given package only showing up in one field at a time. """ def __init__(self, no_binary=None, only_binary=None): + # type: (Optional[Set], Optional[Set]) -> None self.no_binary = set() if no_binary is None else no_binary self.only_binary = set() if only_binary is None else only_binary @@ -27,6 +33,7 @@ def __repr__(self): @staticmethod def handle_mutual_excludes(value, target, other): + # type: (str, Optional[Set], Optional[Set]) -> None new = value.split(',') while ':all:' in new: other.clear()