Skip to content

Commit 74d4e7a

Browse files
committed
Update utils & test to match renamed fields
1 parent 73d9f56 commit 74d4e7a

9 files changed

+317
-295
lines changed

create_cwl_from_objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
def main() -> None:
1111
"""Generate a CWL object to match "cat-tool.cwl"."""
12-
inputs = [cwl.CommandInputParameter(id="file1", type="File")]
12+
inputs = [cwl.CommandInputParameter(id="file1", type_="File")]
1313
outputs = [
1414
cwl.CommandOutputParameter(
1515
id="output",
16-
type="File",
16+
type_="File",
1717
outputBinding=cwl.CommandOutputBinding(glob="output"),
1818
)
1919
]

cwl_utils/cwl_v1_0_expression_refactor.py

Lines changed: 62 additions & 58 deletions
Large diffs are not rendered by default.

cwl_utils/cwl_v1_1_expression_refactor.py

Lines changed: 59 additions & 55 deletions
Large diffs are not rendered by default.

cwl_utils/cwl_v1_2_expression_refactor.py

Lines changed: 70 additions & 62 deletions
Large diffs are not rendered by default.

cwl_utils/parser/cwl_v1_0_utils.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def _compare_records(
3030
This handles normalizing record names, which will be relative to workflow
3131
step, so that they can be compared.
3232
"""
33-
srcfields = {cwl.shortname(field.name): field.type for field in (src.fields or {})}
33+
srcfields = {cwl.shortname(field.name): field.type_ for field in (src.fields or {})}
3434
sinkfields = {
35-
cwl.shortname(field.name): field.type for field in (sink.fields or {})
35+
cwl.shortname(field.name): field.type_ for field in (sink.fields or {})
3636
}
3737
for key in sinkfields.keys():
3838
if (
@@ -63,10 +63,10 @@ def _compare_type(type1: Any, type2: Any) -> bool:
6363
return _compare_type(type1.items, type2.items)
6464
elif isinstance(type1, cwl.RecordSchema) and isinstance(type2, cwl.RecordSchema):
6565
fields1 = {
66-
cwl.shortname(field.name): field.type for field in (type1.fields or {})
66+
cwl.shortname(field.name): field.type_ for field in (type1.fields or {})
6767
}
6868
fields2 = {
69-
cwl.shortname(field.name): field.type for field in (type2.fields or {})
69+
cwl.shortname(field.name): field.type_ for field in (type2.fields or {})
7070
}
7171
if fields1.keys() != fields2.keys():
7272
return False
@@ -184,7 +184,7 @@ def check_types(
184184
return "exception"
185185
if linkMerge == "merge_nested":
186186
return check_types(
187-
cwl.ArraySchema(items=srctype, type="array"), sinktype, None, None
187+
cwl.ArraySchema(items=srctype, type_="array"), sinktype, None, None
188188
)
189189
if linkMerge == "merge_flattened":
190190
return check_types(merge_flatten_type(srctype), sinktype, None, None)
@@ -212,7 +212,7 @@ def content_limit_respected_read(f: IO[bytes]) -> str:
212212
def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
213213
"""Convert stdout and stderr type shortcuts to files."""
214214
for out in clt.outputs:
215-
if out.type == "stdout":
215+
if out.type_ == "stdout":
216216
if out.outputBinding is not None:
217217
raise ValidationException(
218218
"Not allowed to specify outputBinding when using stdout shortcut."
@@ -223,9 +223,9 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
223223
json_dumps(clt.save(), sort_keys=True).encode("utf-8")
224224
).hexdigest()
225225
)
226-
out.type = "File"
226+
out.type_ = "File"
227227
out.outputBinding = cwl.CommandOutputBinding(glob=clt.stdout)
228-
elif out.type == "stderr":
228+
elif out.type_ == "stderr":
229229
if out.outputBinding is not None:
230230
raise ValidationException(
231231
"Not allowed to specify outputBinding when using stderr shortcut."
@@ -236,7 +236,7 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
236236
json_dumps(clt.save(), sort_keys=True).encode("utf-8")
237237
).hexdigest()
238238
)
239-
out.type = "File"
239+
out.type_ = "File"
240240
out.outputBinding = cwl.CommandOutputBinding(glob=clt.stderr)
241241

242242

@@ -246,7 +246,7 @@ def merge_flatten_type(src: Any) -> Any:
246246
return [merge_flatten_type(t) for t in src]
247247
if isinstance(src, cwl.ArraySchema):
248248
return src
249-
return cwl.ArraySchema(type="array", items=src)
249+
return cwl.ArraySchema(type_="array", items=src)
250250

251251

252252
def type_for_step_input(
@@ -264,9 +264,9 @@ def type_for_step_input(
264264
cast(str, step_input.id).split("#")[-1]
265265
== cast(str, in_.id).split("#")[-1]
266266
):
267-
input_type = step_input.type
267+
input_type = step_input.type_
268268
if step.scatter is not None and in_.id in aslist(step.scatter):
269-
input_type = cwl.ArraySchema(items=input_type, type="array")
269+
input_type = cwl.ArraySchema(items=input_type, type_="array")
270270
return input_type
271271
return "Any"
272272

@@ -284,15 +284,15 @@ def type_for_step_output(
284284
step_output.id.split("#")[-1].split("/")[-1]
285285
== sourcename.split("#")[-1].split("/")[-1]
286286
):
287-
output_type = step_output.type
287+
output_type = step_output.type_
288288
if step.scatter is not None:
289289
if step.scatterMethod == "nested_crossproduct":
290290
for _ in range(len(aslist(step.scatter))):
291291
output_type = cwl.ArraySchema(
292-
items=output_type, type="array"
292+
items=output_type, type_="array"
293293
)
294294
else:
295-
output_type = cwl.ArraySchema(items=output_type, type="array")
295+
output_type = cwl.ArraySchema(items=output_type, type_="array")
296296
return output_type
297297
raise ValidationException(
298298
"param {} not found in {}.".format(
@@ -312,42 +312,44 @@ def type_for_source(
312312
scatter_context: List[Optional[Tuple[int, str]]] = []
313313
params = param_for_source_id(process, sourcenames, parent, scatter_context)
314314
if not isinstance(params, list):
315-
new_type = params.type
315+
new_type = params.type_
316316
if scatter_context[0] is not None:
317317
if scatter_context[0][1] == "nested_crossproduct":
318318
for _ in range(scatter_context[0][0]):
319-
new_type = cwl.ArraySchema(items=new_type, type="array")
319+
new_type = cwl.ArraySchema(items=new_type, type_="array")
320320
else:
321-
new_type = cwl.ArraySchema(items=new_type, type="array")
321+
new_type = cwl.ArraySchema(items=new_type, type_="array")
322322
if linkMerge == "merge_nested":
323-
new_type = cwl.ArraySchema(items=new_type, type="array")
323+
new_type = cwl.ArraySchema(items=new_type, type_="array")
324324
elif linkMerge == "merge_flattened":
325325
new_type = merge_flatten_type(new_type)
326326
return new_type
327327
new_type = []
328328
for p, sc in zip(params, scatter_context):
329329
if isinstance(p, str) and not any(_compare_type(t, p) for t in new_type):
330330
cur_type = p
331-
elif hasattr(p, "type") and not any(_compare_type(t, p.type) for t in new_type):
332-
cur_type = p.type
331+
elif hasattr(p, "type_") and not any(
332+
_compare_type(t, p.type_) for t in new_type
333+
):
334+
cur_type = p.type_
333335
else:
334336
cur_type = None
335337
if cur_type is not None:
336338
if sc is not None:
337339
if sc[1] == "nested_crossproduct":
338340
for _ in range(sc[0]):
339-
cur_type = cwl.ArraySchema(items=cur_type, type="array")
341+
cur_type = cwl.ArraySchema(items=cur_type, type_="array")
340342
else:
341-
cur_type = cwl.ArraySchema(items=cur_type, type="array")
343+
cur_type = cwl.ArraySchema(items=cur_type, type_="array")
342344
new_type.append(cur_type)
343345
if len(new_type) == 1:
344346
new_type = new_type[0]
345347
if linkMerge == "merge_nested":
346-
return cwl.ArraySchema(items=new_type, type="array")
348+
return cwl.ArraySchema(items=new_type, type_="array")
347349
elif linkMerge == "merge_flattened":
348350
return merge_flatten_type(new_type)
349351
elif isinstance(sourcenames, List) and len(sourcenames) > 1:
350-
return cwl.ArraySchema(items=new_type, type="array")
352+
return cwl.ArraySchema(items=new_type, type_="array")
351353
else:
352354
return new_type
353355

cwl_utils/parser/cwl_v1_1_utils.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def _compare_records(
3030
This handles normalizing record names, which will be relative to workflow
3131
step, so that they can be compared.
3232
"""
33-
srcfields = {cwl.shortname(field.name): field.type for field in (src.fields or {})}
33+
srcfields = {cwl.shortname(field.name): field.type_ for field in (src.fields or {})}
3434
sinkfields = {
35-
cwl.shortname(field.name): field.type for field in (sink.fields or {})
35+
cwl.shortname(field.name): field.type_ for field in (sink.fields or {})
3636
}
3737
for key in sinkfields.keys():
3838
if (
@@ -63,10 +63,10 @@ def _compare_type(type1: Any, type2: Any) -> bool:
6363
return _compare_type(type1.items, type2.items)
6464
elif isinstance(type1, cwl.RecordSchema) and isinstance(type2, cwl.RecordSchema):
6565
fields1 = {
66-
cwl.shortname(field.name): field.type for field in (type1.fields or {})
66+
cwl.shortname(field.name): field.type_ for field in (type1.fields or {})
6767
}
6868
fields2 = {
69-
cwl.shortname(field.name): field.type for field in (type2.fields or {})
69+
cwl.shortname(field.name): field.type_ for field in (type2.fields or {})
7070
}
7171
if fields1.keys() != fields2.keys():
7272
return False
@@ -184,7 +184,7 @@ def check_types(
184184
return "exception"
185185
if linkMerge == "merge_nested":
186186
return check_types(
187-
cwl.ArraySchema(items=srctype, type="array"), sinktype, None, None
187+
cwl.ArraySchema(items=srctype, type_="array"), sinktype, None, None
188188
)
189189
if linkMerge == "merge_flattened":
190190
return check_types(merge_flatten_type(srctype), sinktype, None, None)
@@ -212,7 +212,7 @@ def content_limit_respected_read(f: IO[bytes]) -> str:
212212
def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
213213
"""Convert stdin, stdout and stderr type shortcuts to files."""
214214
for out in clt.outputs:
215-
if out.type == "stdout":
215+
if out.type_ == "stdout":
216216
if out.outputBinding is not None:
217217
raise ValidationException(
218218
"Not allowed to specify outputBinding when using stdout shortcut."
@@ -223,9 +223,9 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
223223
json_dumps(clt.save(), sort_keys=True).encode("utf-8")
224224
).hexdigest()
225225
)
226-
out.type = "File"
226+
out.type_ = "File"
227227
out.outputBinding = cwl.CommandOutputBinding(glob=clt.stdout)
228-
elif out.type == "stderr":
228+
elif out.type_ == "stderr":
229229
if out.outputBinding is not None:
230230
raise ValidationException(
231231
"Not allowed to specify outputBinding when using stderr shortcut."
@@ -236,10 +236,10 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
236236
json_dumps(clt.save(), sort_keys=True).encode("utf-8")
237237
).hexdigest()
238238
)
239-
out.type = "File"
239+
out.type_ = "File"
240240
out.outputBinding = cwl.CommandOutputBinding(glob=clt.stderr)
241241
for inp in clt.inputs:
242-
if inp.type == "stdin":
242+
if inp.type_ == "stdin":
243243
if inp.inputBinding is not None:
244244
raise ValidationException(
245245
"Not allowed to specify unputBinding when using stdin shortcut."
@@ -253,7 +253,7 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
253253
"$(inputs.%s.path)"
254254
% cast(str, inp.id).rpartition("#")[2].split("/")[-1]
255255
)
256-
inp.type = "File"
256+
inp.type_ = "File"
257257

258258

259259
def merge_flatten_type(src: Any) -> Any:
@@ -262,7 +262,7 @@ def merge_flatten_type(src: Any) -> Any:
262262
return [merge_flatten_type(t) for t in src]
263263
if isinstance(src, cwl.ArraySchema):
264264
return src
265-
return cwl.ArraySchema(type="array", items=src)
265+
return cwl.ArraySchema(type_="array", items=src)
266266

267267

268268
def type_for_step_input(
@@ -280,9 +280,9 @@ def type_for_step_input(
280280
cast(str, step_input.id).split("#")[-1]
281281
== cast(str, in_.id).split("#")[-1]
282282
):
283-
input_type = step_input.type
283+
input_type = step_input.type_
284284
if step.scatter is not None and in_.id in aslist(step.scatter):
285-
input_type = cwl.ArraySchema(items=input_type, type="array")
285+
input_type = cwl.ArraySchema(items=input_type, type_="array")
286286
return input_type
287287
return "Any"
288288

@@ -300,15 +300,15 @@ def type_for_step_output(
300300
output.id.split("#")[-1].split("/")[-1]
301301
== sourcename.split("#")[-1].split("/")[-1]
302302
):
303-
output_type = output.type
303+
output_type = output.type_
304304
if step.scatter is not None:
305305
if step.scatterMethod == "nested_crossproduct":
306306
for _ in range(len(aslist(step.scatter))):
307307
output_type = cwl.ArraySchema(
308-
items=output_type, type="array"
308+
items=output_type, type_="array"
309309
)
310310
else:
311-
output_type = cwl.ArraySchema(items=output_type, type="array")
311+
output_type = cwl.ArraySchema(items=output_type, type_="array")
312312
return output_type
313313
raise ValidationException(
314314
"param {} not found in {}.".format(
@@ -328,42 +328,44 @@ def type_for_source(
328328
scatter_context: List[Optional[Tuple[int, str]]] = []
329329
params = param_for_source_id(process, sourcenames, parent, scatter_context)
330330
if not isinstance(params, list):
331-
new_type = params.type
331+
new_type = params.type_
332332
if scatter_context[0] is not None:
333333
if scatter_context[0][1] == "nested_crossproduct":
334334
for _ in range(scatter_context[0][0]):
335-
new_type = cwl.ArraySchema(items=new_type, type="array")
335+
new_type = cwl.ArraySchema(items=new_type, type_="array")
336336
else:
337-
new_type = cwl.ArraySchema(items=new_type, type="array")
337+
new_type = cwl.ArraySchema(items=new_type, type_="array")
338338
if linkMerge == "merge_nested":
339-
new_type = cwl.ArraySchema(items=new_type, type="array")
339+
new_type = cwl.ArraySchema(items=new_type, type_="array")
340340
elif linkMerge == "merge_flattened":
341341
new_type = merge_flatten_type(new_type)
342342
return new_type
343343
new_type = []
344344
for p, sc in zip(params, scatter_context):
345345
if isinstance(p, str) and not any(_compare_type(t, p) for t in new_type):
346346
cur_type = p
347-
elif hasattr(p, "type") and not any(_compare_type(t, p.type) for t in new_type):
348-
cur_type = p.type
347+
elif hasattr(p, "type_") and not any(
348+
_compare_type(t, p.type_) for t in new_type
349+
):
350+
cur_type = p.type_
349351
else:
350352
cur_type = None
351353
if cur_type is not None:
352354
if sc is not None:
353355
if sc[1] == "nested_crossproduct":
354356
for _ in range(sc[0]):
355-
cur_type = cwl.ArraySchema(items=cur_type, type="array")
357+
cur_type = cwl.ArraySchema(items=cur_type, type_="array")
356358
else:
357-
cur_type = cwl.ArraySchema(items=cur_type, type="array")
359+
cur_type = cwl.ArraySchema(items=cur_type, type_="array")
358360
new_type.append(cur_type)
359361
if len(new_type) == 1:
360362
new_type = new_type[0]
361363
if linkMerge == "merge_nested":
362-
return cwl.ArraySchema(items=new_type, type="array")
364+
return cwl.ArraySchema(items=new_type, type_="array")
363365
elif linkMerge == "merge_flattened":
364366
return merge_flatten_type(new_type)
365367
elif isinstance(sourcenames, List) and len(sourcenames) > 1:
366-
return cwl.ArraySchema(items=new_type, type="array")
368+
return cwl.ArraySchema(items=new_type, type_="array")
367369
else:
368370
return new_type
369371

0 commit comments

Comments
 (0)