4
4
absolute_import )
5
5
6
6
import os .path as op
7
+ import inspect
7
8
import numpy as np
8
9
from ... import logging
9
10
from ..base import (traits , File , isdefined , LibraryBaseInterface ,
@@ -130,17 +131,25 @@ def create_interface_specs(class_name, params=None, BaseClass=TraitedSpec):
130
131
"""
131
132
attr = {}
132
133
if params is not None :
133
- for name , dipy_type , desc in params :
134
+ for p in params :
135
+ name , dipy_type , desc = p [0 ], p [1 ], p [2 ]
134
136
is_file = bool ("files" in name or "out_" in name )
135
137
traits_type , is_mandatory = convert_to_traits_type (dipy_type ,
136
138
is_file )
137
139
# print(name, dipy_type, desc, is_file, traits_type, is_mandatory)
138
- if isinstance (BaseClass , BaseInterfaceInputSpec ):
139
- attr [name ] = traits_type (desc = desc [- 1 ], mandatory = is_mandatory )
140
+ if BaseClass .__name__ == BaseInterfaceInputSpec .__name__ :
141
+ if len (p ) > 3 :
142
+ attr [name ] = traits_type (p [3 ], desc = desc [- 1 ],
143
+ usedefault = True ,
144
+ mandatory = is_mandatory )
145
+ else :
146
+ attr [name ] = traits_type (desc = desc [- 1 ],
147
+ mandatory = is_mandatory )
140
148
else :
141
- attr [name ] = traits_type (desc = desc [- 1 ], exists = True )
149
+ attr [name ] = traits_type (p [3 ], desc = desc [- 1 ], exists = True ,
150
+ usedefault = True ,)
142
151
143
- newclass = type (class_name , (BaseClass , ), attr )
152
+ newclass = type (str ( class_name ) , (BaseClass , ), attr )
144
153
return newclass
145
154
146
155
@@ -166,15 +175,21 @@ def dipy_to_nipype_interface(cls_name, dipy_flow, BaseClass=DipyBaseInterface):
166
175
167
176
"""
168
177
parser = IntrospectiveArgumentParser ()
169
- parser .add_workflow (dipy_flow ())
170
- input_parameters = parser .positional_parameters + parser .optional_parameters
178
+ flow = dipy_flow ()
179
+ parser .add_workflow (flow )
180
+ default_values = inspect .getargspec (flow .run ).defaults
181
+ optional_params = [args + (val ,) for args , val in zip (parser .optional_parameters , default_values )]
182
+ start = len (parser .optional_parameters ) - len (parser .output_parameters )
183
+
184
+ output_parameters = [args + (val ,) for args , val in zip (parser .output_parameters , default_values [start :])]
185
+ input_parameters = parser .positional_parameters + optional_params
171
186
172
187
input_spec = create_interface_specs ("{}InputSpec" .format (cls_name ),
173
188
input_parameters ,
174
189
BaseClass = BaseInterfaceInputSpec )
175
190
176
191
output_spec = create_interface_specs ("{}OutputSpec" .format (cls_name ),
177
- parser . output_parameters ,
192
+ output_parameters ,
178
193
BaseClass = TraitedSpec )
179
194
180
195
def _run_interface (self , runtime ):
@@ -190,7 +205,7 @@ def _list_outputs(self):
190
205
191
206
return outputs
192
207
193
- newclass = type (cls_name , (BaseClass , ),
208
+ newclass = type (str ( cls_name ) , (BaseClass , ),
194
209
{"input_spec" : input_spec ,
195
210
"output_spec" : output_spec ,
196
211
"_run_interface" : _run_interface ,
0 commit comments