Skip to content

Commit

Permalink
Revert "Update utils & test to match renamed fields"
Browse files Browse the repository at this point in the history
This reverts commit 74d4e7a.
  • Loading branch information
mr-c committed Nov 13, 2023
1 parent 3491c8b commit a941a07
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 317 deletions.
4 changes: 2 additions & 2 deletions create_cwl_from_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

def main() -> None:
"""Generate a CWL object to match "cat-tool.cwl"."""
inputs = [cwl.CommandInputParameter(id="file1", type_="File")]
inputs = [cwl.CommandInputParameter(id="file1", type="File")]
outputs = [
cwl.CommandOutputParameter(
id="output",
type_="File",
type="File",
outputBinding=cwl.CommandOutputBinding(glob="output"),
)
]
Expand Down
120 changes: 58 additions & 62 deletions cwl_utils/cwl_v1_0_expression_refactor.py

Large diffs are not rendered by default.

114 changes: 55 additions & 59 deletions cwl_utils/cwl_v1_1_expression_refactor.py

Large diffs are not rendered by default.

132 changes: 62 additions & 70 deletions cwl_utils/cwl_v1_2_expression_refactor.py

Large diffs are not rendered by default.

52 changes: 25 additions & 27 deletions cwl_utils/parser/cwl_v1_0_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def _compare_records(
This handles normalizing record names, which will be relative to workflow
step, so that they can be compared.
"""
srcfields = {cwl.shortname(field.name): field.type_ for field in (src.fields or {})}
srcfields = {cwl.shortname(field.name): field.type for field in (src.fields or {})}
sinkfields = {
cwl.shortname(field.name): field.type_ for field in (sink.fields or {})
cwl.shortname(field.name): field.type for field in (sink.fields or {})
}
for key in sinkfields.keys():
if (
Expand Down Expand Up @@ -63,10 +63,10 @@ def _compare_type(type1: Any, type2: Any) -> bool:
return _compare_type(type1.items, type2.items)
elif isinstance(type1, cwl.RecordSchema) and isinstance(type2, cwl.RecordSchema):
fields1 = {
cwl.shortname(field.name): field.type_ for field in (type1.fields or {})
cwl.shortname(field.name): field.type for field in (type1.fields or {})
}
fields2 = {
cwl.shortname(field.name): field.type_ for field in (type2.fields or {})
cwl.shortname(field.name): field.type for field in (type2.fields or {})
}
if fields1.keys() != fields2.keys():
return False
Expand Down Expand Up @@ -184,7 +184,7 @@ def check_types(
return "exception"
if linkMerge == "merge_nested":
return check_types(
cwl.ArraySchema(items=srctype, type_="array"), sinktype, None, None
cwl.ArraySchema(items=srctype, type="array"), sinktype, None, None
)
if linkMerge == "merge_flattened":
return check_types(merge_flatten_type(srctype), sinktype, None, None)
Expand Down Expand Up @@ -212,7 +212,7 @@ def content_limit_respected_read(f: IO[bytes]) -> str:
def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
"""Convert stdout and stderr type shortcuts to files."""
for out in clt.outputs:
if out.type_ == "stdout":
if out.type == "stdout":
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stdout shortcut."
Expand All @@ -223,9 +223,9 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
json_dumps(clt.save(), sort_keys=True).encode("utf-8")
).hexdigest()
)
out.type_ = "File"
out.type = "File"
out.outputBinding = cwl.CommandOutputBinding(glob=clt.stdout)
elif out.type_ == "stderr":
elif out.type == "stderr":
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stderr shortcut."
Expand All @@ -236,7 +236,7 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
json_dumps(clt.save(), sort_keys=True).encode("utf-8")
).hexdigest()
)
out.type_ = "File"
out.type = "File"
out.outputBinding = cwl.CommandOutputBinding(glob=clt.stderr)


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


def type_for_step_input(
Expand All @@ -264,9 +264,9 @@ def type_for_step_input(
cast(str, step_input.id).split("#")[-1]
== cast(str, in_.id).split("#")[-1]
):
input_type = step_input.type_
input_type = step_input.type
if step.scatter is not None and in_.id in aslist(step.scatter):
input_type = cwl.ArraySchema(items=input_type, type_="array")
input_type = cwl.ArraySchema(items=input_type, type="array")
return input_type
return "Any"

Expand All @@ -284,15 +284,15 @@ def type_for_step_output(
step_output.id.split("#")[-1].split("/")[-1]
== sourcename.split("#")[-1].split("/")[-1]
):
output_type = step_output.type_
output_type = step_output.type
if step.scatter is not None:
if step.scatterMethod == "nested_crossproduct":
for _ in range(len(aslist(step.scatter))):
output_type = cwl.ArraySchema(
items=output_type, type_="array"
items=output_type, type="array"
)
else:
output_type = cwl.ArraySchema(items=output_type, type_="array")
output_type = cwl.ArraySchema(items=output_type, type="array")
return output_type
raise ValidationException(
"param {} not found in {}.".format(
Expand All @@ -312,44 +312,42 @@ def type_for_source(
scatter_context: List[Optional[Tuple[int, str]]] = []
params = param_for_source_id(process, sourcenames, parent, scatter_context)
if not isinstance(params, list):
new_type = params.type_
new_type = params.type
if scatter_context[0] is not None:
if scatter_context[0][1] == "nested_crossproduct":
for _ in range(scatter_context[0][0]):
new_type = cwl.ArraySchema(items=new_type, type_="array")
new_type = cwl.ArraySchema(items=new_type, type="array")
else:
new_type = cwl.ArraySchema(items=new_type, type_="array")
new_type = cwl.ArraySchema(items=new_type, type="array")
if linkMerge == "merge_nested":
new_type = cwl.ArraySchema(items=new_type, type_="array")
new_type = cwl.ArraySchema(items=new_type, type="array")
elif linkMerge == "merge_flattened":
new_type = merge_flatten_type(new_type)
return new_type
new_type = []
for p, sc in zip(params, scatter_context):
if isinstance(p, str) and not any(_compare_type(t, p) for t in new_type):
cur_type = p
elif hasattr(p, "type_") and not any(
_compare_type(t, p.type_) for t in new_type
):
cur_type = p.type_
elif hasattr(p, "type") and not any(_compare_type(t, p.type) for t in new_type):
cur_type = p.type
else:
cur_type = None
if cur_type is not None:
if sc is not None:
if sc[1] == "nested_crossproduct":
for _ in range(sc[0]):
cur_type = cwl.ArraySchema(items=cur_type, type_="array")
cur_type = cwl.ArraySchema(items=cur_type, type="array")
else:
cur_type = cwl.ArraySchema(items=cur_type, type_="array")
cur_type = cwl.ArraySchema(items=cur_type, type="array")
new_type.append(cur_type)
if len(new_type) == 1:
new_type = new_type[0]
if linkMerge == "merge_nested":
return cwl.ArraySchema(items=new_type, type_="array")
return cwl.ArraySchema(items=new_type, type="array")
elif linkMerge == "merge_flattened":
return merge_flatten_type(new_type)
elif isinstance(sourcenames, List) and len(sourcenames) > 1:
return cwl.ArraySchema(items=new_type, type_="array")
return cwl.ArraySchema(items=new_type, type="array")
else:
return new_type

Expand Down
56 changes: 27 additions & 29 deletions cwl_utils/parser/cwl_v1_1_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def _compare_records(
This handles normalizing record names, which will be relative to workflow
step, so that they can be compared.
"""
srcfields = {cwl.shortname(field.name): field.type_ for field in (src.fields or {})}
srcfields = {cwl.shortname(field.name): field.type for field in (src.fields or {})}
sinkfields = {
cwl.shortname(field.name): field.type_ for field in (sink.fields or {})
cwl.shortname(field.name): field.type for field in (sink.fields or {})
}
for key in sinkfields.keys():
if (
Expand Down Expand Up @@ -63,10 +63,10 @@ def _compare_type(type1: Any, type2: Any) -> bool:
return _compare_type(type1.items, type2.items)
elif isinstance(type1, cwl.RecordSchema) and isinstance(type2, cwl.RecordSchema):
fields1 = {
cwl.shortname(field.name): field.type_ for field in (type1.fields or {})
cwl.shortname(field.name): field.type for field in (type1.fields or {})
}
fields2 = {
cwl.shortname(field.name): field.type_ for field in (type2.fields or {})
cwl.shortname(field.name): field.type for field in (type2.fields or {})
}
if fields1.keys() != fields2.keys():
return False
Expand Down Expand Up @@ -184,7 +184,7 @@ def check_types(
return "exception"
if linkMerge == "merge_nested":
return check_types(
cwl.ArraySchema(items=srctype, type_="array"), sinktype, None, None
cwl.ArraySchema(items=srctype, type="array"), sinktype, None, None
)
if linkMerge == "merge_flattened":
return check_types(merge_flatten_type(srctype), sinktype, None, None)
Expand Down Expand Up @@ -212,7 +212,7 @@ def content_limit_respected_read(f: IO[bytes]) -> str:
def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
"""Convert stdin, stdout and stderr type shortcuts to files."""
for out in clt.outputs:
if out.type_ == "stdout":
if out.type == "stdout":
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stdout shortcut."
Expand All @@ -223,9 +223,9 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
json_dumps(clt.save(), sort_keys=True).encode("utf-8")
).hexdigest()
)
out.type_ = "File"
out.type = "File"
out.outputBinding = cwl.CommandOutputBinding(glob=clt.stdout)
elif out.type_ == "stderr":
elif out.type == "stderr":
if out.outputBinding is not None:
raise ValidationException(
"Not allowed to specify outputBinding when using stderr shortcut."
Expand All @@ -236,10 +236,10 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
json_dumps(clt.save(), sort_keys=True).encode("utf-8")
).hexdigest()
)
out.type_ = "File"
out.type = "File"
out.outputBinding = cwl.CommandOutputBinding(glob=clt.stderr)
for inp in clt.inputs:
if inp.type_ == "stdin":
if inp.type == "stdin":
if inp.inputBinding is not None:
raise ValidationException(
"Not allowed to specify unputBinding when using stdin shortcut."
Expand All @@ -253,7 +253,7 @@ def convert_stdstreams_to_files(clt: cwl.CommandLineTool) -> None:
"$(inputs.%s.path)"
% cast(str, inp.id).rpartition("#")[2].split("/")[-1]
)
inp.type_ = "File"
inp.type = "File"


