Skip to content

Commit

Permalink
Allow passing empty lists to some options
Browse files Browse the repository at this point in the history
Signed-off-by: František Nečas <fifinecas@seznam.cz>
  • Loading branch information
FrNecas committed Mar 16, 2020
1 parent 55caf93 commit bb86b2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion rebasehelper/argument_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, option_strings,
dest=None,
default=None,
nargs=None,
const=None,
required=False,
type=None, # pylint: disable=redefined-builtin
metavar=None,
Expand All @@ -64,6 +65,7 @@ def __init__(self, option_strings,
super(CustomAction, self).__init__(
option_strings=option_strings,
dest=dest,
const=const,
default=default,
required=required,
metavar=metavar,
Expand Down Expand Up @@ -95,7 +97,8 @@ class CustomArgumentParser(argparse.ArgumentParser):
def _check_value(self, action, value):
if isinstance(value, list):
# converted value must be subset of the choices (if specified)
if action.choices is not None and not set(value).issubset(action.choices):
empty = value == action.const
if action.choices is not None and not empty and not set(value).issubset(action.choices):
invalid = set(value).difference(action.choices)
if len(invalid) == 1:
tup = repr(invalid.pop()), ', '.join(map(repr, action.choices))
Expand Down
8 changes: 8 additions & 0 deletions rebasehelper/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
"name": ["--pkgcomparetool"],
"choices": plugin_manager.checkers.get_all_plugins(),
"available_choices": plugin_manager.checkers.get_supported_plugins(),
"nargs": "?",
"const": [""],
"default": plugin_manager.checkers.get_default_plugins(),
"type": lambda s: s.split(','),
"help": "set of tools to use for package comparison, defaults to "
Expand All @@ -107,6 +109,8 @@
"name": ["--versioneer-blacklist"],
"choices": plugin_manager.versioneers.get_all_plugins(),
"available_choices": plugin_manager.versioneers.get_supported_plugins(),
"nargs": "?",
"const": [""],
"default": [],
"type": lambda s: s.split(","),
"help": "prevent specified versioneers from being run",
Expand All @@ -115,6 +119,8 @@
"name": ["--spec-hook-blacklist"],
"choices": plugin_manager.spec_hooks.get_all_plugins(),
"available_choices": plugin_manager.spec_hooks.get_supported_plugins(),
"nargs": "?",
"const": [""],
"default": [],
"type": lambda s: s.split(","),
"help": "prevent specified spec hooks from being run",
Expand All @@ -123,6 +129,8 @@
"name": ["--build-log-hook-blacklist"],
"choices": plugin_manager.build_log_hooks.get_all_plugins(),
"available_choices": plugin_manager.build_log_hooks.get_supported_plugins(),
"nargs": "?",
"const": [""],
"default": [],
"type": lambda s: s.split(","),
"help": "prevent specified build log hooks from being run"
Expand Down
2 changes: 1 addition & 1 deletion rebasehelper/tests/functional/test_rebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_files_build_log_hook(self, buildtool):
'--force-build-log-hooks',
'--buildtool', buildtool,
'--outputtool', 'json',
'--pkgcomparetool', 'rpmdiff', # FIXME: no checkers are actually needed here
'--pkgcomparetool', '',
'--color=always',
new_version,
])
Expand Down

0 comments on commit bb86b2c

Please sign in to comment.