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 when defining cache eligibility for rules with multiple output files and no multiext declaration. #1357

Merged
merged 6 commits into from Jan 28, 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
3 changes: 3 additions & 0 deletions snakemake/caching/__init__.py
Expand Up @@ -47,6 +47,9 @@ def get_outputfiles(self, job: Job):
)
yield from ((f, f[prefix_len:]) for f in job.output)
else:
assert (
len(job.output) == 1
), "bug: multiple output files in cacheable job but multiext not used for declaring them"
yield (job.output[0], "")

def raise_write_error(self, entry, exception=None):
Expand Down
6 changes: 6 additions & 0 deletions snakemake/caching/local.py
Expand Up @@ -95,6 +95,12 @@ def fetch(self, job: Job):
if not cachefile.exists():
self.raise_cache_miss_exception(job)

logger.debug(
"Output file {} exists as {} in the cache.".format(
outputfile, cachefile
)
)

self.check_readable(cachefile)
if cachefile.is_dir():
# For directories, create a new one and symlink each entry.
Expand Down
8 changes: 8 additions & 0 deletions snakemake/workflow.py
Expand Up @@ -1541,6 +1541,14 @@ def decorate(ruleinfo):
rule.is_handover = True

if ruleinfo.cache is True:
if len(rule.output) > 1:
if not rule.output[0].is_multiext:
raise WorkflowError(
"Rule is marked for between workflow caching but has multiple output files. "
"This is only allowed if multiext() is used to declare them (see docs on between "
"workflow caching).",
rule=rule,
)
if not self.enable_cache:
logger.warning(
"Workflow defines that rule {} is eligible for caching between workflows "
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cache_multioutput/Snakefile
@@ -0,0 +1,7 @@
rule a:
output:
"1.txt",
"2.txt",
cache: True
shell:
"touch {output}"
Empty file.
4 changes: 4 additions & 0 deletions tests/tests.py
Expand Up @@ -1397,3 +1397,7 @@ def test_modules_ruledeps_inheritance():
@skip_on_windows
def test_conda_named():
run(dpath("test_conda_named"), use_conda=True)


def test_cache_multioutput():
run(dpath("test_cache_multioutput"), shouldfail=True)