15
15
import yaml
16
16
import fileformats .core .utils
17
17
import fileformats .core .mixin
18
- from fileformats .generic import File
18
+ from fileformats .generic import File , Directory
19
19
from fileformats .medimage import Nifti1 , NiftiGz , Bval , Bvec
20
20
from fileformats .application import Dicom , Xml
21
21
from fileformats .text import TextFile
@@ -59,6 +59,7 @@ def escape_leading_digits(name: str) -> str:
59
59
"9" : "nine" ,
60
60
}
61
61
62
+
62
63
def download_tasks_template (output_path : Path ):
63
64
"""Downloads the latest pydra-template to the output path"""
64
65
@@ -161,6 +162,8 @@ def generate_packages(
161
162
file_outputs ,
162
163
genfile_outputs ,
163
164
multi_inputs ,
165
+ dir_inputs ,
166
+ dir_outputs ,
164
167
) = parse_nipype_interface (nipype_interface )
165
168
166
169
# Create "stubs" for each of the available fields
@@ -188,7 +191,9 @@ def fields_stub(name, category_class, values=None):
188
191
return dct
189
192
190
193
input_types = {i : File for i in file_inputs }
194
+ input_types .update ({i : Directory for i in dir_inputs })
191
195
output_types = {o : File for o in file_outputs }
196
+ output_types .update ({o : Directory for o in dir_outputs })
192
197
output_templates = {}
193
198
194
199
# Attempt to parse doctest to pull out sensible defaults for input/output
@@ -574,6 +579,7 @@ def parse_nipype_interface(
574
579
"""Generate preamble comments at start of file with args and doc strings"""
575
580
input_helps = {}
576
581
file_inputs = []
582
+ dir_inputs = []
577
583
genfile_outputs = []
578
584
multi_inputs = []
579
585
if nipype_interface .input_spec :
@@ -589,16 +595,25 @@ def parse_nipype_interface(
589
595
genfile_outputs .append (inpt_name )
590
596
elif type (inpt .trait_type ).__name__ == "File" :
591
597
file_inputs .append (inpt_name )
598
+ elif type (inpt .trait_type ).__name__ == "Directory" :
599
+ dir_inputs .append (inpt_name )
592
600
elif type (inpt .trait_type ).__name__ == "InputMultiObject" :
593
- file_inputs .append (inpt_name )
601
+ if inpt .trait_type .item_trait and inpt .trait_type .item_trait .trait_type ._is_dir :
602
+ dir_inputs .append (inpt_name )
603
+ else :
604
+ file_inputs .append (inpt_name )
594
605
multi_inputs .append (inpt_name )
595
606
elif (
596
607
type (inpt .trait_type ).__name__ == "List"
597
- and type (inpt .trait_type .inner_traits ()[0 ].handler ).__name__ == "File"
608
+ and type (inpt .trait_type .inner_traits ()[0 ].handler ).__name__ in ( "File" , "Directory" )
598
609
):
599
- file_inputs .append (inpt_name )
610
+ if type (inpt .trait_type .inner_traits ()[0 ].handler ).__name__ == "File" :
611
+ file_inputs .append (inpt_name )
612
+ else :
613
+ dir_inputs .append (inpt_name )
600
614
multi_inputs .append (inpt_name )
601
615
file_outputs = []
616
+ dir_outputs = []
602
617
output_helps = {}
603
618
if nipype_interface .output_spec :
604
619
for outpt_name , outpt in nipype_interface .output_spec ().traits ().items ():
@@ -610,6 +625,8 @@ def parse_nipype_interface(
610
625
] = f"type={ type (outpt .trait_type ).__name__ .lower ()} : { outpt_desc } "
611
626
if type (outpt .trait_type ).__name__ == "File" :
612
627
file_outputs .append (outpt_name )
628
+ elif type (outpt .trait_type ).__name__ == "Directory" :
629
+ dir_outputs .append (outpt_name )
613
630
doc_string = nipype_interface .__doc__ if nipype_interface .__doc__ else ""
614
631
doc_string = doc_string .replace ("\n " , "\n # " )
615
632
# Create a preamble at the top of the specificaiton explaining what to do
@@ -631,6 +648,8 @@ def parse_nipype_interface(
631
648
file_outputs ,
632
649
genfile_outputs ,
633
650
multi_inputs ,
651
+ dir_inputs ,
652
+ dir_outputs ,
634
653
)
635
654
636
655
0 commit comments