23
23
from schema_salad .utils import json_dumps
24
24
25
25
import cwl_utils .parser .cwl_v1_1 as cwl
26
+ import cwl_utils .parser .cwl_v1_1_utils as utils
26
27
from cwl_utils .errors import JavascriptException , WorkflowException
27
28
from cwl_utils .expression import do_eval , interpolate
28
29
from cwl_utils .types import CWLObjectType , CWLOutputType
@@ -535,7 +536,7 @@ def empty_inputs(
535
536
else :
536
537
try :
537
538
result [param_id ] = example_input (
538
- type_for_source (process_or_step .run , param .source , parent )
539
+ utils . type_for_source (process_or_step .run , param .source , parent )
539
540
)
540
541
except WorkflowException :
541
542
pass
@@ -580,71 +581,6 @@ def example_input(some_type: Any) -> Any:
580
581
return None
581
582
582
583
583
- def type_for_source (
584
- process : Union [cwl .CommandLineTool , cwl .Workflow , cwl .ExpressionTool ],
585
- sourcenames : Union [str , List [str ]],
586
- parent : Optional [cwl .Workflow ] = None ,
587
- ) -> Union [List [Any ], Any ]:
588
- """Determine the type for the given sourcenames."""
589
- params = param_for_source_id (process , sourcenames , parent )
590
- if not isinstance (params , list ):
591
- return params .type
592
- new_type : List [Any ] = []
593
- for p in params :
594
- if isinstance (p , str ) and p not in new_type :
595
- new_type .append (p )
596
- elif hasattr (p , "type" ) and p .type not in new_type :
597
- new_type .append (p .type )
598
- return new_type
599
-
600
-
601
- def param_for_source_id (
602
- process : Union [cwl .CommandLineTool , cwl .Workflow , cwl .ExpressionTool ],
603
- sourcenames : Union [str , List [str ]],
604
- parent : Optional [cwl .Workflow ] = None ,
605
- ) -> Union [List [cwl .WorkflowInputParameter ], cwl .WorkflowInputParameter ]:
606
- """Find the process input parameter that matches one of the given sourcenames."""
607
- if isinstance (sourcenames , str ):
608
- sourcenames = [sourcenames ]
609
- params : List [cwl .WorkflowInputParameter ] = []
610
- for sourcename in sourcenames :
611
- if not isinstance (process , cwl .Workflow ):
612
- for param in process .inputs :
613
- if param .id .split ("#" )[- 1 ] == sourcename .split ("#" )[- 1 ]:
614
- params .append (param )
615
- targets = [process ]
616
- if parent :
617
- targets .append (parent )
618
- for target in targets :
619
- if isinstance (target , cwl .Workflow ):
620
- for inp in target .inputs :
621
- if inp .id .split ("#" )[- 1 ] == sourcename .split ("#" )[- 1 ]:
622
- params .append (inp )
623
- for step in target .steps :
624
- if sourcename .split ("/" )[0 ] == step .id .split ("#" )[- 1 ] and step .out :
625
- for outp in step .out :
626
- outp_id = outp if isinstance (outp , str ) else outp .id
627
- if outp_id .split ("/" )[- 1 ] == sourcename .split ("/" , 1 )[1 ]:
628
- if step .run and step .run .outputs :
629
- for output in step .run .outputs :
630
- if (
631
- output .id .split ("#" )[- 1 ]
632
- == sourcename .split ("/" , 1 )[1 ]
633
- ):
634
- params .append (output )
635
- if len (params ) == 1 :
636
- return params [0 ]
637
- elif len (params ) > 1 :
638
- return params
639
- raise WorkflowException (
640
- "param {} not found in {}\n or\n {}." .format (
641
- sourcename ,
642
- yaml .main .round_trip_dump (cwl .save (process )),
643
- yaml .main .round_trip_dump (cwl .save (parent )),
644
- )
645
- )
646
-
647
-
648
584
EMPTY_FILE : CWLOutputType = {
649
585
"class" : "File" ,
650
586
"basename" : "em.pty" ,
@@ -1841,11 +1777,13 @@ def traverse_step(
1841
1777
if not step .scatter :
1842
1778
self .append (
1843
1779
example_input (
1844
- type_for_source (parent , source .split ("#" )[- 1 ])
1780
+ utils . type_for_source (parent , source .split ("#" )[- 1 ])
1845
1781
)
1846
1782
)
1847
1783
else :
1848
- scattered_source_type = type_for_source (parent , source )
1784
+ scattered_source_type = utils .type_for_source (
1785
+ parent , source
1786
+ )
1849
1787
if isinstance (scattered_source_type , list ):
1850
1788
for stype in scattered_source_type :
1851
1789
self .append (example_input (stype .type ))
@@ -1854,10 +1792,12 @@ def traverse_step(
1854
1792
else :
1855
1793
if not step .scatter :
1856
1794
self = example_input (
1857
- type_for_source (parent , inp .source .split ("#" )[- 1 ])
1795
+ utils . type_for_source (parent , inp .source .split ("#" )[- 1 ])
1858
1796
)
1859
1797
else :
1860
- scattered_source_type2 = type_for_source (parent , inp .source )
1798
+ scattered_source_type2 = utils .type_for_source (
1799
+ parent , inp .source
1800
+ )
1861
1801
if isinstance (scattered_source_type2 , list ):
1862
1802
self = example_input (scattered_source_type2 [0 ].type )
1863
1803
else :
@@ -1880,7 +1820,9 @@ def traverse_step(
1880
1820
for source in inp .source :
1881
1821
source_id = source .split ("#" )[- 1 ]
1882
1822
input_source_id .append (source_id )
1883
- temp_type = type_for_source (step .run , source_id , parent )
1823
+ temp_type = utils .type_for_source (
1824
+ step .run , source_id , parent
1825
+ )
1884
1826
if isinstance (temp_type , list ):
1885
1827
for ttype in temp_type :
1886
1828
if ttype not in source_types :
@@ -1894,7 +1836,7 @@ def traverse_step(
1894
1836
)
1895
1837
else :
1896
1838
input_source_id = inp .source .split ("#" )[- 1 ]
1897
- source_type = param_for_source_id (
1839
+ source_type = utils . param_for_source_id (
1898
1840
step .run , input_source_id , parent
1899
1841
)
1900
1842
# target.id = target.id.split('#')[-1]
@@ -1965,7 +1907,9 @@ def workflow_step_to_WorkflowInputParameters(
1965
1907
continue
1966
1908
inp_id = inp .id .split ("#" )[- 1 ].split ("/" )[- 1 ]
1967
1909
if inp .source and inp_id != except_in_id :
1968
- param = copy .deepcopy (param_for_source_id (parent , sourcenames = inp .source ))
1910
+ param = copy .deepcopy (
1911
+ utils .param_for_source_id (parent , sourcenames = inp .source )
1912
+ )
1969
1913
if isinstance (param , list ):
1970
1914
for p in param :
1971
1915
p .id = inp_id
0 commit comments