Skip to content

Commit

Permalink
Drop "Atomic" types in favor of recursive typedefs
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-c committed Nov 15, 2023
1 parent 1e35dc4 commit 641de7a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 33 deletions.
6 changes: 3 additions & 3 deletions cwltool/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .errors import WorkflowException
from .loghandler import _logger
from .process import shortname
from .utils import CWLObjectType, CWLOutputAtomType, CWLOutputType, SinkType, aslist
from .utils import CWLObjectType, CWLOutputType, SinkType, aslist


def _get_type(tp):
Expand Down Expand Up @@ -90,8 +90,8 @@ def can_assign_src_to_sink(src: SinkType, sink: Optional[SinkType], strict: bool
return False
if src["type"] == "array" and sink["type"] == "array":
return can_assign_src_to_sink(
cast(MutableSequence[CWLOutputAtomType], src["items"]),
cast(MutableSequence[CWLOutputAtomType], sink["items"]),
cast(MutableSequence[CWLOutputType], src["items"]),
cast(MutableSequence[CWLOutputType], sink["items"]),
strict,
)
if src["type"] == "record" and sink["type"] == "record":
Expand Down
13 changes: 6 additions & 7 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
from .utils import (
DEFAULT_TMP_PREFIX,
CWLObjectType,
CWLOutputAtomType,
CWLOutputType,
HasReqsHints,
adjustDirObjs,
Expand Down Expand Up @@ -289,7 +288,7 @@ def realize_input_schema(
_, input_type_name = entry["type"].split("#")
if input_type_name in schema_defs:
entry["type"] = cast(
CWLOutputAtomType,
CWLOutputType,
realize_input_schema(
cast(
MutableSequence[Union[str, CWLObjectType]],
Expand All @@ -300,29 +299,29 @@ def realize_input_schema(
)
if isinstance(entry["type"], MutableSequence):
entry["type"] = cast(
CWLOutputAtomType,
CWLOutputType,
realize_input_schema(
cast(MutableSequence[Union[str, CWLObjectType]], entry["type"]),
schema_defs,
),
)
if isinstance(entry["type"], Mapping):
entry["type"] = cast(
CWLOutputAtomType,
CWLOutputType,
realize_input_schema([cast(CWLObjectType, entry["type"])], schema_defs),
)
if entry["type"] == "array":
items = entry["items"] if not isinstance(entry["items"], str) else [entry["items"]]
entry["items"] = cast(
CWLOutputAtomType,
CWLOutputType,
realize_input_schema(
cast(MutableSequence[Union[str, CWLObjectType]], items),
schema_defs,
),
)
if entry["type"] == "record":
entry["fields"] = cast(
CWLOutputAtomType,
CWLOutputType,
realize_input_schema(
cast(MutableSequence[Union[str, CWLObjectType]], entry["fields"]),
schema_defs,
Expand Down Expand Up @@ -612,7 +611,7 @@ def loadref(base: str, uri: str) -> Union[CommentedMap, CommentedSeq, str, None]
nestdirs=nestdirs,
)
if sfs is not None:
deps["secondaryFiles"] = cast(MutableSequence[CWLOutputAtomType], mergedirs(sfs))
deps["secondaryFiles"] = cast(MutableSequence[CWLOutputType], mergedirs(sfs))

return deps

Expand Down
7 changes: 3 additions & 4 deletions cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
from .update import INTERNAL_VERSION, ORDERED_VERSIONS, ORIGINAL_CWLVERSION
from .utils import (
CWLObjectType,
CWLOutputAtomType,
CWLOutputType,
HasReqsHints,
JobsGeneratorType,
Expand Down Expand Up @@ -1146,7 +1145,7 @@ def mergedirs(
for e in ents.values():
if e["class"] == "Directory" and "listing" in e:
e["listing"] = cast(
MutableSequence[CWLOutputAtomType],
MutableSequence[CWLOutputType],
mergedirs(cast(List[CWLObjectType], e["listing"])),
)
r.extend(ents.values())
Expand Down Expand Up @@ -1206,7 +1205,7 @@ def scandeps(
deps["listing"] = doc["listing"]
if doc["class"] == "File" and "secondaryFiles" in doc:
deps["secondaryFiles"] = cast(
CWLOutputAtomType,
CWLOutputType,
scandeps(
base,
cast(
Expand Down Expand Up @@ -1290,7 +1289,7 @@ def scandeps(
)
if sf:
deps2["secondaryFiles"] = cast(
MutableSequence[CWLOutputAtomType], mergedirs(sf)
MutableSequence[CWLOutputType], mergedirs(sf)
)
if nestdirs:
deps2 = nestdir(base, deps2)
Expand Down
24 changes: 5 additions & 19 deletions cwltool/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,14 @@

processes_to_kill: Deque["subprocess.Popen[str]"] = collections.deque()

CWLOutputAtomType = Union[
None,
bool,
str,
int,
float,
MutableSequence[
Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]]
],
MutableMapping[
str,
Union[None, bool, str, int, float, MutableSequence[Any], MutableMapping[str, Any]],
],
]
CWLOutputType = Union[
None,
bool,
str,
int,
float,
MutableSequence[CWLOutputAtomType],
MutableMapping[str, CWLOutputAtomType],
MutableSequence["CWLOutputType"],
MutableMapping[str, "CWLOutputType"],
]
CWLObjectType = MutableMapping[str, Optional[CWLOutputType]]
"""Typical raw dictionary found in lightly parsed CWL."""
Expand All @@ -103,8 +90,7 @@
DirectoryType = TypedDict(
"DirectoryType", {"class": str, "listing": List[CWLObjectType], "basename": str}
)
JSONAtomType = Union[Dict[str, Any], List[Any], str, int, float, bool, None]
JSONType = Union[Dict[str, JSONAtomType], List[JSONAtomType], str, int, float, bool, None]
JSONType = Union[Dict[str, "JSONType"], List["JSONType"], str, int, float, bool, None]


class WorkflowStateItem(NamedTuple):
Expand Down Expand Up @@ -297,7 +283,7 @@ def get_listing(fs_access: "StdFsAccess", rec: CWLObjectType, recursive: bool =
return
if "listing" in rec:
return
listing: List[CWLOutputAtomType] = []
listing: List[CWLOutputType] = []
loc = cast(str, rec["location"])
for ld in fs_access.listdir(loc):
parse = urllib.parse.urlparse(ld)
Expand Down

0 comments on commit 641de7a

Please sign in to comment.