Skip to content

Commit

Permalink
fix: proper error message when defining cache eligibility for rules w…
Browse files Browse the repository at this point in the history
…ith multiple output files and no multiext declaration. (#1357)

* dbg message for cache fetching

* dbg

* handle invalid multi output rules marked as cacheable

* cleanup

* fmt

* add testcase
  • Loading branch information
johanneskoester committed Jan 28, 2022
1 parent 6c505c2 commit 47b5096
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
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)

0 comments on commit 47b5096

Please sign in to comment.