Skip to content

Commit 20ea1d0

Browse files
Typed CWL parsers
1 parent c4e10e3 commit 20ea1d0

14 files changed

+7207
-6405
lines changed

cwl_utils/cite_extract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def main() -> int:
3333

3434

3535
def extract_software_reqs(
36-
process: cwl.Process,
36+
process: cwl.Process | cwl.WorkflowStep,
3737
) -> Iterator[cwl.SoftwareRequirement]:
3838
"""Return an iterator over any SoftwareRequirements found in the given process."""
3939
if process.requirements:

cwl_utils/cwl_v1_0_expression_refactor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,7 @@ def traverse_CommandLineTool(
14651465
inp.linkMerge = None
14661466
for index, out in enumerate(new_clt_step.out):
14671467
new_clt_step.out[index] = out.split("/")[-1]
1468+
14681469
for tool_inp in new_clt_step.run.inputs:
14691470
tool_inp.id = tool_inp.id.split("#")[-1]
14701471
for tool_out in new_clt_step.run.outputs:

cwl_utils/docker_extract.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def extract_docker_requirements(
102102
yield req
103103

104104

105-
def extract_docker_reqs(process: cwl.Process) -> Iterator[cwl.DockerRequirement]:
105+
def extract_docker_reqs(
106+
process: cwl.Process | cwl.WorkflowStep,
107+
) -> Iterator[cwl.DockerRequirement]:
106108
"""For the given process, extract the DockerRequirement(s)."""
107109
if process.requirements:
108110
for req in process.requirements:

cwl_utils/inputs_schema_gen.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from copy import deepcopy
1313
from importlib.resources import files
1414
from pathlib import Path
15-
from typing import Any, TypeGuard
15+
from typing import Any, TypeGuard, cast
1616
from urllib.parse import urlparse
1717

1818
import requests
@@ -26,6 +26,7 @@
2626
InputEnumSchema,
2727
InputRecordSchema,
2828
InputRecordSchemaTypes,
29+
SchemaDefRequirement,
2930
Workflow,
3031
WorkflowInputParameter,
3132
cwl_v1_0,
@@ -402,12 +403,15 @@ def get_complex_schema_values(idx_iter: str) -> InputRecordSchema:
402403

403404
if cwl_obj.requirements is not None:
404405
with suppress(StopIteration):
405-
schema_def_requirement = next(
406-
filter(
407-
lambda requirement_iter: requirement_iter.class_
408-
== "SchemaDefRequirement",
409-
cwl_obj.requirements,
410-
)
406+
schema_def_requirement = cast(
407+
SchemaDefRequirement,
408+
next(
409+
filter(
410+
lambda requirement_iter: requirement_iter.class_
411+
== "SchemaDefRequirement",
412+
cwl_obj.requirements,
413+
)
414+
),
411415
)
412416

413417
workflow_schema_definitions_list.extend(

cwl_utils/parser/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ class NoType(ABC):
238238
| cwl_v1_2.WorkflowStepInput
239239
)
240240
"""Type Union for a CWL v1.x LoadContents object."""
241+
SchemaDefRequirement: TypeAlias = (
242+
cwl_v1_0.SchemaDefRequirement
243+
| cwl_v1_1.SchemaDefRequirement
244+
| cwl_v1_2.SchemaDefRequirement
245+
)
246+
"""Type Union for a CWL v1.x SchemaDefRequirement object."""
241247
_Loader: TypeAlias = cwl_v1_0._Loader | cwl_v1_1._Loader | cwl_v1_2._Loader
242248
"""Type union for a CWL v1.x _Loader."""
243249

0 commit comments

Comments
 (0)