Skip to content

Commit e7739e7

Browse files
committed
descriptor gets saved to a file for easier exporting, added value-choices extraction, added method to get input type from handler type
1 parent fc27d01 commit e7739e7

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

nipype/utils/nipype2boutiques.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def generate_boutiques_descriptor(
101101
for input in tool_desc['inputs']:
102102
del input['tempvalue']
103103

104+
# Save descriptor to a file
105+
with open(interface_name + '.json', 'w') as outfile:
106+
json.dump(tool_desc, outfile)
107+
104108
return json.dumps(tool_desc, indent=4, separators=(',', ': '))
105109

106110

@@ -128,7 +132,10 @@ def get_boutiques_input(inputs, interface, input_name, spec,
128132
input = {}
129133
input['id'] = input_name
130134
input['name'] = input_name.replace('_', ' ').capitalize()
131-
input['type'] = get_type_from_spec_info(spec_info)
135+
136+
# Figure out the input type from its handler type
137+
input['type'] = get_type_from_handler_type(spec.handler)
138+
132139
input['list'] = is_list(spec_info)
133140
input['value-key'] = "[" + input_name.upper(
134141
) + "]" # assumes that input names are unique
@@ -145,6 +152,14 @@ def get_boutiques_input(inputs, interface, input_name, spec,
145152
if spec.usedefault:
146153
input['default-value'] = spec.default_value()[1]
147154

155+
try:
156+
value_choices = spec.handler.values
157+
except AttributeError:
158+
pass
159+
else:
160+
if value_choices is not None:
161+
input['value-choices'] = value_choices
162+
148163
# Create unique, temporary value.
149164
temp_value = must_generate_value(input_name, input['type'],
150165
ignored_template_inputs, spec_info, spec,
@@ -158,9 +173,9 @@ def get_boutiques_input(inputs, interface, input_name, spec,
158173
str(tempvalue))
159174

160175
# Now that temp values have been generated, set Boolean types to
161-
# Number (there is no Boolean type in Boutiques)
176+
# Flag (there is no Boolean type in Boutiques)
162177
if input['type'] == "Boolean":
163-
input['type'] = "Number"
178+
input['type'] = "Flag"
164179

165180
return input
166181

@@ -217,9 +232,16 @@ def get_boutiques_output(name, interface, tool_inputs, verbose=False):
217232
input['value-key'])
218233
) # FIXME: this only works if output is written in the current directory
219234
output['path-template'] = os.path.basename(output_value)
235+
236+
if not output_value:
237+
# Look for an input with the same name and use this as the path template
238+
for input in tool_inputs:
239+
if input['id'] == name:
240+
output['path-template'] = input['value-key']
220241
return output
221242

222243

244+
# TODO remove this once we know get_type_from_handler_type works well
223245
def get_type_from_spec_info(spec_info):
224246
'''
225247
Returns an input type from the spec info. There must be a better
@@ -235,6 +257,17 @@ def get_type_from_spec_info(spec_info):
235257
return "String"
236258

237259

260+
def get_type_from_handler_type(handler):
261+
handler_type = type(handler).__name__
262+
if handler_type == "File" or handler_type == "Directory":
263+
return "File"
264+
elif handler_type == "Int" or handler_type == "Float":
265+
return "Number"
266+
elif handler_type == "Bool":
267+
return "Flag"
268+
else:
269+
return "String"
270+
238271
def is_list(spec_info):
239272
'''
240273
Returns True if the spec info looks like it describes a list

0 commit comments

Comments
 (0)