Skip to content
Open
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
82 changes: 43 additions & 39 deletions cwl_utils/cwl_v1_0_expression_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import copy
import hashlib
import uuid
from collections.abc import Mapping, MutableSequence, Sequence
from collections.abc import MutableSequence, Sequence
from contextlib import suppress
from typing import Any, Optional, cast

Expand All @@ -18,10 +18,13 @@
from cwl_utils.errors import JavascriptException, WorkflowException
from cwl_utils.expression import do_eval, interpolate
from cwl_utils.types import (
CWLDirectoryType,
CWLFileType,
CWLObjectType,
CWLOutputType,
CWLParameterContext,
CWLRuntimeParameterContext,
is_file_or_directory,
)


Expand Down Expand Up @@ -547,31 +550,37 @@ def example_input(some_type: Any) -> Any:
"""Produce a fake input for the given type."""
# TODO: accept some sort of context object with local custom type definitions
if some_type == "Directory":
return {
"class": "Directory",
"location": "https://www.example.com/example",
"basename": "example",
"listing": [
{
"class": "File",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
],
}
return CWLDirectoryType(
**{
"class": "Directory",
"location": "https://www.example.com/example",
"basename": "example",
"listing": [
CWLFileType(
**{
"class": "File",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
)
],
}
)
if some_type == "File":
return {
"class": "File",
"location": "https://www.example.com/example.txt",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
return CWLFileType(
**{
"class": "File",
"location": "https://www.example.com/example.txt",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
)
if some_type == "int":
return 23
if some_type == "string":
Expand All @@ -581,12 +590,14 @@ def example_input(some_type: Any) -> Any:
return None


EMPTY_FILE: CWLOutputType = {
"class": "File",
"basename": "em.pty",
"nameroot": "em",
"nameext": "pty",
}
EMPTY_FILE = CWLFileType(
**{
"class": "File",
"basename": "em.pty",
"nameroot": "em",
"nameext": "pty",
}
)

TOPLEVEL_SF_EXPR_ERROR = (
"Input '{}'. Sorry, CWL Expressions as part of a secondaryFiles "
Expand Down Expand Up @@ -793,14 +804,7 @@ def process_workflow_reqs_and_hints(
resources={},
)
modified = True
if (
isinstance(expr_result, Mapping)
and "class" in expr_result
and (
expr_result["class"]
in ("File", "Directory")
)
):
if is_file_or_directory(expr_result):
target = cwl.InputParameter(
id=None,
type_=expr_result["class"],
Expand Down
82 changes: 43 additions & 39 deletions cwl_utils/cwl_v1_1_expression_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import copy
import hashlib
import uuid
from collections.abc import Mapping, MutableSequence, Sequence
from collections.abc import MutableSequence, Sequence
from contextlib import suppress
from typing import Any, Optional, cast

Expand All @@ -18,10 +18,13 @@
from cwl_utils.errors import JavascriptException, WorkflowException
from cwl_utils.expression import do_eval, interpolate
from cwl_utils.types import (
CWLDirectoryType,
CWLFileType,
CWLObjectType,
CWLOutputType,
CWLParameterContext,
CWLRuntimeParameterContext,
is_file_or_directory,
)


Expand Down Expand Up @@ -545,31 +548,37 @@ def example_input(some_type: Any) -> Any:
"""Produce a fake input for the given type."""
# TODO: accept some sort of context object with local custom type definitions
if some_type == "Directory":
return {
"class": "Directory",
"location": "https://www.example.com/example",
"basename": "example",
"listing": [
{
"class": "File",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
],
}
return CWLDirectoryType(
**{
"class": "Directory",
"location": "https://www.example.com/example",
"basename": "example",
"listing": [
CWLFileType(
**{
"class": "File",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
)
],
}
)
if some_type == "File":
return {
"class": "File",
"location": "https://www.example.com/example.txt",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
return CWLFileType(
**{
"class": "File",
"location": "https://www.example.com/example.txt",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
)
if some_type == "int":
return 23
if some_type == "string":
Expand All @@ -579,12 +588,14 @@ def example_input(some_type: Any) -> Any:
return None


EMPTY_FILE: CWLOutputType = {
"class": "File",
"basename": "em.pty",
"nameroot": "em",
"nameext": "pty",
}
EMPTY_FILE = CWLFileType(
**{
"class": "File",
"basename": "em.pty",
"nameroot": "em",
"nameext": "pty",
}
)

TOPLEVEL_SF_EXPR_ERROR = (
"Input '{}'. Sorry, CWL Expressions as part of a secondaryFiles "
Expand Down Expand Up @@ -795,14 +806,7 @@ def process_workflow_reqs_and_hints(
resources={},
)
modified = True
if (
isinstance(expr_result, Mapping)
and "class" in expr_result
and (
expr_result["class"]
in ("File", "Directory")
)
):
if is_file_or_directory(expr_result):
target = cwl.WorkflowInputParameter(
id=None,
type_=expr_result["class"],
Expand Down
70 changes: 40 additions & 30 deletions cwl_utils/cwl_v1_2_expression_refactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from cwl_utils.errors import JavascriptException, WorkflowException
from cwl_utils.expression import do_eval, interpolate
from cwl_utils.types import (
CWLDirectoryType,
CWLFileType,
CWLObjectType,
CWLOutputType,
CWLParameterContext,
Expand Down Expand Up @@ -545,31 +547,37 @@ def example_input(some_type: Any) -> Any:
"""Produce a fake input for the given type."""
# TODO: accept some sort of context object with local custom type definitions
if some_type == "Directory":
return {
"class": "Directory",
"location": "https://www.example.com/example",
"basename": "example",
"listing": [
{
"class": "File",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
],
}
return CWLDirectoryType(
**{
"class": "Directory",
"location": "https://www.example.com/example",
"basename": "example",
"listing": [
CWLFileType(
**{
"class": "File",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
)
],
}
)
if some_type == "File":
return {
"class": "File",
"location": "https://www.example.com/example.txt",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
return CWLFileType(
**{
"class": "File",
"location": "https://www.example.com/example.txt",
"basename": "example.txt",
"size": 23,
"contents": "hoopla",
"nameroot": "example",
"nameext": "txt",
}
)
if some_type == "int":
return 23
if some_type == "string":
Expand All @@ -579,12 +587,14 @@ def example_input(some_type: Any) -> Any:
return None


EMPTY_FILE: CWLOutputType = {
"class": "File",
"basename": "em.pty",
"nameroot": "em",
"nameext": "pty",
}
EMPTY_FILE = CWLFileType(
**{
"class": "File",
"basename": "em.pty",
"nameroot": "em",
"nameext": "pty",
}
)

TOPLEVEL_SF_EXPR_ERROR = (
"Input '{}'. Sorry, CWL Expressions as part of a secondaryFiles "
Expand Down
19 changes: 10 additions & 9 deletions cwl_utils/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
import json
from collections.abc import Awaitable, MutableMapping
from enum import Enum
from typing import Any, Literal, Union, cast
from typing import Any, Union, cast

from schema_salad.utils import json_dumps

from cwl_utils.errors import JavascriptException, SubstitutionError, WorkflowException
from cwl_utils.loghandler import _logger
from cwl_utils.sandboxjs import JSEngine, default_timeout, get_js_engine, param_re
from cwl_utils.types import CWLObjectType, CWLOutputType, CWLParameterContext
from cwl_utils.types import (
CWLObjectType,
CWLOutputType,
CWLParameterContext,
is_cwl_parameter_context_key,
)
from cwl_utils.utils import bytes2str_in_dicts


Expand Down Expand Up @@ -123,19 +128,15 @@ def evaluator(
if first_symbol_end + 1 == len(ex) and first_symbol == "null":
return None
try:
if first_symbol in ("inputs", "self", "runtime"):
symbol = cast(
Literal["inputs"] | Literal["self"] | Literal["runtime"],
first_symbol,
)
if is_cwl_parameter_context_key(first_symbol):
if inspect.iscoroutinefunction(js_engine.regex_eval):
return asyncio.get_event_loop().run_until_complete(
cast(
Awaitable[CWLOutputType],
js_engine.regex_eval(
first_symbol,
ex[first_symbol_end:-1],
cast(CWLOutputType, obj[symbol]),
cast(CWLOutputType, obj[first_symbol]),
**kwargs,
),
)
Expand All @@ -146,7 +147,7 @@ def evaluator(
js_engine.regex_eval(
first_symbol,
ex[first_symbol_end:-1],
cast(CWLOutputType, obj[symbol]),
cast(CWLOutputType, obj[first_symbol]),
**kwargs,
),
)
Expand Down
Loading
Loading