Skip to content

Commit 4b64365

Browse files
committed
more docs
1 parent 7b31e4e commit 4b64365

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

cwlupgrader/main.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def parse_args(args: List[str]) -> argparse.Namespace:
4242

4343

4444
def 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

7778
def 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

8794
def 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:
100113
def 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

311325
def 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"]

tests/test_complete.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77

88
def test_draft3_workflow(tmp_path):
9-
main([f"--dir={tmp_path}", get_data('tests/draft-3-wf.cwl')])
9+
"""Basic draft3 to CWL v1.1 test."""
10+
main([f"--dir={tmp_path}", "--v1-only", get_data('tests/draft-3-wf.cwl')])
1011
result = filecmp.cmp(get_data('tests/draft-3-wf-v1.0.cwl'), tmp_path/"draft-3-wf.cwl",
1112
shallow=False)
1213
assert result

0 commit comments

Comments
 (0)