44"""CWL Expression refactoring tool for CWL v1.0 ."""
55import copy
66import hashlib
7- from collections .abc import Mapping
8- from typing import (
9- Any ,
10- Dict ,
11- List ,
12- MutableSequence ,
13- Optional ,
14- Sequence ,
15- Tuple ,
16- Type ,
17- Union ,
18- cast ,
19- )
7+ from collections .abc import Mapping , MutableSequence , Sequence
8+ from typing import Any , Optional , Union , cast
209
2110from ruamel import yaml
2211from schema_salad .sourceline import SourceLine
@@ -142,7 +131,7 @@ def get_expression(
142131
143132
144133def etool_to_cltool (
145- etool : cwl .ExpressionTool , expressionLib : Optional [List [str ]] = None
134+ etool : cwl .ExpressionTool , expressionLib : Optional [list [str ]] = None
146135) -> cwl .CommandLineTool :
147136 """Convert a ExpressionTool to a CommandLineTool."""
148137 inputs = yaml .comments .CommentedSeq () # preserve the order
@@ -216,7 +205,7 @@ def traverse(
216205 inside : bool ,
217206 skip_command_line1 : bool ,
218207 skip_command_line2 : bool ,
219- ) -> Tuple [Union [cwl .CommandLineTool , cwl .ExpressionTool , cwl .Workflow ], bool ]:
208+ ) -> tuple [Union [cwl .CommandLineTool , cwl .ExpressionTool , cwl .Workflow ], bool ]:
220209 """Convert the given process and any subprocesses."""
221210 if not inside and isinstance (process , cwl .CommandLineTool ):
222211 process = expand_stream_shortcuts (process )
@@ -330,7 +319,7 @@ def generate_etool_from_expr(
330319 Union [
331320 cwl .InputParameter ,
332321 cwl .CommandInputParameter ,
333- List [Union [cwl .InputParameter , cwl .CommandInputParameter ]],
322+ list [Union [cwl .InputParameter , cwl .CommandInputParameter ]],
334323 ]
335324 ] = None , # if the "self" input should be a different type than the "result" output
336325 extra_processes : Optional [
@@ -344,7 +333,7 @@ def generate_etool_from_expr(
344333 self_type = target
345334 if isinstance (self_type , list ):
346335 new_type : Union [
347- List [Union [cwl .ArraySchema , cwl .InputRecordSchema ]],
336+ list [Union [cwl .ArraySchema , cwl .InputRecordSchema ]],
348337 Union [cwl .ArraySchema , cwl .InputRecordSchema ],
349338 ] = [clean_type_ids (t .type_ ) for t in self_type if t .type_ ]
350339 elif self_type .type_ :
@@ -420,7 +409,7 @@ def get_input_for_id(
420409 """Determine the CommandInputParameter for the given input name."""
421410 name = name .split ("/" )[- 1 ]
422411
423- for inp in cast (List [cwl .CommandInputParameter ], tool .inputs ):
412+ for inp in cast (list [cwl .CommandInputParameter ], tool .inputs ):
424413 if inp .id and inp .id .split ("#" )[- 1 ].split ("/" )[- 1 ] == name :
425414 return inp
426415 if isinstance (tool , cwl .Workflow ) and "/" in name :
@@ -437,7 +426,7 @@ def find_expressionLib(
437426 processes : Sequence [
438427 Union [cwl .CommandLineTool , cwl .Workflow , cwl .ExpressionTool , cwl .WorkflowStep ]
439428 ]
440- ) -> Optional [List [str ]]:
429+ ) -> Optional [list [str ]]:
441430 """
442431 Return the expressionLib from the highest priority InlineJavascriptRequirement.
443432
@@ -448,7 +437,7 @@ def find_expressionLib(
448437 if process .requirements :
449438 for req in process .requirements :
450439 if isinstance (req , cwl .InlineJavascriptRequirement ):
451- return cast (Optional [List [str ]], copy .deepcopy (req .expressionLib ))
440+ return cast (Optional [list [str ]], copy .deepcopy (req .expressionLib ))
452441 return None
453442
454443
@@ -457,15 +446,15 @@ def replace_expr_with_etool(
457446 name : str ,
458447 workflow : cwl .Workflow ,
459448 target : Union [cwl .CommandInputParameter , cwl .InputParameter ],
460- source : Optional [Union [str , List [Any ]]],
449+ source : Optional [Union [str , list [Any ]]],
461450 replace_etool : bool = False ,
462451 extra_process : Optional [
463452 Union [cwl .Workflow , cwl .WorkflowStep , cwl .CommandLineTool ]
464453 ] = None ,
465454 source_type : Optional [cwl .CommandInputParameter ] = None ,
466455) -> None :
467456 """Modify the given workflow, replacing the expr with an standalone ExpressionTool."""
468- extra_processes : List [
457+ extra_processes : list [
469458 Union [cwl .Workflow , cwl .WorkflowStep , cwl .CommandLineTool ]
470459 ] = [workflow ]
471460 if extra_process :
@@ -474,7 +463,7 @@ def replace_expr_with_etool(
474463 expr , target , source is None , source_type , extra_processes
475464 )
476465 if replace_etool :
477- processes : List [Union [cwl .WorkflowStep , cwl .Workflow , cwl .CommandLineTool ]] = [
466+ processes : list [Union [cwl .WorkflowStep , cwl .Workflow , cwl .CommandLineTool ]] = [
478467 workflow
479468 ]
480469 if extra_process :
@@ -528,7 +517,7 @@ def empty_inputs(
528517 cwl .CommandLineTool , cwl .WorkflowStep , cwl .ExpressionTool , cwl .Workflow
529518 ],
530519 parent : Optional [cwl .Workflow ] = None ,
531- ) -> Dict [str , Any ]:
520+ ) -> dict [str , Any ]:
532521 """Produce a mock input object for the given inputs."""
533522 result = {}
534523 if isinstance (process_or_step , cwl .Process ):
@@ -662,22 +651,22 @@ def process_workflow_reqs_and_hints(
662651 # and connecting all workflow inputs to the generated step
663652 modified = False
664653 inputs = empty_inputs (workflow )
665- generated_res_reqs : List [ Tuple [str , Union [int , str ]]] = []
666- generated_iwdr_reqs : List [ Tuple [str , Union [int , str ]]] = []
667- generated_envVar_reqs : List [ Tuple [str , Union [int , str ]]] = []
668- prop_reqs : Tuple [
654+ generated_res_reqs : list [ tuple [str , Union [int , str ]]] = []
655+ generated_iwdr_reqs : list [ tuple [str , Union [int , str ]]] = []
656+ generated_envVar_reqs : list [ tuple [str , Union [int , str ]]] = []
657+ prop_reqs : tuple [
669658 Union [
670- Type [cwl .EnvVarRequirement ],
671- Type [cwl .ResourceRequirement ],
672- Type [cwl .InitialWorkDirRequirement ],
659+ type [cwl .EnvVarRequirement ],
660+ type [cwl .ResourceRequirement ],
661+ type [cwl .InitialWorkDirRequirement ],
673662 ],
674663 ...,
675664 ] = ()
676665 resourceReq : Optional [cwl .ResourceRequirement ] = None
677666 envVarReq : Optional [cwl .EnvVarRequirement ] = None
678667 iwdr : Optional [cwl .InitialWorkDirRequirement ] = None
679668 if workflow .requirements is not None :
680- for req in cast (List [cwl .ProcessRequirement ], workflow .requirements ):
669+ for req in cast (list [cwl .ProcessRequirement ], workflow .requirements ):
681670 if req and isinstance (req , cwl .EnvVarRequirement ):
682671 if req .envDef :
683672 for index , envDef in enumerate (req .envDef ):
@@ -994,9 +983,9 @@ def process_level_reqs(
994983 modified = False
995984 target_process = step .run
996985 inputs = empty_inputs (process )
997- generated_res_reqs : List [ Tuple [str , str ]] = []
998- generated_iwdr_reqs : List [ Tuple [str , Union [int , str ], Any ]] = []
999- generated_envVar_reqs : List [ Tuple [str , Union [int , str ]]] = []
986+ generated_res_reqs : list [ tuple [str , str ]] = []
987+ generated_iwdr_reqs : list [ tuple [str , Union [int , str ], Any ]] = []
988+ generated_envVar_reqs : list [ tuple [str , Union [int , str ]]] = []
1000989 if not step .id :
1001990 return False
1002991 step_name = step .id .split ("#" , 1 )[- 1 ]
@@ -1378,7 +1367,7 @@ def traverse_CommandLineTool(
13781367 }
13791368 ]
13801369 if outp .outputBinding .loadContents :
1381- cast (Dict [Any , Any ], self )[0 ]["contents" ] = "stuff"
1370+ cast (dict [Any , Any ], self )[0 ]["contents" ] = "stuff"
13821371 expression = get_expression (outp .outputBinding .outputEval , inputs , self )
13831372 if expression :
13841373 modified = True
@@ -1635,7 +1624,7 @@ def replace_clt_hintreq_expr_with_etool(
16351624
16361625def cltool_inputs_to_etool_inputs (
16371626 tool : cwl .CommandLineTool ,
1638- ) -> List [cwl .InputParameter ]:
1627+ ) -> list [cwl .InputParameter ]:
16391628 """Copy CommandLineTool input objects into the equivalent ExpressionTool input objects."""
16401629 inputs = yaml .comments .CommentedSeq ()
16411630 if tool .inputs :
@@ -1661,7 +1650,7 @@ def cltool_inputs_to_etool_inputs(
16611650
16621651def cltool_step_outputs_to_workflow_outputs (
16631652 cltool_step : cwl .WorkflowStep , etool_step_id : str , etool_out_id : str
1664- ) -> List [cwl .OutputParameter ]:
1653+ ) -> list [cwl .OutputParameter ]:
16651654 """
16661655 Copy CommandLineTool outputs into the equivalent Workflow output parameters.
16671656
@@ -1731,7 +1720,7 @@ def generate_etool_from_expr2(
17311720 }"""
17321721 )
17331722 hints = None
1734- procs : List [
1723+ procs : list [
17351724 Union [cwl .CommandLineTool , cwl .ExpressionTool , cwl .Workflow , cwl .WorkflowStep ]
17361725 ] = []
17371726 if process :
@@ -1820,12 +1809,12 @@ def traverse_step(
18201809 raise WorkflowException ("target not found" )
18211810 input_source_id = None
18221811 source_type : Optional [
1823- Union [List [cwl .InputParameter ], cwl .InputParameter ]
1812+ Union [list [cwl .InputParameter ], cwl .InputParameter ]
18241813 ] = None
18251814 if inp .source :
18261815 if isinstance (inp .source , MutableSequence ):
18271816 input_source_id = []
1828- source_types : List [cwl .InputParameter ] = []
1817+ source_types : list [cwl .InputParameter ] = []
18291818 for source in inp .source :
18301819 source_id = source .split ("#" )[- 1 ]
18311820 input_source_id .append (source_id )
@@ -1851,7 +1840,7 @@ def traverse_step(
18511840 # target.id = target.id.split('#')[-1]
18521841 if isinstance (original_process , cwl .ExpressionTool ):
18531842 found_JSReq = False
1854- reqs : List [cwl .ProcessRequirement ] = []
1843+ reqs : list [cwl .ProcessRequirement ] = []
18551844 if original_process .hints :
18561845 reqs .extend (original_process .hints )
18571846 if original_process .requirements :
@@ -1907,8 +1896,8 @@ def traverse_step(
19071896
19081897
19091898def workflow_step_to_InputParameters (
1910- step_ins : List [cwl .WorkflowStepInput ], parent : cwl .Workflow , except_in_id : str
1911- ) -> List [cwl .InputParameter ]:
1899+ step_ins : list [cwl .WorkflowStepInput ], parent : cwl .Workflow , except_in_id : str
1900+ ) -> list [cwl .InputParameter ]:
19121901 """Create InputParameters to match the given WorkflowStep inputs."""
19131902 params = []
19141903 for inp in step_ins :
@@ -1947,10 +1936,10 @@ def replace_step_valueFrom_expr_with_etool(
19471936 step : cwl .WorkflowStep ,
19481937 step_inp : cwl .WorkflowStepInput ,
19491938 original_process : Union [cwl .CommandLineTool , cwl .ExpressionTool ],
1950- original_step_ins : List [cwl .WorkflowStepInput ],
1951- source : Optional [Union [str , List [str ]]],
1939+ original_step_ins : list [cwl .WorkflowStepInput ],
1940+ source : Optional [Union [str , list [str ]]],
19521941 replace_etool : bool ,
1953- source_type : Optional [Union [cwl .InputParameter , List [cwl .InputParameter ]]] = None ,
1942+ source_type : Optional [Union [cwl .InputParameter , list [cwl .InputParameter ]]] = None ,
19541943) -> None :
19551944 """Replace a WorkflowStep level 'valueFrom' expression with a sibling ExpressionTool step."""
19561945 if not step_inp .id :
@@ -1972,12 +1961,16 @@ def replace_step_valueFrom_expr_with_etool(
19721961 [workflow , step ],
19731962 )
19741963 if replace_etool :
1975- processes = [
1964+ processes : list [
1965+ Union [
1966+ cwl .Workflow , cwl .CommandLineTool , cwl .ExpressionTool , cwl .WorkflowStep
1967+ ]
1968+ ] = [
19761969 workflow ,
19771970 step ,
1978- ] # type: List[Union[cwl.Workflow, cwl.CommandLineTool, cwl.ExpressionTool, cwl.WorkflowStep]]
1971+ ]
19791972 cltool = etool_to_cltool (temp_etool , find_expressionLib (processes ))
1980- etool = cltool # type : Union[cwl.ExpressionTool, cwl.CommandLineTool]
1973+ etool : Union [cwl .ExpressionTool , cwl .CommandLineTool ] = cltool
19811974 else :
19821975 etool = temp_etool
19831976 wf_step_inputs = copy .deepcopy (original_step_ins )
@@ -2026,7 +2019,7 @@ def traverse_workflow(
20262019 replace_etool : bool ,
20272020 skip_command_line1 : bool ,
20282021 skip_command_line2 : bool ,
2029- ) -> Tuple [cwl .Workflow , bool ]:
2022+ ) -> tuple [cwl .Workflow , bool ]:
20302023 """Traverse a workflow, processing each step."""
20312024 modified = False
20322025 for index , step in enumerate (workflow .steps ):
0 commit comments