Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,22 @@ flake8: FORCE
src/cwl_utils/parser/cwl_v1_0.py: FORCE
schema-salad-tool --codegen python \
--codegen-parser-info "org.w3id.cwl.v1_0" \
https://github.com/common-workflow-language/common-workflow-language/raw/codegen/v1.0/extensions.yml \
--codegen-parent "https://w3id.org/cwl/salad=schema_salad.metaschema" \
https://github.com/common-workflow-language/common-workflow-language/raw/codegen/v1.0/CommonWorkflowLanguage.yml \
> $@

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

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

regen_parsers: src/cwl_utils/parser/cwl_v1_*.py
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ Regenerate parsers
To regenerate install the ``schema_salad`` package and run:

``cwl_utils/parser/cwl_v1_0.py`` was created via
``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``
``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``

``cwl_utils/parser/cwl_v1_1.py`` was created via
``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``
``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``

``cwl_utils/parser/cwl_v1_2.py`` was created via
``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``
``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``

Release
~~~~~~~
Expand Down
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies = [
"packaging",
"rdflib",
"requests",
"schema-salad >= 8.8.20250205075315,<9",
"schema-salad @ git+https://github.com/common-workflow-language/schema_salad@refs/pull/1028/head",
"ruamel.yaml >= 0.17.6, < 0.20",
"typing_extensions >= 4.10.0",
]
Expand Down Expand Up @@ -73,6 +73,9 @@ cwl-inputs-schema-gen = "cwl_utils.inputs_schema_gen:main"
[tool.pytest.ini_options]
addopts = "-rsx -n auto --pyargs cwl_utils.tests"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.version]
path = "src/cwl_utils/__meta__.py"

Expand Down
20 changes: 11 additions & 9 deletions src/cwl_utils/cwl_v1_0_expression_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from typing import Any, cast

from ruamel import yaml
from schema_salad.metaschema import ArraySchema
from schema_salad.runtime import LoadingOptions, save
from schema_salad.sourceline import SourceLine
from schema_salad.utils import json_dumps

Expand Down Expand Up @@ -41,7 +43,7 @@ def expand_stream_shortcuts(process: cwl.CommandLineTool) -> cwl.CommandLineTool
stdout_path = process.stdout
if not stdout_path:
stdout_path = hashlib.sha1( # nosec
json_dumps(cwl.save(process)).encode("utf-8")
json_dumps(save(process)).encode("utf-8")
).hexdigest()
result.stdout = stdout_path
result.outputs[index].type_ = "File"
Expand All @@ -57,11 +59,11 @@ def escape_expression_field(contents: str) -> str:


