Skip to content

Commit 61fc40a

Browse files
Typed CWL parsers
1 parent c4e10e3 commit 61fc40a

17 files changed

+7213
-6408
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ testenv*/
111111
# PyCharm
112112
.idea/
113113

114+
# UV
115+
uv.lock
116+
114117
# Backup files
115118
*.orig
116119
*~

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ def traverse_CommandLineTool(
12411241
"""Extract any CWL Expressions within the given CommandLineTool into sibling steps."""
12421242
modified = False
12431243
# don't modify clt, modify step.run
1244-
target_clt = step.run
1244+
target_clt = cast(cwl.CommandLineTool, step.run)
12451245
inputs = empty_inputs(clt)
12461246
if not step.id:
12471247
return False
@@ -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/cwl_v1_1_expression_refactor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ def traverse_CommandLineTool(
12431243
"""Extract any CWL Expressions within the given CommandLineTool into sibling steps."""
12441244
modified = False
12451245
# don't modify clt, modify step.run
1246-
target_clt = step.run
1246+
target_clt = cast(cwl.CommandLineTool, step.run)
12471247
inputs = empty_inputs(clt)
12481248
if not step.id:
12491249
return False

cwl_utils/cwl_v1_2_expression_refactor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ def traverse_CommandLineTool(
13461346
"""Extract any CWL Expressions within the given CommandLineTool into sibling steps."""
13471347
modified = False
13481348
# don't modify clt, modify step.run
1349-
target_clt = step.run
1349+
target_clt = cast(cwl.CommandLineTool, step.run)
13501350
inputs = empty_inputs(clt)
13511351
if not step.id:
13521352
return False

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)