8
8
import os .path
9
9
import stat
10
10
import sys
11
- from collections .abc import MutableSequence , Sequence
11
+ from collections .abc import MutableMapping , MutableSequence , Sequence
12
12
from pathlib import Path
13
- from typing import Any , Callable , Dict , List , MutableMapping , Optional , Set , Union
13
+ from typing import Any , Callable , Optional , Union
14
14
15
15
import ruamel .yaml
16
16
from ruamel .yaml .comments import CommentedMap # for consistent sort order
27
27
yaml .default_flow_style = False
28
28
29
29
30
- def parse_args (args : List [str ]) -> argparse .Namespace :
30
+ def parse_args (args : list [str ]) -> argparse .Namespace :
31
31
"""Argument parser."""
32
32
parser = argparse .ArgumentParser (
33
33
description = "Tool to upgrade CWL documents from one version to another. "
@@ -59,7 +59,7 @@ def parse_args(args: List[str]) -> argparse.Namespace:
59
59
return parser .parse_args (args )
60
60
61
61
62
- def main (args : Optional [List [str ]] = None ) -> int :
62
+ def main (args : Optional [list [str ]] = None ) -> int :
63
63
"""Hook to set the args."""
64
64
if not args :
65
65
args = sys .argv [1 :]
@@ -68,7 +68,7 @@ def main(args: Optional[List[str]] = None) -> int:
68
68
69
69
def run (args : argparse .Namespace ) -> int :
70
70
"""Main function."""
71
- imports : Set [str ] = set ()
71
+ imports : set [str ] = set ()
72
72
if args .dir and not os .path .exists (args .dir ):
73
73
os .makedirs (args .dir )
74
74
for path in args .inputs :
@@ -107,7 +107,7 @@ def upgrade_document(
107
107
document : Any ,
108
108
output_dir : str ,
109
109
target_version : Optional [str ] = "latest" ,
110
- imports : Optional [Set [str ]] = None ,
110
+ imports : Optional [set [str ]] = None ,
111
111
) -> Any :
112
112
if imports is None :
113
113
imports = set ()
@@ -210,7 +210,7 @@ def write_cwl_document(document: Any, name: str, dirname: str) -> None:
210
210
211
211
212
212
def process_imports (
213
- document : Any , imports : Set [str ], updater : Callable [[Any , str ], Any ], outdir : str
213
+ document : Any , imports : set [str ], updater : Callable [[Any , str ], Any ], outdir : str
214
214
) -> None :
215
215
"""Find any '$import's and process them."""
216
216
if isinstance (document , CommentedMap ):
@@ -481,10 +481,10 @@ def _v1_1_to_v1_2(document: CommentedMap, outdir: str) -> CommentedMap:
481
481
return document
482
482
483
483
484
- def cleanup_v1_0_input_bindings (document : Dict [str , Any ]) -> None :
484
+ def cleanup_v1_0_input_bindings (document : dict [str , Any ]) -> None :
485
485
"""In v1.1 Workflow or ExpressionTool level inputBindings are deprecated."""
486
486
487
- def cleanup (inp : Dict [str , Any ]) -> None :
487
+ def cleanup (inp : dict [str , Any ]) -> None :
488
488
"""Serialize non loadContents fields and add that to the doc."""
489
489
if "inputBinding" in inp :
490
490
bindings = inp ["inputBinding" ]
@@ -505,10 +505,10 @@ def cleanup(inp: Dict[str, Any]) -> None:
505
505
cleanup (inputs [input_name ])
506
506
507
507
508
- def move_up_loadcontents (document : Dict [str , Any ]) -> None :
508
+ def move_up_loadcontents (document : dict [str , Any ]) -> None :
509
509
"""Promote 'loadContents' up a level for CWL v1.1."""
510
510
511
- def cleanup (inp : Dict [str , Any ]) -> None :
511
+ def cleanup (inp : dict [str , Any ]) -> None :
512
512
"""Move loadContents to the preferred location."""
513
513
if "inputBinding" in inp :
514
514
bindings = inp ["inputBinding" ]
@@ -525,7 +525,7 @@ def cleanup(inp: Dict[str, Any]) -> None:
525
525
cleanup (inputs [input_name ])
526
526
527
527
528
- def upgrade_v1_0_hints_and_reqs (document : Dict [str , Any ]) -> None :
528
+ def upgrade_v1_0_hints_and_reqs (document : dict [str , Any ]) -> None :
529
529
"""Rename some pre-v1.1 extensions to their official CWL v1.1 names."""
530
530
for extra in ("requirements" , "hints" ):
531
531
if extra in document :
@@ -555,7 +555,7 @@ def upgrade_v1_0_hints_and_reqs(document: Dict[str, Any]) -> None:
555
555
)
556
556
557
557
558
- def has_hint_or_req (document : Dict [str , Any ], name : str ) -> bool :
558
+ def has_hint_or_req (document : dict [str , Any ], name : str ) -> bool :
559
559
"""Detects an existing named hint or requirement."""
560
560
for extra in ("requirements" , "hints" ):
561
561
if extra in document :
@@ -571,7 +571,7 @@ def has_hint_or_req(document: Dict[str, Any], name: str) -> bool:
571
571
return False
572
572
573
573
574
- def workflow_clean (document : Dict [str , Any ]) -> None :
574
+ def workflow_clean (document : dict [str , Any ]) -> None :
575
575
"""Transform draft-3 style Workflows to more idiomatic v1.0"""
576
576
input_output_clean (document )
577
577
hints_and_requirements_clean (document )
@@ -652,7 +652,7 @@ def workflow_clean(document: Dict[str, Any]) -> None:
652
652
document ["steps" ] = new_steps
653
653
654
654
655
- def input_output_clean (document : Dict [str , Any ]) -> None :
655
+ def input_output_clean (document : dict [str , Any ]) -> None :
656
656
"""Transform draft-3 style input/output listings into idiomatic v1.0."""
657
657
for param_type in ["inputs" , "outputs" ]:
658
658
if param_type not in document :
@@ -701,7 +701,7 @@ def array_type_raise_sf(param: MutableMapping[str, Any]) -> None:
701
701
del typ ["secondaryFiles" ]
702
702
703
703
704
- def hints_and_requirements_clean (document : Dict [str , Any ]) -> None :
704
+ def hints_and_requirements_clean (document : dict [str , Any ]) -> None :
705
705
"""Transform draft-3 style hints/reqs into idiomatic v1.0 hints/reqs."""
706
706
for section in ["hints" , "requirements" ]:
707
707
if section in document :
@@ -736,13 +736,13 @@ def hints_and_requirements_clean(document: Dict[str, Any]) -> None:
736
736
document [section ] = new_section
737
737
738
738
739
- def shorten_type (type_obj : Union [str , List [Any ]]) -> Union [str , List [Any ]]:
739
+ def shorten_type (type_obj : Union [str , list [Any ]]) -> Union [str , list [Any ]]:
740
740
"""Transform draft-3 style type declarations into idiomatic v1.0 types."""
741
741
if isinstance (type_obj , str ) or not isinstance (type_obj , Sequence ):
742
742
return type_obj
743
- new_type = [] # type: List[str ]
743
+ new_type : list [ str ] = [ ]
744
744
for entry in type_obj : # find arrays that we can shorten and do so
745
- if isinstance (entry , Dict ):
745
+ if isinstance (entry , dict ):
746
746
if entry ["type" ] == "array" and isinstance (entry ["items" ], str ):
747
747
entry = entry ["items" ] + "[]"
748
748
elif entry ["type" ] == "enum" :
@@ -759,7 +759,7 @@ def shorten_type(type_obj: Union[str, List[Any]]) -> Union[str, List[Any]]:
759
759
return new_type
760
760
761
761
762
- def clean_secondary_files (document : Dict [str , Any ]) -> None :
762
+ def clean_secondary_files (document : dict [str , Any ]) -> None :
763
763
"""Cleanup for secondaryFiles"""
764
764
if "secondaryFiles" in document :
765
765
for i , sfile in enumerate (document ["secondaryFiles" ]):
@@ -769,7 +769,7 @@ def clean_secondary_files(document: Dict[str, Any]) -> None:
769
769
).replace (".path" , ".location" )
770
770
771
771
772
- def sort_v1_0 (document : Dict [str , Any ]) -> CommentedMap :
772
+ def sort_v1_0 (document : dict [str , Any ]) -> CommentedMap :
773
773
"""Sort the sections of the CWL document in a more meaningful order."""
774
774
keyorder = [
775
775
"cwlVersion" ,
@@ -800,7 +800,7 @@ def sort_v1_0(document: Dict[str, Any]) -> CommentedMap:
800
800
)
801
801
802
802
803
- def sort_enum (enum : Dict [str , Any ]) -> Dict [str , Any ]:
803
+ def sort_enum (enum : dict [str , Any ]) -> dict [str , Any ]:
804
804
"""Sort the enum type definitions in a more meaningful order."""
805
805
keyorder = ["type" , "name" , "label" , "symbols" , "inputBinding" ]
806
806
return CommentedMap (
@@ -811,7 +811,7 @@ def sort_enum(enum: Dict[str, Any]) -> Dict[str, Any]:
811
811
)
812
812
813
813
814
- def sort_input_or_output (io_def : Dict [str , Any ]) -> Dict [str , Any ]:
814
+ def sort_input_or_output (io_def : dict [str , Any ]) -> dict [str , Any ]:
815
815
"""Sort the input definitions in a more meaningful order."""
816
816
keyorder = [
817
817
"label" ,
0 commit comments