Skip to content

Commit b509aad

Browse files
committed
fix: allow more support for cli
1 parent d387481 commit b509aad

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

nipype/scripts/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,35 @@ def add_args_options(arg_parser, interface):
6868
args["default"] = getattr(inputs, name)
6969
args["action"] = 'store_true'
7070

71+
# current support is for simple trait types
72+
if not spec.inner_traits:
73+
trait_type = type(spec.trait_type.default_value)
74+
if trait_type in (str, int, float):
75+
args["type"] = trait_type
76+
elif len(spec.inner_traits) == 1:
77+
trait_type = type(spec.inner_traits[0].trait_type.default_value)
78+
if trait_type in (bool, str, int, float):
79+
args["type"] = trait_type
80+
7181
if hasattr(spec, "mandatory") and spec.mandatory:
7282
if spec.is_trait_type(InputMultiPath):
7383
args["nargs"] = "+"
84+
elif spec.is_trait_type(traits.List):
85+
if (spec.trait_type.minlen == spec.trait_type.maxlen) and \
86+
spec.trait_type.maxlen:
87+
args["nargs"] = spec.trait_type.maxlen
88+
else:
89+
args["nargs"] = "+"
7490
arg_parser.add_argument(name, help=desc, **args)
7591
else:
7692
if spec.is_trait_type(InputMultiPath):
7793
args["nargs"] = "*"
94+
elif spec.is_trait_type(traits.List):
95+
if (spec.trait_type.minlen == spec.trait_type.maxlen) and \
96+
spec.trait_type.maxlen:
97+
args["nargs"] = spec.trait_type.maxlen
98+
else:
99+
args["nargs"] = "*"
78100
arg_parser.add_argument("--%s" % name, dest=name,
79101
help=desc, **args)
80102
return arg_parser

nipype/utils/nipype_cmd.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,8 @@ def run_instance(interface, options):
5050
print("setting function inputs")
5151

5252
for input_name, _ in list(interface.inputs.items()):
53-
if getattr(options, input_name) != None:
53+
if getattr(options, input_name) is not None:
5454
value = getattr(options, input_name)
55-
if not isinstance(value, bool):
56-
# traits cannot cast from string to float or int
57-
try:
58-
value = float(value)
59-
except:
60-
pass
61-
# try to cast string input to boolean
62-
try:
63-
value = str2bool(value)
64-
except:
65-
pass
6655
try:
6756
setattr(interface.inputs, input_name,
6857
value)

0 commit comments

Comments
 (0)