Skip to content

Commit c1cfc80

Browse files
committed
added logic to deal with range and list inputs, added try except block to deal with undefined output values
1 parent ce06815 commit c1cfc80

File tree

1 file changed

+46
-22
lines changed

1 file changed

+46
-22
lines changed

nipype/utils/nipype2boutiques.py

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,48 @@ def get_boutiques_input(inputs, interface, input_name, spec,
138138
input['name'] = input_name.replace('_', ' ').capitalize()
139139

140140
# Figure out the input type from its handler type
141-
input_type = get_type_from_handler_type(spec.handler)
142-
input['type'] = input_type[0]
143-
if input_type[1]:
141+
handler_type = type(spec.handler).__name__
142+
143+
if handler_type == "File" or handler_type == "Directory":
144+
input['type'] = "File"
145+
elif handler_type == "Int":
146+
input['type'] = "Number"
144147
input['integer'] = True
148+
elif handler_type == "Float":
149+
input['type'] = "Number"
150+
elif handler_type == "Bool":
151+
input['type'] = "Flag"
152+
else:
153+
input['type'] = "String"
154+
155+
# Deal with range inputs
156+
if handler_type == "Range":
157+
input['type'] = "Number"
158+
if spec.handler.low is not None:
159+
input['minimum'] = spec.handler.low
160+
if spec.handler.high is not None:
161+
input['maximum'] = spec.handler.high
162+
if spec.handler.exclude_low is not None:
163+
input['exclusive-minimum'] = spec.handler.exclude_low
164+
if spec.handler.exclude_high is not None:
165+
input['exclusive-maximum'] = spec.handler.exclude_high
166+
167+
# Deal with list inputs
168+
if handler_type == "List":
169+
input['list'] = True
170+
trait_type = type(spec.handler.item_trait.trait_type).__name__
171+
if trait_type == "Int":
172+
input['integer'] = True
173+
input['type'] = "Number"
174+
elif trait_type == "Float":
175+
input['type'] = "Number"
176+
else:
177+
input['type'] = "String"
178+
if spec.handler.minlen is not None:
179+
input['min-list-entries'] = spec.handler.minlen
180+
if spec.handler.maxlen is not None:
181+
input['max-list-entries'] = spec.handler.maxlen
145182

146-
input['list'] = is_list(spec_info)
147183
input['value-key'] = "[" + input_name.upper(
148184
) + "]" # assumes that input names are unique
149185

@@ -234,7 +270,10 @@ def get_boutiques_output(outputs, name, spec, interface, tool_inputs, verbose=Fa
234270

235271
# Path template creation.
236272

237-
output_value = interface._list_outputs()[name]
273+
try:
274+
output_value = interface._list_outputs()[name]
275+
except TypeError:
276+
output_value = None
238277

239278
# If output value is defined, use its basename
240279
if output_value != "" and isinstance(
@@ -273,7 +312,7 @@ def get_boutiques_output(outputs, name, spec, interface, tool_inputs, verbose=Fa
273312
return output
274313

275314

276-
# TODO remove this once we know get_type_from_handler_type works well
315+
# TODO remove this
277316
def get_type_from_spec_info(spec_info):
278317
'''
279318
Returns an input type from the spec info. There must be a better
@@ -289,22 +328,7 @@ def get_type_from_spec_info(spec_info):
289328
return "String"
290329

291330

292-
def get_type_from_handler_type(handler):
293-
'''
294-
Gets the input type from the spec handler type.
295-
Returns a tuple containing the type and a boolean to specify
296-
if the type is an integer.
297-
'''
298-
handler_type = type(handler).__name__
299-
if handler_type == "File" or handler_type == "Directory":
300-
return "File", False
301-
elif handler_type == "Int" or handler_type == "Float":
302-
return "Number", handler_type == "Int"
303-
elif handler_type == "Bool":
304-
return "Flag", False
305-
else:
306-
return "String", False
307-
331+
# TODO remove this
308332
def is_list(spec_info):
309333
'''
310334
Returns True if the spec info looks like it describes a list

0 commit comments

Comments
 (0)