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

fix: proper error message if resource types do not match #1556

Merged
merged 1 commit into from Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 15 additions & 5 deletions snakemake/rules.py
Expand Up @@ -1081,13 +1081,23 @@ def apply(name, res, threads=None):

if not isinstance(res, int) and not isinstance(res, str):
raise WorkflowError(
"Resources function did not return int, float (floats are "
"rouded to the nearest integer), or str.",
f"Resource {name} is neither int, float(would be rounded to nearest int), or str.",
rule=self,
)
if isinstance(res, int):
global_res = self.workflow.global_resources.get(name, res)
if global_res is not None:

global_res = self.workflow.global_resources.get(name)
if global_res is not None:
if not isinstance(res, TBDString) and type(res) != type(global_res):
global_type = (
"an int" if isinstance(global_res, int) else type(global_res)
)
raise WorkflowError(
f"Resource {name} is of type {type(res).__name__} but global resource constraint "
f"defines {global_type} with value {global_res}. "
"Resources with the same name need to have the same types (int, float, or str are allowed).",
rule=self,
)
if isinstance(res, int):
res = min(global_res, res)
return res

Expand Down
22 changes: 22 additions & 0 deletions tests/test_github_issue1389/Snakefile
@@ -0,0 +1,22 @@
rule all:
input:
"test1.txt",
"test2.txt",


rule a:
output:
"test1.txt",
resources:
foo=1,
shell:
"touch {output}"


rule b:
output:
"test2.txt",
resources:
foo="bar",
shell:
"touch {output}"
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions tests/tests.py
Expand Up @@ -1597,3 +1597,8 @@ def test_github_issue1498():

def test_cleanup_metadata_fail():
run(dpath("test09"), cleanup_metadata=["xyz"])


@skip_on_windows # same on win, no need to test
def test_github_issue1389():
run(dpath("test_github_issue1389"), resources={"foo": 4}, shouldfail=True)