Skip to content

Commit 6acba42

Browse files
authored
Merge pull request #12 from common-workflow-language/improve_wkflow_conversion
improve workflow conversion
2 parents d5018f3 + e475119 commit 6acba42

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

cwlupgrader/main.py

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

33
from __future__ import print_function
44
import ruamel.yaml
5-
from typing import Any, Dict, Union
5+
from typing import Any, Dict, List, Union
66
from collections import Mapping, MutableMapping, Sequence
77
import sys
88
import copy
@@ -27,12 +27,20 @@ def _draft3_to_v1_0(document):
2727
# type: (MutableMapping[str, Any]) -> MutableMapping[str, Any]
2828
if "class" in document:
2929
if document["class"] == "Workflow":
30+
inputOutputClean(document)
3031
for out in document["outputs"]:
31-
out["outputSource"] = out["source"]
32-
del out["source"]
32+
out["outputSource"] = out.pop("source").lstrip('#')
33+
for step in document["steps"]:
34+
step["out"] = step.pop("outputs")
35+
for inp in step["inputs"]:
36+
inp["id"] = inp["id"][len(step["id"])+1:] # remove step id prefix
37+
inp["source"] = inp["source"].lstrip('#')
38+
step["in"] = step.pop("inputs")
39+
if "scatter" in step:
40+
step["scatter"] = step["scatter"][ # remove step prefix
41+
len(step["id"])*2+3:]
3342
elif document["class"] == "File":
34-
document["location"] = document["path"]
35-
del document["path"]
43+
document["location"] = document.pop("path")
3644
elif document["class"] == "CreateFileRequirement":
3745
document["class"] = "InitialWorkDirRequirement"
3846
document["listing"] = []
@@ -43,7 +51,7 @@ def _draft3_to_v1_0(document):
4351
})
4452
del document["fileDef"]
4553
elif document["class"] == "CommandLineTool":
46-
setupCLTMappings(document)
54+
inputOutputClean(document)
4755

4856
if "secondaryFiles" in document:
4957
for i, sf in enumerate(document["secondaryFiles"]):
@@ -66,18 +74,12 @@ def _draft3_to_v1_0(document):
6674

6775
return document
6876

69-
def setupCLTMappings(document): # type: (MutableMapping[str, Any]) -> None
77+
def inputOutputClean(document): # type: (MutableMapping[str, Any]) -> None
7078
for paramType in ['inputs', 'outputs']:
71-
params = {}
7279
for param in document[paramType]:
73-
paramID = param['id'].lstrip('#')
74-
param['type'] = shortenType(param['type'])
75-
if len(param) == 2 and 'type' in param:
76-
params[paramID] = param['type']
77-
else:
78-
del param['id']
79-
params[paramID] = param
80-
document[paramType] = params
80+
param['id'] = param['id'].lstrip('#')
81+
if 'type' in param:
82+
param['type'] = shortenType(param['type'])
8183

8284
def shortenType(typeObj):
8385
# type: (List[Any]) -> Union[str, List[Any]]
@@ -99,5 +101,6 @@ def shortenType(typeObj):
99101
return typeCopy[0] + '?'
100102
return typeObj
101103

104+
102105
if __name__ == "__main__":
103106
sys.exit(main())

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ deps = -rrequirements.txt
1515
commands = make mypy
1616
whitelist_externals = make
1717
deps =
18-
mypy-lang>=0.4
18+
mypy>=0.4
1919
typed-ast
2020
-rrequirements.txt
2121

0 commit comments

Comments
 (0)