Skip to content

Commit 4a53edb

Browse files
Make parsers inherit from schema_salad.metaschema
This commit regenerates CWL parsers by making them inherit from the `schema_salad.metaschema` package, ensuring that different CWL versions share common ancestors in their class hierarchies. BREAKING CHANGE: parsers do not inherit from cwltool extensions anymore. If you want to use CWL extensions within your project, you have to generate your own parsers.
1 parent 238ef0f commit 4a53edb

37 files changed

Lines changed: 33193 additions & 44552 deletions

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,22 @@ flake8: FORCE
194194
cwl_utils/parser/cwl_v1_0.py: FORCE
195195
schema-salad-tool --codegen python \
196196
--codegen-parser-info "org.w3id.cwl.v1_0" \
197-
https://github.com/common-workflow-language/common-workflow-language/raw/codegen/v1.0/extensions.yml \
197+
--codegen-parent "https://w3id.org/cwl/salad=schema_salad.metaschema" \
198+
https://github.com/common-workflow-language/common-workflow-language/raw/codegen/v1.0/CommonWorkflowLanguage.yml \
198199
> $@
199200

200201
cwl_utils/parser/cwl_v1_1.py: FORCE
201202
schema-salad-tool --codegen python \
202203
--codegen-parser-info "org.w3id.cwl.v1_1" \
203-
https://github.com/common-workflow-language/cwl-v1.1/raw/codegen/extensions.yml \
204+
--codegen-parent "https://w3id.org/cwl/salad=schema_salad.metaschema" \
205+
https://github.com/common-workflow-language/cwl-v1.1/raw/codegen/CommonWorkflowLanguage.yml \
204206
> $@
205207

206208
cwl_utils/parser/cwl_v1_2.py: FORCE
207209
schema-salad-tool --codegen python \
208210
--codegen-parser-info "org.w3id.cwl.v1_2" \
209-
https://github.com/common-workflow-language/cwl-v1.2/raw/codegen/extensions.yml \
211+
--codegen-parent "https://w3id.org/cwl/salad=schema_salad.metaschema" \
212+
https://github.com/common-workflow-language/cwl-v1.2/raw/codegen/CommonWorkflowLanguage.yml \
210213
> $@
211214

212215
regen_parsers: cwl_utils/parser/cwl_v1_*.py

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ Regenerate parsers
160160
To regenerate install the ``schema_salad`` package and run:
161161

162162
``cwl_utils/parser/cwl_v1_0.py`` was created via
163-
``schema-salad-tool --codegen python https://github.com/common-workflow-language/common-workflow-language/raw/codegen/v1.0/extensions.yml --codegen-parser-info "org.w3id.cwl.v1_0" > cwl_utils/parser/cwl_v1_0.py``
163+
``schema-salad-tool --codegen python https://github.com/common-workflow-language/common-workflow-language/raw/codegen/v1.0/CommonWorkflowLanguage.yml --codegen-parent "https://w3id.org/cwl/salad=schema_salad.metaschema" --codegen-parser-info "org.w3id.cwl.v1_0" > cwl_utils/parser/cwl_v1_0.py``
164164

165165
``cwl_utils/parser/cwl_v1_1.py`` was created via
166-
``schema-salad-tool --codegen python https://github.com/common-workflow-language/cwl-v1.1/raw/codegen/extensions.yml --codegen-parser-info "org.w3id.cwl.v1_1" > cwl_utils/parser/cwl_v1_1.py``
166+
``schema-salad-tool --codegen python https://github.com/common-workflow-language/cwl-v1.1/raw/codegen/CommonWorkflowLanguage.yml --codegen-parent "https://w3id.org/cwl/salad=schema_salad.metaschema" --codegen-parser-info "org.w3id.cwl.v1_1" > cwl_utils/parser/cwl_v1_1.py``
167167

168168
``cwl_utils/parser/cwl_v1_2.py`` was created via
169-
``schema-salad-tool --codegen python https://github.com/common-workflow-language/cwl-v1.2/raw/codegen/extensions.yml --codegen-parser-info "org.w3id.cwl.v1_2" > cwl_utils/parser/cwl_v1_2.py``
169+
``schema-salad-tool --codegen python https://github.com/common-workflow-language/cwl-v1.2/raw/codegen/CommonWorkflowLanguage.yml --codegen-parent "https://w3id.org/cwl/salad=schema_salad.metaschema" --codegen-parser-info "org.w3id.cwl.v1_2" > cwl_utils/parser/cwl_v1_2.py``
170170

171171
Release
172172
~~~~~~~

cwl_utils/cwl_v1_0_expression_refactor.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Any, cast
1212

1313
from ruamel import yaml
14+
from schema_salad.metaschema import ArraySchema
1415
from schema_salad.sourceline import SourceLine
1516
from schema_salad.utils import json_dumps
1617

@@ -57,11 +58,11 @@ def escape_expression_field(contents: str) -> str:
5758

5859

