Skip to content

Commit cc747b2

Browse files
committed
move up loadContents everywhere
1 parent 93b027f commit cc747b2

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

cwlupgrader/main.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def _v1_0_to_v1_1(document):
103103
if "class" in document:
104104
if document['class'] == 'Workflow':
105105
upgrade_v1_0_hints_and_reqs(document)
106+
move_up_loadcontents(document)
106107
cleanup_v1_0_input_bindings(document)
107108
steps = document['steps']
108109
if isinstance(steps, MutableSequence):
@@ -113,6 +114,7 @@ def _v1_0_to_v1_1(document):
113114
upgrade_v1_0_hints_and_reqs(steps[step_name])
114115
elif document['class'] == 'CommandLineTool':
115116
upgrade_v1_0_hints_and_reqs(document)
117+
move_up_loadcontents(document)
116118
network_access = has_hint_or_req(document, "NetworkAccess")
117119
listing = has_hint_or_req(document, "LoadListingRequirement")
118120
if 'hints' in document:
@@ -127,17 +129,13 @@ def _v1_0_to_v1_1(document):
127129
if not listing:
128130
document['hints']["LoadListingRequirement"] = {"loadListing": "deep_listing"}
129131
elif document['class'] == 'ExpressionTool':
132+
move_up_loadcontents(document)
130133
cleanup_v1_0_input_bindings(document)
131134
return document
132135

133136

134137
def cleanup_v1_0_input_bindings(document):
135-
"""
136-
In v1.1 Workflow or ExpressionTool level inputBindings are no more.
137-
138-
'loadContents' is promoted up a level, the rest make no sense in v1.0, but document their contents anyways
139-
140-
"""
138+
"""In v1.1 Workflow or ExpressionTool level inputBindings are deprecated."""
141139
def cleanup(inp):
142140
"""Serialize non loadContents fields and add that to the doc."""
143141
if 'inputBinding' in inp:
@@ -147,8 +145,6 @@ def cleanup(inp):
147145
prefix = '' if 'doc' not in inp else '{}\n'.format(inp['doc'])
148146
inp['doc'] = WORKFLOW_INPUT_INPUTBINDING.format(prefix, field)
149147
del bindings[field]
150-
else:
151-
inp[field] = bindings.pop(field)
152148
if not bindings:
153149
del inp['inputBinding']
154150
inputs = document['inputs']
@@ -159,6 +155,24 @@ def cleanup(inp):
159155
for input_name in inputs:
160156
cleanup(inputs[input_name])
161157

158+
def move_up_loadcontents(document):
159+
"""'loadContents' is promoted up a level in CWL v1.1."""
160+
161+
def cleanup(inp):
162+
"""Move loadContents to the preferred location"""
163+
if 'inputBinding' in inp:
164+
bindings = inp["inputBinding"]
165+
for field in list(bindings.keys()):
166+
if field == "loadContents":
167+
inp[field] = bindings.pop(field)
168+
inputs = document['inputs']
169+
if isinstance(inputs, MutableSequence):
170+
for entry in inputs:
171+
cleanup(entry)
172+
elif isinstance(inputs, MutableMapping):
173+
for input_name in inputs:
174+
cleanup(inputs[input_name])
175+
162176

163177
def upgrade_v1_0_hints_and_reqs(document):
164178
for extra in ("requirements", "hints"):

0 commit comments

Comments
 (0)