def merge_flatten_type(src: Any) -> Any:
Expand All @@ -262,7 +262,7 @@ def merge_flatten_type(src: Any) -> Any:
return [merge_flatten_type(t) for t in src]
if isinstance(src, cwl.ArraySchema):
return src
return cwl.ArraySchema(type_="array", items=src)
return cwl.ArraySchema(type="array", items=src)


def type_for_step_input(
Expand All @@ -280,9 +280,9 @@ def type_for_step_input(
cast(str, step_input.id).split("#")[-1]
== cast(str, in_.id).split("#")[-1]
):
input_type = step_input.type_
input_type = step_input.type
if step.scatter is not None and in_.id in aslist(step.scatter):
input_type = cwl.ArraySchema(items=input_type, type_="array")
input_type = cwl.ArraySchema(items=input_type, type="array")
return input_type
return "Any"

Expand All @@ -300,15 +300,15 @@ def type_for_step_output(
output.id.split("#")[-1].split("/")[-1]
== sourcename.split("#")[-1].split("/")[-1]
):
output_type = output.type_
output_type = output.type
if step.scatter is not None:
if step.scatterMethod == "nested_crossproduct":
for _ in range(len(aslist(step.scatter))):
output_type = cwl.ArraySchema(
items=output_type, type_="array"
items=output_type, type="array"
)
else:
output_type = cwl.ArraySchema(items=output_type, type_="array")
output_type = cwl.ArraySchema(items=output_type, type="array")
return output_type
raise ValidationException(
"param {} not found in {}.".format(
Expand All @@ -328,44 +328,42 @@ def type_for_source(
scatter_context: List[Optional[Tuple[int, str]]] = []
params = param_for_source_id(process, sourcenames, parent, scatter_context)
if not isinstance(params, list):
new_type = params.type_
new_type = params.type
if scatter_context[0] is not None:
if scatter_context[0][1] == "nested_crossproduct":
for _ in range(scatter_context[0][0]):
new_type = cwl.ArraySchema(items=new_type, type_="array")
new_type = cwl.ArraySchema(items=new_type, type="array")
else:
new_type = cwl.ArraySchema(items=new_type, type_="array")
new_type = cwl.ArraySchema(items=new_type, type="array")
if linkMerge == "merge_nested":
new_type = cwl.ArraySchema(items=new_type, type_="array")
new_type = cwl.ArraySchema(items=new_type, type="array")
elif linkMerge == "merge_flattened":
new_type = merge_flatten_type(new_type)
return new_type
new_type = []
for p, sc in zip(params, scatter_context):
if isinstance(p, str) and not any(_compare_type(t, p) for t in new_type):
cur_type = p
elif hasattr(p, "type_") and not any(
_compare_type(t, p.type_) for t in new_type
):
cur_type = p.type_
elif hasattr(p, "type") and not any(_compare_type(t, p.type) for t in new_type):
cur_type = p.type
else:
cur_type = None
if cur_type is not None:
if sc is not None:
if sc[1] == "nested_crossproduct":
for _ in range(sc[0]):
cur_type = cwl.ArraySchema(items=cur_type, type_="array")
cur_type = cwl.ArraySchema(items=cur_type, type="array")
else:
cur_type = cwl.ArraySchema(items=cur_type, type_="array")
cur_type = cwl.ArraySchema(items=cur_type, type="array")
new_type.append(cur_type)
if len(new_type) == 1:
new_type = new_type[0]
if linkMerge == "merge_nested":
return cwl.ArraySchema(items=new_type, type_="array")
return cwl.ArraySchema(items=new_type, type="array")
elif linkMerge == "merge_flattened":
return merge_flatten_type(new_type)
elif isinstance(sourcenames, List) and len(sourcenames) > 1:
return cwl.ArraySchema(items=new_type, type_="array")
return cwl.ArraySchema(items=new_type, type="array")
else:
return new_type

Expand Down
Loading

0 comments on commit a941a07

Please sign in to comment.