Skip to content

Commit

Permalink
Merge pull request #6062 from mkurnikov/cli-types
Browse files Browse the repository at this point in the history
Add type annotations for pip._internal.cli
  • Loading branch information
pradyunsg authored Dec 14, 2018
2 parents ab5d0f0 + 0288485 commit 5d2d16e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
from typing import Optional, List, Union, Tuple, Any # noqa: F401
from typing import Optional, List, Tuple, Any # noqa: F401
from optparse import Values # noqa: F401
from pip._internal.cache import WheelCache # noqa: F401
from pip._internal.req.req_set import RequirementSet # noqa: F401
Expand Down
78 changes: 39 additions & 39 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def check_dist_restriction(options, check_target=False):
dest='help',
action='help',
help='Show help.',
) # type: partial[Option]
) # type: Callable[..., Option]

isolated_mode = partial(
Option,
Expand All @@ -126,7 +126,7 @@ def check_dist_restriction(options, check_target=False):
"Run pip in an isolated mode, ignoring environment variables and user "
"configuration."
),
) # type: partial[Option]
) # type: Callable[..., Option]

require_virtualenv = partial(
Option,
Expand All @@ -136,7 +136,7 @@ def check_dist_restriction(options, check_target=False):
action='store_true',
default=False,
help=SUPPRESS_HELP
) # type: partial[Option]
) # type: Callable[..., Option]

verbose = partial(
Option,
Expand All @@ -145,7 +145,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]
) # type: Callable[..., Option]

no_color = partial(
Option,
Expand All @@ -154,15 +154,15 @@ def check_dist_restriction(options, check_target=False):
action='store_true',
default=False,
help="Suppress colored output",
) # type: partial[Option]
) # type: Callable[..., Option]

version = partial(
Option,
'-V', '--version',
dest='version',
action='store_true',
help='Show version and exit.',
) # type: partial[Option]
) # type: Callable[..., Option]

quiet = partial(
Option,
Expand All @@ -175,7 +175,7 @@ def check_dist_restriction(options, check_target=False):
' times (corresponding to WARNING, ERROR, and CRITICAL logging'
' levels).'
),
) # type: partial[Option]
) # type: Callable[..., Option]

progress_bar = partial(
Option,
Expand All @@ -188,15 +188,15 @@ def check_dist_restriction(options, check_target=False):
'Specify type of progress to be displayed [' +
'|'.join(BAR_TYPES.keys()) + '] (default: %default)'
),
) # type: partial[Option]
) # type: Callable[..., Option]

log = partial(
Option,
"--log", "--log-file", "--local-log",
dest="log",
metavar="path",
help="Path to a verbose appending log."
) # type: partial[Option]
) # type: Callable[..., Option]

no_input = partial(
Option,
Expand All @@ -206,7 +206,7 @@ def check_dist_restriction(options, check_target=False):
action='store_true',
default=False,
help=SUPPRESS_HELP
) # type: partial[Option]
) # type: Callable[..., Option]

proxy = partial(
Option,
Expand All @@ -215,7 +215,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: partial[Option]
) # type: Callable[..., Option]

retries = partial(
Option,
Expand All @@ -225,7 +225,7 @@ def check_dist_restriction(options, check_target=False):
default=5,
help="Maximum number of retries each connection should attempt "
"(default %default times).",
) # type: partial[Option]
) # type: Callable[..., Option]

timeout = partial(
Option,
Expand All @@ -235,7 +235,7 @@ def check_dist_restriction(options, check_target=False):
type='float',
default=15,
help='Set the socket timeout (default %default seconds).',
) # type: partial[Option]
) # type: Callable[..., Option]

skip_requirements_regex = partial(
Option,
Expand All @@ -245,7 +245,7 @@ def check_dist_restriction(options, check_target=False):
type='str',
default='',
help=SUPPRESS_HELP,
) # type: partial[Option]
) # type: Callable[..., Option]


def exists_action():
Expand All @@ -271,7 +271,7 @@ def exists_action():
type='str',
metavar='path',
help="Path to alternate CA bundle.",
) # type: partial[Option]
) # type: Callable[..., Option]

client_cert = partial(
Option,
Expand All @@ -282,7 +282,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: partial[Option]
) # type: Callable[..., Option]

index_url = partial(
Option,
Expand All @@ -294,7 +294,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: partial[Option]
) # type: Callable[..., Option]


def extra_index_url():
Expand All @@ -317,7 +317,7 @@ def extra_index_url():
action='store_true',
default=False,
help='Ignore package index (only looking at --find-links URLs instead).',
) # type: partial[Option]
) # type: Callable[..., Option]


