Skip to content

Commit

Permalink
Fix precedence of commandline options and yaml options
Browse files Browse the repository at this point in the history
commandline options should take precedence over options specied in yaml
file, but default values should be used if options are not set in yaml
file. Fixes #180
  • Loading branch information
mvdbeek committed Sep 23, 2021
1 parent c6aea18 commit 62ff309
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
23 changes: 13 additions & 10 deletions src/ephemeris/shed_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,16 +602,19 @@ def main():
tool_list = dict()

# Get some of the other installation arguments
kwargs = dict(
default_install_tool_dependencies=tool_list.get("install_tool_dependencies") or getattr(args,
"install_tool_dependencies",
False),
default_install_repository_dependencies=tool_list.get("install_repository_dependencies") or getattr(args,
"install_repository_dependencies",
False),
default_install_resolver_dependencies=tool_list.get("install_resolver_dependencies") or getattr(args,
"install_resolver_dependencies",
False))
# Command line arguments should take precedence over arguments in the tool list,
# but only if the command line argument has actually been used.
kwargs = {}
for arg in ['install_tool_dependencies', 'install_repository_dependencies', 'install_resolver_dependencies']:
if not getattr(args, f"{arg}_set", False):
# commandline argument not set, use tool_list argument
arg_val = tool_list.get(arg)
if arg_val is None:
# Not specified in yaml file, use command line default, even if not set
arg_val = getattr(args, arg, False)
else:
arg_val = getattr(args, arg)
kwargs[f"default_{arg}"] = arg_val

# Start installing/updating and store the results in install_results.
# Or do testing if the action is `test`
Expand Down
27 changes: 22 additions & 5 deletions src/ephemeris/shed_tools_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
from .common_parser import get_common_args


class StoredTrue(argparse.Action):

_value = True

def __init__(self, option_strings, dest, nargs=0, **kwargs):
super().__init__(option_strings, dest, nargs=nargs, **kwargs)

def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest + '_set', True)
setattr(namespace, self.dest, self._value)


class StoredFalse(StoredTrue):

_value = False


def parser():
"""construct the parser object"""
common_arguments = get_common_args(log_file=True)
Expand Down Expand Up @@ -106,32 +123,32 @@ def parser():
for command_parser in [update_command_parser, install_command_parser]:
command_parser.add_argument(
"--skip_install_tool_dependencies",
action="store_false",
action=StoredFalse,
dest="install_tool_dependencies",
default=False, # Override True default for this function
help=argparse.SUPPRESS) # Deprecated function. Leave for backwards compatibility.
command_parser.add_argument(
"--install_tool_dependencies",
action="store_true",
action=StoredTrue,
dest="install_tool_dependencies",
help="Turn on installation of tool dependencies using classic toolshed packages. "
"Can be overwritten on a per-tool basis in the tools file.")
command_parser.add_argument(
"--install_resolver_dependencies",
action="store_true",
action=StoredTrue,
dest="install_resolver_dependencies",
default=True, # Override False default for this function
help=argparse.SUPPRESS) # Deprecated function. Leave for backwards compatibility.
command_parser.add_argument(
"--skip_install_resolver_dependencies",
action="store_false",
action=StoredFalse,
dest="install_resolver_dependencies",
help="Skip installing tool dependencies through resolver (e.g. conda). "
"Will be ignored on galaxy releases older than 16.07. "
"Can be overwritten on a per-tool basis in the tools file")
command_parser.add_argument(
"--skip_install_repository_dependencies",
action="store_false",
action=StoredFalse,
dest="install_repository_dependencies",
help="Skip installing the repository dependencies."
)
Expand Down

0 comments on commit 62ff309

Please sign in to comment.