@@ -42,6 +42,7 @@ def parse_args(args: List[str]) -> argparse.Namespace:
4242
4343
4444def main (args : Optional [List [str ]] = None ) -> int :
45+ """Hook to set the args."""
4546 if not args :
4647 args = sys .argv [1 :]
4748 return run (parse_args (args ))
@@ -75,6 +76,12 @@ def run(args: argparse.Namespace) -> int:
7576
7677
7778def load_cwl_document (path : str ) -> Any :
79+ """
80+ Load the given path using the Ruamel YAML round-trip loader.
81+
82+ Also ensures that the filename is recorded so that SourceLine can produce
83+ informative error messages.
84+ """
7885 yaml = ruamel .yaml .main .YAML (typ = "rt" )
7986 yaml .allow_duplicate_keys = True
8087 yaml .preserve_quotes = True # type: ignore
@@ -85,6 +92,12 @@ def load_cwl_document(path: str) -> Any:
8592
8693
8794def write_cwl_document (document : Any , name : str , dirname : str ) -> None :
95+ """
96+ Serialize the document using the Ruamel YAML round trip dumper.
97+
98+ Will also prepend "#!/usr/bin/env cwl-runner\n " and
99+ set the executable bit if it is a CWL document.
100+ """
88101 ruamel .yaml .scalarstring .walk_tree (document )
89102 path = Path (dirname ) / name
90103 with open (path , "w" ) as handle :
@@ -100,6 +113,7 @@ def write_cwl_document(document: Any, name: str, dirname: str) -> None:
100113def process_imports (
101114 document : Any , imports : Set [str ], updater : Callable [[Any , str ], Any ], outdir : str
102115) -> None :
116+ """Find any '$import's and process them."""
103117 if isinstance (document , CommentedMap ):
104118 for key , value in document .items ():
105119 if key == "$import" :
@@ -309,6 +323,7 @@ def cleanup(inp: Dict[str, Any]) -> None:
309323
310324
311325def upgrade_v1_0_hints_and_reqs (document : Dict [str , Any ]) -> None :
326+ """Rename some pre-v1.1 extensions to their official CWL v1.1 names."""
312327 for extra in ("requirements" , "hints" ):
313328 if extra in document :
314329 with SourceLine (document , extra , Exception ):
@@ -392,9 +407,9 @@ def workflow_clean(document: Dict[str, Any]) -> None:
392407 inp ["source" ].lstrip ("#" ).replace ("." , "/" )
393408 )
394409 else :
395- for index , inp_source in enumerate (inp ["source" ]):
396- with SourceLine (inp ["source" ], index , Exception ):
397- inp ["source" ][index ] = inp_source .lstrip (
410+ for index4 , inp_source in enumerate (inp ["source" ]):
411+ with SourceLine (inp ["source" ], index4 , Exception ):
412+ inp ["source" ][index4 ] = inp_source .lstrip (
398413 "#"
399414 ).replace ("." , "/" )
400415 del inp ["id" ]
0 commit comments