def clean_type_ids(
cwltype: cwl.ArraySchema | cwl.InputRecordSchema,
) -> cwl.ArraySchema | cwl.InputRecordSchema:
cwltype: ArraySchema | cwl.InputRecordSchema,
) -> ArraySchema | cwl.InputRecordSchema:
"""Simplify type identifiers."""
result = copy.deepcopy(cwltype)
if isinstance(result, cwl.ArraySchema):
if isinstance(result, ArraySchema):
if isinstance(result.items, MutableSequence):
for item in result.items:
if hasattr(item, "id"):
Expand Down Expand Up @@ -340,8 +342,8 @@ def generate_etool_from_expr(
self_type = target
if isinstance(self_type, list):
new_type: (
list[cwl.ArraySchema | cwl.InputRecordSchema]
| cwl.ArraySchema
list[ArraySchema | cwl.InputRecordSchema]
| ArraySchema
| cwl.InputRecordSchema
) = [clean_type_ids(t.type_) for t in self_type if t.type_]
elif self_type.type_:
Expand Down Expand Up @@ -1218,7 +1220,7 @@ def process_level_reqs(


def add_input_to_process(
process: cwl.Process, name: str, inptype: Any, loadingOptions: cwl.LoadingOptions
process: cwl.Process, name: str, inptype: Any, loadingOptions: LoadingOptions
) -> None:
"""Add a new InputParameter to the given CommandLineTool."""
if isinstance(process, cwl.CommandLineTool):
Expand Down Expand Up @@ -1347,7 +1349,7 @@ def traverse_CommandLineTool(
modified = True
inp_id = "_{}_glob".format(outp.id.split("#")[-1])
etool_id = f"_expression_{step_id}{inp_id}"
glob_target_type = ["string", cwl.ArraySchema("string", "array")]
glob_target_type = ["string", ArraySchema("string", "array")]
target = cwl.InputParameter(id=None, type_=glob_target_type)
replace_step_clt_expr_with_etool(
expression, etool_id, parent, target, step, replace_etool
Expand Down Expand Up @@ -1843,7 +1845,7 @@ def traverse_step(
source_types.append(temp_type)
source_type = cwl.InputParameter(
id=None,
type_=cwl.ArraySchema(source_types, "array"),
type_=ArraySchema(source_types, "array"),
)
else:
input_source_id = inp.source.split("#")[-1]
Expand Down
20 changes: 11 additions & 9 deletions src/cwl_utils/cwl_v1_1_expression_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from typing import Any, cast

from ruamel import yaml
from schema_salad.metaschema import ArraySchema
from schema_salad.runtime import LoadingOptions, save
from schema_salad.sourceline import SourceLine
from schema_salad.utils import json_dumps

Expand Down Expand Up @@ -41,7 +43,7 @@ def expand_stream_shortcuts(process: cwl.CommandLineTool) -> cwl.CommandLineTool
stdout_path = process.stdout
if not stdout_path:
stdout_path = hashlib.sha1( # nosec
json_dumps(cwl.save(process)).encode("utf-8")
json_dumps(save(process)).encode("utf-8")
).hexdigest()
result.stdout = stdout_path
result.outputs[index].type_ = "File"
Expand All @@ -57,11 +59,11 @@ def escape_expression_field(contents: str) -> str:


def clean_type_ids(
cwltype: cwl.ArraySchema | cwl.InputRecordSchema,
) -> cwl.ArraySchema | cwl.InputRecordSchema:
cwltype: ArraySchema | cwl.InputRecordSchema,
) -> ArraySchema | cwl.InputRecordSchema:
"""Simplify type identifiers."""
result = copy.deepcopy(cwltype)
if isinstance(result, cwl.ArraySchema):
if isinstance(result, ArraySchema):
if isinstance(result.items, MutableSequence):
for item in result.items:
if hasattr(item, "id"):
Expand Down Expand Up @@ -340,8 +342,8 @@ def generate_etool_from_expr(
self_type = target
if isinstance(self_type, list):
new_type: (
list[cwl.ArraySchema | cwl.InputRecordSchema]
| cwl.ArraySchema
list[ArraySchema | cwl.InputRecordSchema]
| ArraySchema
| cwl.InputRecordSchema
) = [clean_type_ids(t.type_) for t in self_type]
else:
Expand Down Expand Up @@ -1220,7 +1222,7 @@ def process_level_reqs(


def add_input_to_process(
process: cwl.Process, name: str, inptype: Any, loadingOptions: cwl.LoadingOptions
process: cwl.Process, name: str, inptype: Any, loadingOptions: LoadingOptions
) -> None:
"""Add a new InputParameter to the given CommandLineTool."""
if isinstance(process, cwl.CommandLineTool):
Expand Down Expand Up @@ -1349,7 +1351,7 @@ def traverse_CommandLineTool(
modified = True
inp_id = "_{}_glob".format(outp.id.split("#")[-1])
etool_id = f"_expression_{step_id}{inp_id}"
glob_target_type = ["string", cwl.ArraySchema("string", "array")]
glob_target_type = ["string", ArraySchema("string", "array")]
target = cwl.WorkflowInputParameter(id=None, type_=glob_target_type)
replace_step_clt_expr_with_etool(
expression, etool_id, parent, target, step, replace_etool
Expand Down Expand Up @@ -1851,7 +1853,7 @@ def traverse_step(
source_types.append(temp_type)
source_type = cwl.WorkflowInputParameter(
id=None,
type_=cwl.ArraySchema(source_types, "array"),
type_=ArraySchema(source_types, "array"),
)
else:
input_source_id = inp.source.split("#")[-1]
Expand Down
22 changes: 12 additions & 10 deletions src/cwl_utils/cwl_v1_2_expression_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from typing import Any, cast

from ruamel import yaml
from schema_salad.metaschema import ArraySchema
from schema_salad.runtime import LoadingOptions, save
from schema_salad.sourceline import SourceLine
from schema_salad.utils import json_dumps

Expand Down Expand Up @@ -40,7 +42,7 @@ def expand_stream_shortcuts(process: cwl.CommandLineTool) -> cwl.CommandLineTool
stdout_path = process.stdout
if not stdout_path:
stdout_path = hashlib.sha1( # nosec
json_dumps(cwl.save(process)).encode("utf-8")
json_dumps(save(process)).encode("utf-8")
).hexdigest()
result.stdout = stdout_path
result.outputs[index].type_ = "File"
Expand All @@ -56,11 +58,11 @@ def escape_expression_field(contents: str) -> str:


def clean_type_ids(
cwltype: cwl.ArraySchema | cwl.InputRecordSchema,
) -> cwl.ArraySchema | cwl.InputRecordSchema:
cwltype: ArraySchema | cwl.InputRecordSchema,
) -> ArraySchema | cwl.InputRecordSchema:
"""Simplify type identifiers."""
result = copy.deepcopy(cwltype)
if isinstance(result, cwl.ArraySchema):
if isinstance(result, ArraySchema):
if isinstance(result.items, MutableSequence):
for item in result.items:
if hasattr(item, "id"):
Expand Down Expand Up @@ -339,8 +341,8 @@ def generate_etool_from_expr(
self_type = target
if isinstance(self_type, list):
new_type: (
list[cwl.ArraySchema | cwl.InputRecordSchema]
| cwl.ArraySchema
list[ArraySchema | cwl.InputRecordSchema]
| ArraySchema
| cwl.InputRecordSchema
) = [clean_type_ids(t.type_) for t in self_type]
else:
Expand Down Expand Up @@ -715,7 +717,7 @@ def process_workflow_inputs_and_outputs(
else:
sources = [s.split("#")[-1] for s in param2.outputSource]
source_type_items = utils.type_for_source(workflow, sources)
if isinstance(source_type_items, cwl.ArraySchema):
if isinstance(source_type_items, ArraySchema):
if isinstance(source_type_items.items, list):
if "null" not in source_type_items.items:
source_type_items.items.append("null")
Expand Down Expand Up @@ -1323,7 +1325,7 @@ def process_level_reqs(


def add_input_to_process(
process: cwl.Process, name: str, inptype: Any, loadingOptions: cwl.LoadingOptions
process: cwl.Process, name: str, inptype: Any, loadingOptions: LoadingOptions
) -> None:
"""Add a new InputParameter to the given CommandLineTool."""
if isinstance(process, cwl.CommandLineTool):
Expand Down Expand Up @@ -1452,7 +1454,7 @@ def traverse_CommandLineTool(
modified = True
inp_id = "_{}_glob".format(outp.id.split("#")[-1])
etool_id = f"_expression_{step_id}{inp_id}"
glob_target_type = ["string", cwl.ArraySchema("string", "array")]
glob_target_type = ["string", ArraySchema("string", "array")]
target = cwl.WorkflowInputParameter(id=None, type_=glob_target_type)
replace_step_clt_expr_with_etool(
expression, etool_id, parent, target, step, replace_etool
Expand Down Expand Up @@ -1954,7 +1956,7 @@ def traverse_step(
source_types.append(temp_type)
source_type = cwl.WorkflowInputParameter(
id=None,
type_=cwl.ArraySchema(source_types, "array"),
type_=ArraySchema(source_types, "array"),
)
else:
input_source_id = inp.source.split("#")[-1]
Expand Down
4 changes: 1 addition & 3 deletions src/cwl_utils/expression_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ruamel.yaml.main import YAML
from ruamel.yaml.scalarstring import walk_tree
from schema_salad.runtime import save

from cwl_utils import (
cwl_v1_0_expression_refactor,
Expand Down Expand Up @@ -111,15 +112,12 @@ def refactor(args: argparse.Namespace) -> int:
traverse: Callable[[Any, bool, bool, bool, bool], tuple[Any, bool]] = (
cwl_v1_0_expression_refactor.traverse
)
save: saveCWL = cwl_v1_0.save
case "v1.1":
top = cwl_v1_1.load_document_by_yaml(result, uri)
traverse = cwl_v1_1_expression_refactor.traverse
save = cwl_v1_1.save
case "v1.2":
top = cwl_v1_2.load_document_by_yaml(result, uri)
traverse = cwl_v1_2_expression_refactor.traverse
save = cwl_v1_2.save
case _:
_logger.error(
"Sorry, %s is not a supported CWL version by this tool.",
Expand Down
3 changes: 2 additions & 1 deletion src/cwl_utils/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

from cwlupgrader import main as cwlupgrader
from ruamel import yaml
from schema_salad.runtime import save
from schema_salad.sourceline import add_lc_filename

from cwl_utils import cwl_v1_2_expression_refactor
from cwl_utils.loghandler import _logger as _cwlutilslogger
from cwl_utils.pack import pack
from cwl_utils.parser.cwl_v1_2 import load_document_by_yaml, save
from cwl_utils.parser.cwl_v1_2 import load_document_by_yaml

_logger = logging.getLogger("cwl-normalizer") # pylint: disable=invalid-name
defaultStreamHandler = logging.StreamHandler() # pylint: disable=invalid-name
Expand Down
Loading