diff --git a/src/ephemeris/shed_tools.py b/src/ephemeris/shed_tools.py index d3734a7..e19b205 100644 --- a/src/ephemeris/shed_tools.py +++ b/src/ephemeris/shed_tools.py @@ -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` diff --git a/src/ephemeris/shed_tools_args.py b/src/ephemeris/shed_tools_args.py index 851d78c..868e2e4 100644 --- a/src/ephemeris/shed_tools_args.py +++ b/src/ephemeris/shed_tools_args.py @@ -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) @@ -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." )