Skip to content

Commit

Permalink
fix: 2142 log directive in default target rule (#2191)
Browse files Browse the repository at this point in the history
### Description

When the default target rule (e.g `all`) contains a `log` directive,
snakemake deems workflow complete and skips execution. See #2142

This PR fixes this bug by adding a `include_logfiles` flag to
`job.has_product()` method, similar to one used in `job.products()`. In
fact, this flag is simply passed on to `job.products()` internally.

### QC
<!-- Make sure that you can tick the boxes below. -->

* [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).
  • Loading branch information
SichongP committed Apr 21, 2023
1 parent bdde680 commit 86e9624
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion snakemake/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ def update_needrun(job):
reason.updated_input.update(updated_subworkflow_input)
elif job in self.targetjobs:
# TODO find a way to handle added/removed input files here?
if not job.has_products():
if not job.has_products(include_logfiles=False):
if job.input:
if job.rule.norun:
reason.updated_input_run.update(
Expand Down
6 changes: 3 additions & 3 deletions snakemake/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ def reset_params_and_resources(self):
def get_target_spec(self):
raise NotImplementedError()

def products(self):
def products(self, include_logfiles=True):
raise NotImplementedError()

def has_products(self):
for o in self.products():
def has_products(self, include_logfiles=True):
for o in self.products(include_logfiles=include_logfiles):
return True
return False

Expand Down
8 changes: 8 additions & 0 deletions tests/test_github_issue2142/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rule all:
input: "data.txt"
log:
"logs/all.log"

rule A:
output: "data.txt"
shell: "touch {output}"
Empty file.
4 changes: 4 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,10 @@ def test_github_issue1389():
run(dpath("test_github_issue1389"), resources={"foo": 4}, shouldfail=True)


def test_github_issue2142():
run(dpath("test_github_issue2142"))


def test_ensure_nonempty_fail():
run(dpath("test_ensure"), targets=["a"], shouldfail=True)

Expand Down

0 comments on commit 86e9624

Please sign in to comment.