Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate --path parsing into cmdoptions.py #6600

Merged
merged 1 commit into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,24 @@ def _handle_merge_hash(option, opt_str, value, parser):
) # type: Callable[..., Option]


list_path = partial(
Option,
'--path',
dest='path',
action='append',
help='Restrict to the specified installation path for listing '
'packages (can be used multiple times).'
) # type: Callable[..., Option]


def check_list_path_option(options):
# type: (Values) -> None
if options.path and (options.user or options.local):
raise CommandError(
"Cannot combine '--path' with '--user' or '--local'"
)


##########
# groups #
##########
Expand Down
14 changes: 3 additions & 11 deletions src/pip/_internal/commands/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import sys

from pip._internal.cache import WheelCache
from pip._internal.cli import cmdoptions
from pip._internal.cli.base_command import Command
from pip._internal.exceptions import CommandError
from pip._internal.models.format_control import FormatControl
from pip._internal.operations.freeze import freeze
from pip._internal.utils.compat import stdlib_pkgs
Expand Down Expand Up @@ -57,12 +57,7 @@ def __init__(self, *args, **kw):
action='store_true',
default=False,
help='Only output packages installed in user-site.')
self.cmd_opts.add_option(
'--path',
dest='path',
action='append',
help='Restrict to the specified installation path for listing '
'packages (can be used multiple times).')
self.cmd_opts.add_option(cmdoptions.list_path())
self.cmd_opts.add_option(
'--all',
dest='freeze_all',
Expand All @@ -84,10 +79,7 @@ def run(self, options, args):
if not options.freeze_all:
skip.update(DEV_PKGS)

if options.path and (options.user or options.local):
raise CommandError(
"Cannot combine '--path' with '--user' or '--local'"
)
cmdoptions.check_list_path_option(options)

freeze_kwargs = dict(
requirement=options.requirements,
Expand Down
12 changes: 2 additions & 10 deletions src/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,7 @@ def __init__(self, *args, **kw):
action='store_true',
default=False,
help='Only output packages installed in user-site.')
self.cmd_opts.add_option(
'--path',
dest='path',
action='append',
help='Restrict to the specified installation path for listing '
'packages (can be used multiple times).')
cmd_opts.add_option(cmdoptions.list_path())
cmd_opts.add_option(
'--pre',
action='store_true',
Expand Down Expand Up @@ -131,10 +126,7 @@ def run(self, options, args):
raise CommandError(
"Options --outdated and --uptodate cannot be combined.")

if options.path and (options.user or options.local):
raise CommandError(
"Cannot combine '--path' with '--user' or '--local'"
)
cmdoptions.check_list_path_option(options)

packages = get_installed_distributions(
local_only=options.local,
Expand Down