Skip to content

Commit f884b50

Browse files
fix: Don't attempt to parse TBDString resources (#2690)
### Description This fixes the `WorkflowError`s that occur when the resource parsing code tries to parse `TBDString`s during a dry run. This should fix #2575 and fix #2555. ### QC * [x] The PR contains a test case for the changes or the changes are already covered by an existing test case. * [x] The documentation (`docs/`) is updated to reflect the changes or this is not necessary (e.g. if the change does neither modify the language nor the behavior or functionalities of Snakemake). Co-authored-by: Johannes Köster <[email protected]>
1 parent 18689b4 commit f884b50

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

snakemake/resources.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,11 @@ def infer_resources(name, value, resources: dict):
611611
"""Infer resources from a given one, if possible."""
612612
from humanfriendly import parse_size, parse_timespan, InvalidTimespan, InvalidSize
613613

614-
if (name == "mem" or name == "disk") and isinstance(value, str):
614+
if (
615+
(name == "mem" or name == "disk")
616+
and isinstance(value, str)
617+
and not isinstance(value, TBDString)
618+
):
615619
inferred_name = f"{name}_mb"
616620
try:
617621
in_bytes = parse_size(value)
@@ -620,7 +624,11 @@ def infer_resources(name, value, resources: dict):
620624
f"Cannot parse mem or disk value into size in MB for setting {inferred_name} resource: {value}"
621625
)
622626
resources[inferred_name] = max(int(round(in_bytes / 1024 / 1024)), 1)
623-
elif name == "runtime" and isinstance(value, str):
627+
elif (
628+
name == "runtime"
629+
and isinstance(value, str)
630+
and not isinstance(value, TBDString)
631+
):
624632
try:
625633
resources["runtime"] = max(int(round(parse_timespan(value) / 60)), 1)
626634
except InvalidTimespan:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rule all:
2+
input: "a.out"
3+
4+
rule test1:
5+
output: "a.out"
6+
resources:
7+
mem = lambda wildcards, attempt: f"{attempt}MB",
8+
runtime = lambda wildcards, attempt: f"{attempt}m"
9+
shell: "touch {output}"

tests/tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,13 @@ def test_resource_string_in_cli_or_profile():
19801980
)
19811981

19821982

1983+
def test_resource_tbdstring():
1984+
test_path = dpath("test_resource_tbdstring")
1985+
results_dir = Path(test_path) / "expected-results"
1986+
results_dir.mkdir(exist_ok=True)
1987+
run(test_path, executor="dryrun", check_results=False)
1988+
1989+
19831990
def test_queue_input():
19841991
run(dpath("test_queue_input"))
19851992

0 commit comments

Comments
 (0)