def find_links():
Expand Down Expand Up @@ -355,7 +355,7 @@ def trusted_host():
action="store_true",
default=False,
help="Enable the processing of dependency links.",
) # type: partial[Option]
) # type: Callable[..., Option]


def constraints():
Expand Down Expand Up @@ -406,7 +406,7 @@ def editable():
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".'
) # type: partial[Option]
) # type: Callable[..., Option]


def _get_format_control(values, option):
Expand Down Expand Up @@ -471,7 +471,7 @@ def only_binary():
default=None,
help=("Only use wheels compatible with <platform>. "
"Defaults to the platform of the running system."),
) # type: partial[Option]
) # type: Callable[..., Option]


python_version = partial(
Expand All @@ -486,7 +486,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]
) # type: Callable[..., Option]


implementation = partial(
Expand All @@ -500,7 +500,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]
) # type: Callable[..., Option]


abi = partial(
Expand All @@ -515,7 +515,7 @@ def only_binary():
"you will need to specify --implementation, "
"--platform, and --python-version when using "
"this option."),
) # type: partial[Option]
) # type: Callable[..., Option]


def prefer_binary():
Expand All @@ -536,7 +536,7 @@ def prefer_binary():
default=USER_CACHE_DIR,
metavar="dir",
help="Store the cache data in <dir>."
) # type: partial[Option]
) # type: Callable[..., Option]


def no_cache_dir_callback(option, opt, value, parser):
Expand Down Expand Up @@ -570,7 +570,7 @@ def no_cache_dir_callback(option, opt, value, parser):
action="callback",
callback=no_cache_dir_callback,
help="Disable the cache.",
) # type: partial[Option]
) # type: Callable[..., Option]

no_deps = partial(
Option,
Expand All @@ -579,7 +579,7 @@ def no_cache_dir_callback(option, opt, value, parser):
action='store_true',
default=False,
help="Don't install package dependencies.",
) # type: partial[Option]
) # type: Callable[..., Option]

build_dir = partial(
Option,
Expand All @@ -591,15 +591,15 @@ def no_cache_dir_callback(option, opt, value, parser):
'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: partial[Option]
) # type: Callable[..., Option]

ignore_requires_python = partial(
Option,
'--ignore-requires-python',
dest='ignore_requires_python',
action='store_true',
help='Ignore the Requires-Python information.'
) # type: partial[Option]
) # type: Callable[..., Option]

no_build_isolation = partial(
Option,
Expand All @@ -610,7 +610,7 @@ def no_cache_dir_callback(option, opt, value, parser):
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: partial[Option]
) # type: Callable[..., Option]

use_pep517 = partial(
Option,
Expand Down Expand Up @@ -642,7 +642,7 @@ def no_cache_dir_callback(option, opt, value, parser):
"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: partial[Option]
) # type: Callable[..., Option]

global_options = partial(
Option,
Expand All @@ -652,15 +652,15 @@ def no_cache_dir_callback(option, opt, value, parser):
metavar='options',
help="Extra global options to be supplied to the setup.py "
"call before the install command.",
) # type: partial[Option]
) # type: Callable[..., Option]

no_clean = partial(
Option,
'--no-clean',
action='store_true',
default=False,
help="Don't clean up build directories."
) # type: partial[Option]
) # type: Callable[..., Option]

pre = partial(
Option,
Expand All @@ -669,7 +669,7 @@ def no_cache_dir_callback(option, opt, value, parser):
default=False,
help="Include pre-release and development versions. By default, "
"pip only finds stable versions.",
) # type: partial[Option]
) # type: Callable[..., Option]

disable_pip_version_check = partial(
Option,
Expand All @@ -679,7 +679,7 @@ def no_cache_dir_callback(option, opt, value, parser):
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: partial[Option]
) # type: Callable[..., Option]


# Deprecated, Remove later
Expand All @@ -689,15 +689,15 @@ def no_cache_dir_callback(option, opt, value, parser):
dest='always_unzip',
action='store_true',
help=SUPPRESS_HELP,
) # type: partial[Option]
) # type: Callable[..., 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:
parser.values.hashes = {}
parser.values.hashes = {} # type: ignore
try:
algo, digest = value.split(':', 1)
except ValueError:
Expand All @@ -721,7 +721,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: partial[Option]
) # type: Callable[..., Option]


require_hashes = partial(
Expand All @@ -733,7 +733,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: partial[Option]
) # type: Callable[..., Option]


##########
Expand Down
Loading

0 comments on commit 5d2d16e

Please sign in to comment.