Skip to content

Commit 52d87a9

Browse files
committed
added handling for lists with value choices, fixed logic to handle case when command line flag includes a 0 or 1 (seen in FNIRT)
1 parent 9a17389 commit 52d87a9

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

nipype/utils/nipype2boutiques.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,7 @@ def get_boutiques_input(inputs, interface, input_name, spec, verbose,
268268
elif handler_type == "Float":
269269
inp['type'] = "Number"
270270
elif handler_type == "Bool":
271-
if (spec.argstr and len(spec.argstr.split("=")) > 1 and
272-
(spec.argstr.split("=")[1] == '0'
273-
or spec.argstr.split("=")[1] == '1')):
274-
inp['type'] = "Number"
275-
inp['integer'] = True
276-
inp['minimum'] = 0
277-
inp['maximum'] = 1
278-
else:
279-
inp['type'] = "Flag"
271+
inp['type'] = "Flag"
280272
else:
281273
inp['type'] = "String"
282274

@@ -296,14 +288,24 @@ def get_boutiques_input(inputs, interface, input_name, spec, verbose,
296288
# TODO handle lists of lists (e.g. FSL ProbTrackX seed input)
297289
if handler_type == "List":
298290
inp['list'] = True
299-
trait_type = type(trait_handler.item_trait.trait_type).__name__
300-
if trait_type == "Int":
291+
item_type = trait_handler.item_trait.trait_type
292+
item_type_name = type(item_type).__name__
293+
if item_type_name == "Int":
301294
inp['integer'] = True
302295
inp['type'] = "Number"
303-
elif trait_type == "Float":
296+
elif item_type_name == "Float":
304297
inp['type'] = "Number"
305-
elif trait_type == "File":
298+
elif item_type_name == "File":
306299
inp['type'] = "File"
300+
elif item_type_name == "Enum":
301+
value_choices = item_type.values
302+
if value_choices is not None:
303+
if all(isinstance(n, int) for n in value_choices):
304+
inp['type'] = "Number"
305+
inp['integer'] = True
306+
elif all(isinstance(n, float) for n in value_choices):
307+
inp['type'] = "Number"
308+
inp['value-choices'] = value_choices
307309
else:
308310
inp['type'] = "String"
309311
if trait_handler.minlen != 0:
@@ -532,7 +534,7 @@ def generate_custom_inputs(desc_inputs):
532534
for desc_input in desc_inputs:
533535
if desc_input['type'] == 'Flag':
534536
custom_input_dicts.append({desc_input['id']: True})
535-
elif desc_input.get('value-choices'):
537+
elif desc_input.get('value-choices') and not desc_input.get('list'):
536538
for value in desc_input['value-choices']:
537539
custom_input_dicts.append({desc_input['id']: value})
538540
return custom_input_dicts
@@ -578,8 +580,12 @@ def get_command_line_flag(input_spec, is_flag_type=False, input_name=None):
578580
flag, flag_sep = None, None
579581
if input_spec.argstr:
580582
if "=" in input_spec.argstr:
581-
flag = input_spec.argstr.split("=")[0].strip()
582-
flag_sep = "="
583+
if (input_spec.argstr.split("=")[1] == '0'
584+
or input_spec.argstr.split("=")[1] == '1'):
585+
flag = input_spec.argstr
586+
else:
587+
flag = input_spec.argstr.split("=")[0].strip()
588+
flag_sep = "="
583589
elif input_spec.argstr.split("%")[0]:
584590
flag = input_spec.argstr.split("%")[0].strip()
585591
elif is_flag_type:

0 commit comments

Comments
 (0)