Skip to content

Commit 4841219

Browse files
committed
improve workflow conversion
1 parent d5018f3 commit 4841219

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

cwlupgrader/main.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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())

0 commit comments

Comments
 (0)