2323from schema_salad .utils import json_dumps
2424
2525import cwl_utils .parser .cwl_v1_1 as cwl
26+ import cwl_utils .parser .cwl_v1_1_utils as utils
2627from cwl_utils .errors import JavascriptException , WorkflowException
2728from cwl_utils .expression import do_eval , interpolate
2829from cwl_utils .types import CWLObjectType , CWLOutputType
@@ -535,7 +536,7 @@ def empty_inputs(
535536 else :
536537 try :
537538 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 )
539540 )
540541 except WorkflowException :
541542 pass
@@ -580,71 +581,6 @@ def example_input(some_type: Any) -> Any:
580581 return None
581582
582583
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-
648584EMPTY_FILE : CWLOutputType = {
649585 "class" : "File" ,
650586 "basename" : "em.pty" ,
@@ -1841,11 +1777,13 @@ def traverse_step(
18411777 if not step .scatter :
18421778 self .append (
18431779 example_input (
1844- type_for_source (parent , source .split ("#" )[- 1 ])
1780+ utils . type_for_source (parent , source .split ("#" )[- 1 ])
18451781 )
18461782 )
18471783 else :
1848- scattered_source_type = type_for_source (parent , source )
1784+ scattered_source_type = utils .type_for_source (
1785+ parent , source
1786+ )
18491787 if isinstance (scattered_source_type , list ):
18501788 for stype in scattered_source_type :
18511789 self .append (example_input (stype .type ))
@@ -1854,10 +1792,12 @@ def traverse_step(
18541792 else :
18551793 if not step .scatter :
18561794 self = example_input (
1857- type_for_source (parent , inp .source .split ("#" )[- 1 ])
1795+ utils . type_for_source (parent , inp .source .split ("#" )[- 1 ])
18581796 )
18591797 else :
1860- scattered_source_type2 = type_for_source (parent , inp .source )
1798+ scattered_source_type2 = utils .type_for_source (
1799+ parent , inp .source
1800+ )
18611801 if isinstance (scattered_source_type2 , list ):
18621802 self = example_input (scattered_source_type2 [0 ].type )
18631803 else :
@@ -1880,7 +1820,9 @@ def traverse_step(
18801820 for source in inp .source :
18811821 source_id = source .split ("#" )[- 1 ]
18821822 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+ )
18841826 if isinstance (temp_type , list ):
18851827 for ttype in temp_type :
18861828 if ttype not in source_types :
@@ -1894,7 +1836,7 @@ def traverse_step(
18941836 )
18951837 else :
18961838 input_source_id = inp .source .split ("#" )[- 1 ]
1897- source_type = param_for_source_id (
1839+ source_type = utils . param_for_source_id (
18981840 step .run , input_source_id , parent
18991841 )
19001842 # target.id = target.id.split('#')[-1]
@@ -1965,7 +1907,9 @@ def workflow_step_to_WorkflowInputParameters(
19651907 continue
19661908 inp_id = inp .id .split ("#" )[- 1 ].split ("/" )[- 1 ]
19671909 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+ )
19691913 if isinstance (param , list ):
19701914 for p in param :
19711915 p .id = inp_id
0 commit comments