5960
def clean_type_ids(
60-
cwltype: cwl.ArraySchema | cwl.InputRecordSchema,
61-
) -> cwl.ArraySchema | cwl.InputRecordSchema:
61+
cwltype: ArraySchema | cwl.InputRecordSchema,
62+
) -> ArraySchema | cwl.InputRecordSchema:
6263
"""Simplify type identifiers."""
6364
result = copy.deepcopy(cwltype)
64-
if isinstance(result, cwl.ArraySchema):
65+
if isinstance(result, ArraySchema):
6566
if isinstance(result.items, MutableSequence):
6667
for item in result.items:
6768
if hasattr(item, "id"):
@@ -340,8 +341,8 @@ def generate_etool_from_expr(
340341
self_type = target
341342
if isinstance(self_type, list):
342343
new_type: (
343-
list[cwl.ArraySchema | cwl.InputRecordSchema]
344-
| cwl.ArraySchema
344+
list[ArraySchema | cwl.InputRecordSchema]
345+
| ArraySchema
345346
| cwl.InputRecordSchema
346347
) = [clean_type_ids(t.type_) for t in self_type if t.type_]
347348
elif self_type.type_:
@@ -1347,7 +1348,7 @@ def traverse_CommandLineTool(
13471348
modified = True
13481349
inp_id = "_{}_glob".format(outp.id.split("#")[-1])
13491350
etool_id = f"_expression_{step_id}{inp_id}"
1350-
glob_target_type = ["string", cwl.ArraySchema("string", "array")]
1351+
glob_target_type = ["string", ArraySchema("string", "array")]
13511352
target = cwl.InputParameter(id=None, type_=glob_target_type)
13521353
replace_step_clt_expr_with_etool(
13531354
expression, etool_id, parent, target, step, replace_etool
@@ -1843,7 +1844,7 @@ def traverse_step(
18431844
source_types.append(temp_type)
18441845
source_type = cwl.InputParameter(
18451846
id=None,
1846-
type_=cwl.ArraySchema(source_types, "array"),
1847+
type_=ArraySchema(source_types, "array"),
18471848
)
18481849
else:
18491850
input_source_id = inp.source.split("#")[-1]

cwl_utils/cwl_v1_1_expression_refactor.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Any, cast
1212

1313
from ruamel import yaml
14+
from schema_salad.metaschema import ArraySchema
1415
from schema_salad.sourceline import SourceLine
1516
from schema_salad.utils import json_dumps
1617

@@ -57,11 +58,11 @@ def escape_expression_field(contents: str) -> str:
5758

5859

5960
def clean_type_ids(
60-
cwltype: cwl.ArraySchema | cwl.InputRecordSchema,
61-
) -> cwl.ArraySchema | cwl.InputRecordSchema:
61+
cwltype: ArraySchema | cwl.InputRecordSchema,
62+
) -> ArraySchema | cwl.InputRecordSchema:
6263
"""Simplify type identifiers."""
6364
result = copy.deepcopy(cwltype)
64-
if isinstance(result, cwl.ArraySchema):
65+
if isinstance(result, ArraySchema):
6566
if isinstance(result.items, MutableSequence):
6667
for item in result.items:
6768
if hasattr(item, "id"):
@@ -340,8 +341,8 @@ def generate_etool_from_expr(
340341
self_type = target
341342
if isinstance(self_type, list):
342343
new_type: (
343-
list[cwl.ArraySchema | cwl.InputRecordSchema]
344-
| cwl.ArraySchema
344+
list[ArraySchema | cwl.InputRecordSchema]
345+
| ArraySchema
345346
| cwl.InputRecordSchema
346347
) = [clean_type_ids(t.type_) for t in self_type]
347348
else:
@@ -1349,7 +1350,7 @@ def traverse_CommandLineTool(
13491350
modified = True
13501351
inp_id = "_{}_glob".format(outp.id.split("#")[-1])
13511352
etool_id = f"_expression_{step_id}{inp_id}"
1352-
glob_target_type = ["string", cwl.ArraySchema("string", "array")]
1353+
glob_target_type = ["string", ArraySchema("string", "array")]
13531354
target = cwl.WorkflowInputParameter(id=None, type_=glob_target_type)
13541355
replace_step_clt_expr_with_etool(
13551356
expression, etool_id, parent, target, step, replace_etool
@@ -1851,7 +1852,7 @@ def traverse_step(
18511852
source_types.append(temp_type)
18521853
source_type = cwl.WorkflowInputParameter(
18531854
id=None,
1854-
type_=cwl.ArraySchema(source_types, "array"),
1855+
type_=ArraySchema(source_types, "array"),
18551856
)
18561857
else:
18571858
input_source_id = inp.source.split("#")[-1]

cwl_utils/cwl_v1_2_expression_refactor.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import Any, cast
1212

1313
from ruamel import yaml
14+
from schema_salad.metaschema import ArraySchema
1415
from schema_salad.sourceline import SourceLine
1516
from schema_salad.utils import json_dumps
1617

@@ -56,11 +57,11 @@ def escape_expression_field(contents: str) -> str:
5657

5758

5859
def clean_type_ids(
59-
cwltype: cwl.ArraySchema | cwl.InputRecordSchema,
60-
) -> cwl.ArraySchema | cwl.InputRecordSchema:
60+
cwltype: ArraySchema | cwl.InputRecordSchema,
61+
) -> ArraySchema | cwl.InputRecordSchema:
6162
"""Simplify type identifiers."""
6263
result = copy.deepcopy(cwltype)
63-
if isinstance(result, cwl.ArraySchema):
64+
if isinstance(result, ArraySchema):
6465
if isinstance(result.items, MutableSequence):
6566
for item in result.items:
6667
if hasattr(item, "id"):
@@ -339,8 +340,8 @@ def generate_etool_from_expr(
339340
self_type = target
340341
if isinstance(self_type, list):
341342
new_type: (
342-
list[cwl.ArraySchema | cwl.InputRecordSchema]
343-
| cwl.ArraySchema
343+
list[ArraySchema | cwl.InputRecordSchema]
344+
| ArraySchema
344345
| cwl.InputRecordSchema
345346
) = [clean_type_ids(t.type_) for t in self_type]
346347
else:
@@ -715,7 +716,7 @@ def process_workflow_inputs_and_outputs(
715716
else:
716717
sources = [s.split("#")[-1] for s in param2.outputSource]
717718
source_type_items = utils.type_for_source(workflow, sources)
718-
if isinstance(source_type_items, cwl.ArraySchema):
719+
if isinstance(source_type_items, ArraySchema):
719720
if isinstance(source_type_items.items, list):
720721
if "null" not in source_type_items.items:
721722
source_type_items.items.append("null")
@@ -1452,7 +1453,7 @@ def traverse_CommandLineTool(
14521453
modified = True
14531454
inp_id = "_{}_glob".format(outp.id.split("#")[-1])
14541455
etool_id = f"_expression_{step_id}{inp_id}"
1455-
glob_target_type = ["string", cwl.ArraySchema("string", "array")]
1456+
glob_target_type = ["string", ArraySchema("string", "array")]
14561457
target = cwl.WorkflowInputParameter(id=None, type_=glob_target_type)
14571458
replace_step_clt_expr_with_etool(
14581459
expression, etool_id, parent, target, step, replace_etool
@@ -1954,7 +1955,7 @@ def traverse_step(
19541955
source_types.append(temp_type)
19551956
source_type = cwl.WorkflowInputParameter(
19561957
id=None,
1957-
type_=cwl.ArraySchema(source_types, "array"),
1958+
type_=ArraySchema(source_types, "array"),
19581959
)
19591960
else:
19601961
input_source_id = inp.source.split("#")[-1]

cwl_utils/parser/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from typing import Any, Optional, TypeAlias, cast
88
from urllib.parse import unquote_plus, urlparse
99

10+
import schema_salad.metaschema
1011
from schema_salad.exceptions import ValidationException
1112
from schema_salad.utils import yaml_no_ts
1213

@@ -181,9 +182,7 @@ class NoType(ABC):
181182
cwl_v1_2.SoftwareRequirement,
182183
)
183184
"""Type union for a CWL v1.x SoftwareRequirement object."""
184-
ArraySchema: TypeAlias = (
185-
cwl_v1_0.ArraySchema | cwl_v1_1.ArraySchema | cwl_v1_2.ArraySchema
186-
)
185+
ArraySchema: TypeAlias = schema_salad.metaschema.ArraySchema
187186
InputArraySchema: TypeAlias = (
188187
cwl_v1_0.InputArraySchema | cwl_v1_1.InputArraySchema | cwl_v1_2.InputArraySchema
189188
)
@@ -193,7 +192,7 @@ class NoType(ABC):
193192
cwl_v1_2.InputArraySchema,
194193
)
195194
"""Type Union for a CWL v1.x ArraySchema object."""
196-
EnumSchema: TypeAlias = cwl_v1_0.EnumSchema | cwl_v1_1.EnumSchema | cwl_v1_2.EnumSchema
195+
EnumSchema: TypeAlias = schema_salad.metaschema.EnumSchema
197196
InputEnumSchema: TypeAlias = (
198197
cwl_v1_0.InputEnumSchema | cwl_v1_1.InputEnumSchema | cwl_v1_2.InputEnumSchema
199198
)
@@ -203,9 +202,7 @@ class NoType(ABC):
203202
cwl_v1_2.InputEnumSchema,
204203
)
205204
"""Type Union for a CWL v1.x EnumSchema object."""
206-
RecordSchema: TypeAlias = (
207-
cwl_v1_0.RecordSchema | cwl_v1_1.RecordSchema | cwl_v1_2.RecordSchema
208-
)
205+
RecordSchema: TypeAlias = schema_salad.metaschema.RecordSchema
209206
InputRecordSchema: TypeAlias = (
210207
cwl_v1_0.InputRecordSchema | cwl_v1_1.InputRecordSchema | cwl_v1_2.InputRecordSchema
211208
)

0 commit comments

Comments
 (0)