Skip to content

Commit b6c8c8d

Browse files
authored
Merge pull request #15 from common-workflow-language/cleaner_wf_conv
improve workflow conversion
2 parents e0b6ef3 + 535bc63 commit b6c8c8d

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

cwlupgrader/main.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
from __future__ import print_function
44
import ruamel.yaml
5-
from typing import Any, Dict, List, Union
5+
from typing import Any, Dict, List, Text, Union
66
from collections import Mapping, MutableMapping, Sequence
77
import sys
88
import copy
99

1010
def main(): # type: () -> int
1111
for path in sys.argv[1:]:
1212
with open(path) as entry:
13-
document = ruamel.yaml.round_trip_load(entry)
13+
document = ruamel.yaml.load(entry)
1414
if ('cwlVersion' in document
1515
and document['cwlVersion'] == 'cwl:draft-3'):
1616
draft3_to_v1_0(document)
1717
else:
1818
print("Skipping non draft-3 CWL document", file=sys.stderr)
19-
print(ruamel.yaml.round_trip_dump(document))
19+
print(ruamel.yaml.dump(document))
2020
return 0
2121

2222
def draft3_to_v1_0(document): # type: (Dict[str, Any]) -> None
@@ -30,15 +30,23 @@ def _draft3_to_v1_0(document):
3030
inputOutputClean(document)
3131
for out in document["outputs"]:
3232
out["outputSource"] = out.pop("source").lstrip('#')
33+
new_steps = {}
3334
for step in document["steps"]:
34-
step["out"] = step.pop("outputs")
35+
new_step = {} # type: Dict[Text, Any]
36+
new_step["out"] = [ outp["id"][len(step["id"])+1:] for outp in
37+
step["outputs"] ]
38+
ins = {}
3539
for inp in step["inputs"]:
36-
inp["id"] = inp["id"][len(step["id"])+1:] # remove step id prefix
40+
ident = inp["id"][len(step["id"])+1:] # remove step id prefix
3741
inp["source"] = inp["source"].lstrip('#')
38-
step["in"] = step.pop("inputs")
42+
del inp["id"]
43+
ins[ident] = inp
44+
new_step["in"] = ins
3945
if "scatter" in step:
40-
step["scatter"] = step["scatter"][ # remove step prefix
46+
new_step["scatter"] = step["scatter"][ # remove step prefix
4147
len(step["id"])*2+3:]
48+
new_steps[step["id"].lstrip('#')] = new_step
49+
document["steps"] = new_steps
4250
elif document["class"] == "File":
4351
document["location"] = document.pop("path")
4452
elif document["class"] == "CreateFileRequirement":

0 commit comments

Comments
 (0)