Skip to content

Commit ecf9c25

Browse files
Add more TypedDict definitions
This commit adds more `TypedDict` definitions for `File`, `Dirent`, and `Directory` objects. In addition, it adds the `exitCode` entry to the `CWLRuntimeParameterContext`, which was missing.
1 parent b9de378 commit ecf9c25

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

cwl_utils/expression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def evaluator(
125125
try:
126126
if first_symbol in ("inputs", "self", "runtime"):
127127
symbol = cast(
128-
Literal["inputs"] | Literal["self"] | Literal["runtime"],
128+
Literal["inputs", "self", "runtime"],
129129
first_symbol,
130130
)
131131
if inspect.iscoroutinefunction(js_engine.regex_eval):

cwl_utils/types.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# From https://github.com/rabix/sbpack/blob/b8404a0859ffcbe1edae6d8f934e51847b003320/sbpack/lib.py
33
"""Shared Python type definitions for commons JSON like CWL objects."""
4+
import sys
45
from collections.abc import MutableMapping, MutableSequence
5-
from typing import TypeAlias, TypedDict
6+
from typing import Literal, TypeAlias, TypedDict
7+
8+
if sys.version_info >= (3, 11):
9+
from typing import Required
10+
else:
11+
from typing_extensions import Required
12+
613

714
built_in_types: list[str] = [
815
"null",
@@ -21,12 +28,46 @@
2128
]
2229

2330

31+
DirectoryDict = TypedDict(
32+
"DirectoryDict",
33+
{
34+
"class": Required[Literal["Directory"]],
35+
"location": str,
36+
"path": str,
37+
"basename": str,
38+
"listing": MutableSequence["FileDict | DirectoryDict"],
39+
},
40+
total=False,
41+
)
42+
43+
44+
FileDict = TypedDict(
45+
"FileDict",
46+
{
47+
"class": Required[Literal["File"]],
48+
"location": str,
49+
"path": str,
50+
"basename": str,
51+
"dirname": str,
52+
"nameroot": str,
53+
"nameext": str,
54+
"checksum": str,
55+
"size": int,
56+
"secondaryFiles": MutableSequence["FileDict | DirectoryDict"],
57+
"format": str,
58+
"contents": str,
59+
},
60+
total=False,
61+
)
62+
63+
2464
CWLOutputAtomType: TypeAlias = (
2565
None
2666
| bool
2767
| str
2868
| int
29-
| float
69+
| FileDict
70+
| DirectoryDict
3071
| MutableSequence["CWLOutputAtomType"]
3172
| MutableMapping[str, "CWLOutputAtomType"]
3273
)
@@ -35,6 +76,8 @@
3576
| str
3677
| int
3778
| float
79+
| FileDict
80+
| DirectoryDict
3881
| MutableSequence[CWLOutputAtomType]
3982
| MutableMapping[str, CWLOutputAtomType]
4083
)
@@ -49,9 +92,16 @@ class CWLRuntimeParameterContext(TypedDict, total=False):
4992
ram: float | str
5093
outdirSize: float | str
5194
tmpdirSize: float | str
95+
exitCode: int
5296

5397

5498
class CWLParameterContext(TypedDict, total=False):
5599
inputs: CWLObjectType
56100
self: CWLOutputType | None
57101
runtime: CWLRuntimeParameterContext
102+
103+
104+
class DirentDict(TypedDict, total=False):
105+
entry: Required[str]
106+
entryname: str
107+
writable: bool

0 commit comments

Comments
 (0)