Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WDL 2.0] task hints #456

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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
8 changes: 5 additions & 3 deletions WDL/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,9 +893,11 @@ def runner_input(
decl = available_inputs.get(name)

if not decl:
# allow arbitrary runtime overrides
# allow arbitrary runtime/hints overrides
nmparts = name.split(".")
runtime_idx = next((i for i, term in enumerate(nmparts) if term in ("runtime",)), -1)
runtime_idx = next(
(i for i, term in enumerate(nmparts) if term in ("runtime", "hints")), -1
)
if runtime_idx >= 0 and len(nmparts) > (runtime_idx + 1):
decl = available_inputs.get(".".join(nmparts[:runtime_idx] + ["_runtime"]))

Expand Down Expand Up @@ -1073,7 +1075,7 @@ def runner_input_value(s_value, ty, downloadable, root):
ty.item_type, [runner_input_value(s_value, ty.item_type, downloadable, root)]
)
if isinstance(ty, Type.Any):
# infer dynamically-typed runtime overrides
# infer dynamically-typed runtime/hints overrides
try:
return Value.Int(int(s_value))
except ValueError:
Expand Down
8 changes: 7 additions & 1 deletion WDL/Tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ class Task(SourceNode):
""":type: Dict[str,WDL.Expr.Base]

``runtime{}`` section, with keys and corresponding expressions to be evaluated"""
hints: Dict[str, Any]
""":type: Dict[str, Any]

``hints{}`` section as a JSON-like dict"""
meta: Dict[str, Any]
""":type: Dict[str,Any]

Expand All @@ -285,6 +289,7 @@ def __init__(
parameter_meta: Dict[str, Any],
runtime: Dict[str, Expr.Base],
meta: Dict[str, Any],
hints: Dict[str, Any],
) -> None:
super().__init__(pos)
self.name = name
Expand All @@ -295,6 +300,7 @@ def __init__(
self.parameter_meta = parameter_meta
self.runtime = runtime
self.meta = meta
self.hints = hints
self.effective_wdl_version = "1.0" # overridden by Document.__init__
# TODO: enforce validity constraints on parameter_meta and runtime
# TODO: if the input section exists, then all postinputs decls must be
Expand All @@ -314,7 +320,7 @@ def available_inputs(self) -> Env.Bindings[Decl]:
ans = Env.Bindings()

if self.effective_wdl_version not in ("draft-2", "1.0"):
# synthetic placeholder to expose runtime overrides
# synthetic placeholder to expose runtime & hints overrides
ans = ans.bind("_runtime", Decl(self.pos, Type.Any(), "_runtime"))

for decl in reversed(self.inputs if self.inputs is not None else self.postinputs):
Expand Down
4 changes: 2 additions & 2 deletions WDL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ def values_from_json(
key2parts = key2.split(".")

runtime_idx = next(
(i for i, term in enumerate(key2parts) if term in ("runtime",)), -1
(i for i, term in enumerate(key2parts) if term in ("runtime", "hints")), -1
)
if (
runtime_idx >= 0
and len(key2parts) > (runtime_idx + 1)
and ".".join(key2parts[:runtime_idx] + ["_runtime"]) in available
):
# allow arbitrary keys for runtime
# allow arbitrary keys for runtime/hints
ty = Type.Any()
elif len(key2parts) == 3 and key2parts[0] and key2parts[1] and key2parts[2]:
# attempt to simplify <call>.<subworkflow>.<input> from old Cromwell JSON
Expand Down
4 changes: 3 additions & 1 deletion WDL/_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
| output_decls
| meta_section
| runtime_section
| hints_section
| any_decl -> noninput_decl

tasks: task*
Expand All @@ -336,6 +337,7 @@
// task runtime section (key-expression pairs)
runtime_section: "runtime" "{" [runtime_kv (","? runtime_kv)*] "}"
runtime_kv: CNAME ":" expr
hints_section: "hints" meta_object

///////////////////////////////////////////////////////////////////////////////////////////////////
// decl
Expand Down Expand Up @@ -479,7 +481,7 @@
%ignore COMMENT
"""
keywords["development"] = set(
"Array Directory File Float Int Map None Pair String alias as call command else false if import input left meta object output parameter_meta right runtime scatter struct task then true workflow".split(
"Array Directory File Float Int Map None Pair String alias as call command else false hints if import input left meta object output parameter_meta right runtime scatter struct task then true workflow".split(
" "
)
)
Expand Down
4 changes: 4 additions & 0 deletions WDL/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ def runtime_section(self, items, meta):
d[k] = v
return {"runtime": d}

def hints_section(self, items, meta):
return {"hints": items[0]}

def task(self, items, meta):
d = {"noninput_decls": []}
for item in items:
Expand Down Expand Up @@ -416,6 +419,7 @@ def task(self, items, meta):
d.get("parameter_meta", {}),
d.get("runtime", {}),
d.get("meta", {}),
d.get("hints", {}),
)

def tasks(self, items, meta):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_7runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,11 @@ def test_weird_filenames(self):
runtime {
container: ["ubuntu:20.04"]
}
hints {
foo: {
bar: ["bas", 42]
}
}
}
"""

Expand Down