mirror of https://github.com/pypa/pip
Merge pull request #6600 from lkollar/consolidate-path-opt-parsing
Consolidate `--path` parsing into `cmdoptions.py`
This commit is contained in:
commit
3f8df24875
|
@ -822,6 +822,24 @@ require_hashes = partial(
|
||||||
) # type: Callable[..., Option]
|
) # 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 #
|
# groups #
|
||||||
##########
|
##########
|
||||||
|
|
|
@ -3,8 +3,8 @@ from __future__ import absolute_import
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pip._internal.cache import WheelCache
|
from pip._internal.cache import WheelCache
|
||||||
|
from pip._internal.cli import cmdoptions
|
||||||
from pip._internal.cli.base_command import Command
|
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.models.format_control import FormatControl
|
||||||
from pip._internal.operations.freeze import freeze
|
from pip._internal.operations.freeze import freeze
|
||||||
from pip._internal.utils.compat import stdlib_pkgs
|
from pip._internal.utils.compat import stdlib_pkgs
|
||||||
|
@ -57,12 +57,7 @@ class FreezeCommand(Command):
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Only output packages installed in user-site.')
|
help='Only output packages installed in user-site.')
|
||||||
self.cmd_opts.add_option(
|
self.cmd_opts.add_option(cmdoptions.list_path())
|
||||||
'--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(
|
self.cmd_opts.add_option(
|
||||||
'--all',
|
'--all',
|
||||||
dest='freeze_all',
|
dest='freeze_all',
|
||||||
|
@ -84,10 +79,7 @@ class FreezeCommand(Command):
|
||||||
if not options.freeze_all:
|
if not options.freeze_all:
|
||||||
skip.update(DEV_PKGS)
|
skip.update(DEV_PKGS)
|
||||||
|
|
||||||
if options.path and (options.user or options.local):
|
cmdoptions.check_list_path_option(options)
|
||||||
raise CommandError(
|
|
||||||
"Cannot combine '--path' with '--user' or '--local'"
|
|
||||||
)
|
|
||||||
|
|
||||||
freeze_kwargs = dict(
|
freeze_kwargs = dict(
|
||||||
requirement=options.requirements,
|
requirement=options.requirements,
|
||||||
|
|
|
@ -62,12 +62,7 @@ class ListCommand(Command):
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Only output packages installed in user-site.')
|
help='Only output packages installed in user-site.')
|
||||||
self.cmd_opts.add_option(
|
cmd_opts.add_option(cmdoptions.list_path())
|
||||||
'--path',
|
|
||||||
dest='path',
|
|
||||||
action='append',
|
|
||||||
help='Restrict to the specified installation path for listing '
|
|
||||||
'packages (can be used multiple times).')
|
|
||||||
cmd_opts.add_option(
|
cmd_opts.add_option(
|
||||||
'--pre',
|
'--pre',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
@ -131,10 +126,7 @@ class ListCommand(Command):
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"Options --outdated and --uptodate cannot be combined.")
|
"Options --outdated and --uptodate cannot be combined.")
|
||||||
|
|
||||||
if options.path and (options.user or options.local):
|
cmdoptions.check_list_path_option(options)
|
||||||
raise CommandError(
|
|
||||||
"Cannot combine '--path' with '--user' or '--local'"
|
|
||||||
)
|
|
||||||
|
|
||||||
packages = get_installed_distributions(
|
packages = get_installed_distributions(
|
||||||
local_only=options.local,
|
local_only=options.local,
|
||||||
|
|
Loading…
Reference in New Issue