Skip to content

Commit 62ff309

Browse files
committed
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 #180
1 parent c6aea18 commit 62ff309

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

src/ephemeris/shed_tools.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -602,16 +602,19 @@ def main():
602602
tool_list = dict()
603603

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

616619
# Start installing/updating and store the results in install_results.
617620
# Or do testing if the action is `test`

src/ephemeris/shed_tools_args.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
from .common_parser import get_common_args
66

77

8+
class StoredTrue(argparse.Action):
9+
10+
_value = True
11+
12+
def __init__(self, option_strings, dest, nargs=0, **kwargs):
13+
super().__init__(option_strings, dest, nargs=nargs, **kwargs)
14+
15+
def __call__(self, parser, namespace, values, option_string=None):
16+
setattr(namespace, self.dest + '_set', True)
17+
setattr(namespace, self.dest, self._value)
18+
19+
20+
class StoredFalse(StoredTrue):
21+
22+
_value = False
23+
24+
825
def parser():
926
"""construct the parser object"""
1027
common_arguments = get_common_args(log_file=True)
@@ -106,32 +123,32 @@ def parser():
106123
for command_parser in [update_command_parser, install_command_parser]:
107124
command_parser.add_argument(
108125
"--skip_install_tool_dependencies",
109-
action="store_false",
126+
action=StoredFalse,
110127
dest="install_tool_dependencies",
111128
default=False, # Override True default for this function
112129
help=argparse.SUPPRESS) # Deprecated function. Leave for backwards compatibility.
113130
command_parser.add_argument(
114131
"--install_tool_dependencies",
115-
action="store_true",
132+
action=StoredTrue,
116133
dest="install_tool_dependencies",
117134
help="Turn on installation of tool dependencies using classic toolshed packages. "
118135
"Can be overwritten on a per-tool basis in the tools file.")
119136
command_parser.add_argument(
120137
"--install_resolver_dependencies",
121-
action="store_true",
138+
action=StoredTrue,
122139
dest="install_resolver_dependencies",
123140
default=True, # Override False default for this function
124141
help=argparse.SUPPRESS) # Deprecated function. Leave for backwards compatibility.
125142
command_parser.add_argument(
126143
"--skip_install_resolver_dependencies",
127-
action="store_false",
144+
action=StoredFalse,
128145
dest="install_resolver_dependencies",
129146
help="Skip installing tool dependencies through resolver (e.g. conda). "
130147
"Will be ignored on galaxy releases older than 16.07. "
131148
"Can be overwritten on a per-tool basis in the tools file")
132149
command_parser.add_argument(
133150
"--skip_install_repository_dependencies",
134-
action="store_false",
151+
action=StoredFalse,
135152
dest="install_repository_dependencies",
136153
help="Skip installing the repository dependencies."
137154
)

0 commit comments

Comments
 (0)