From 62ff3092fb131212116a84f0d7fe707e16427a71 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Thu, 23 Sep 2021 19:29:56 +0200 Subject: [PATCH 1/2] Fix precedence of commandline options and yaml options 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 https://github.com/galaxyproject/ephemeris/issues/180 --- src/ephemeris/shed_tools.py | 23 +++++++++++++---------- src/ephemeris/shed_tools_args.py | 27 ++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 15 deletions(-) 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." ) From 657eba24541466ad4cb169892001b1c3dd490b1f Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Mon, 27 Sep 2021 11:31:04 +0200 Subject: [PATCH 2/2] Fix data manager test setup --- tests/test_run_data_managers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_run_data_managers.py b/tests/test_run_data_managers.py index c29e213..286f538 100644 --- a/tests/test_run_data_managers.py +++ b/tests/test_run_data_managers.py @@ -25,11 +25,14 @@ def test_install_data_managers(self, start_container): # noqa: F811 Prevent sta container = start_container data_managers = [ dict(name="data_manager_fetch_genome_dbkeys_all_fasta", - owner="devteam"), + owner="devteam", + install_resolver_dependencies=True), dict(name="data_manager_sam_fasta_index_builder", - owner="devteam"), + owner="devteam", + install_resolver_dependencies=True), dict(name="data_manager_bwa_mem_index_builder", - owner="devteam") + owner="devteam", + install_resolver_dependencies=True) ] irm = InstallRepositoryManager(container.gi) irm.install_repositories(data_managers)