diff --git a/src/ephemeris/shed_tools.py b/src/ephemeris/shed_tools.py index 76f0019..59f2a1e 100644 --- a/src/ephemeris/shed_tools.py +++ b/src/ephemeris/shed_tools.py @@ -689,15 +689,19 @@ def main(argv=None): else: 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 18ec43c..9ecfc2a 100644 --- a/src/ephemeris/shed_tools_args.py +++ b/src/ephemeris/shed_tools_args.py @@ -8,6 +8,23 @@ ) +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) @@ -120,7 +137,7 @@ def parser(): command_parser.add_argument( "--skip-install-tool-dependencies", "--skip_install_tool_dependencies", - action="store_false", + action=StoredFalse, dest="install_tool_dependencies", default=False, # Override True default for this function help=argparse.SUPPRESS, @@ -128,7 +145,7 @@ def parser(): command_parser.add_argument( "--install-tool-dependencies", "--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.", @@ -136,7 +153,7 @@ def parser(): command_parser.add_argument( "--install-resolver-dependencies", "--install_resolver_dependencies", - action="store_true", + action=StoredTrue, dest="install_resolver_dependencies", default=True, # Override False default for this function help=argparse.SUPPRESS, @@ -144,7 +161,7 @@ def parser(): command_parser.add_argument( "--skip-install-resolver-dependencies", "--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. " @@ -153,7 +170,7 @@ def parser(): command_parser.add_argument( "--skip-install-repository-dependencies", "--skip_install_repository_dependencies", - action="store_false", + action=StoredFalse, dest="install_repository_dependencies", help="Skip installing the repository dependencies.", ) diff --git a/tests/test_run_data_managers.py b/tests/test_run_data_managers.py index d12f527..5174a9b 100644 --- a/tests/test_run_data_managers.py +++ b/tests/test_run_data_managers.py @@ -21,9 +21,15 @@ def test_install_data_managers(self, start_container): """Install the data_managers on galaxy""" container = start_container data_managers = [ - dict(name="data_manager_fetch_genome_dbkeys_all_fasta", owner="devteam"), - dict(name="data_manager_sam_fasta_index_builder", owner="devteam"), - dict(name="data_manager_bwa_mem_index_builder", owner="devteam"), + dict(name="data_manager_fetch_genome_dbkeys_all_fasta", + owner="devteam", + install_resolver_dependencies=True), + dict(name="data_manager_sam_fasta_index_builder", + owner="devteam", + install_resolver_dependencies=True), + dict(name="data_manager_bwa_mem_index_builder", + owner="devteam", + install_resolver_dependencies=True) ] irm = InstallRepositoryManager(container.gi) irm.install_repositories(data_managers)