From e820f973ad8ca99822be69c927c7d7bf6a89f54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20K=C3=B6ster?= Date: Thu, 31 Mar 2022 13:33:33 +0200 Subject: [PATCH] fix: do not remove existing temp files in case of dryrun (#1543) --- snakemake/dag.py | 7 +++++-- tests/test_github_issue1542/Snakefile | 20 +++++++++++++++++++ tests/test_github_issue1542/a.txt | 0 .../expected-results/a.txt | 0 tests/tests.py | 4 ++++ 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/test_github_issue1542/Snakefile create mode 100644 tests/test_github_issue1542/a.txt create mode 100644 tests/test_github_issue1542/expected-results/a.txt diff --git a/snakemake/dag.py b/snakemake/dag.py index eed5d0059..6daa8cbb5 100755 --- a/snakemake/dag.py +++ b/snakemake/dag.py @@ -639,8 +639,11 @@ def unneeded_files(): yield from filterfalse(partial(needed, job), tempfiles) for f in unneeded_files(): - logger.info("Removing temporary output file {}.".format(f)) - f.remove(remove_non_empty_dir=True) + if self.dryrun: + logger.info(f"Would remove temporary output {f}") + else: + logger.info("Removing temporary output {}.".format(f)) + f.remove(remove_non_empty_dir=True) def handle_log(self, job, upload_remote=True): for f in job.log: diff --git a/tests/test_github_issue1542/Snakefile b/tests/test_github_issue1542/Snakefile new file mode 100644 index 000000000..221fec1bc --- /dev/null +++ b/tests/test_github_issue1542/Snakefile @@ -0,0 +1,20 @@ +# Snakefile +rule all: + input: + "b.txt", + + +rule a: + output: + temp("a.txt"), + shell: + "touch a.txt" + + +rule b: + input: + "a.txt", + output: + "b.txt", + shell: + "touch b.txt" diff --git a/tests/test_github_issue1542/a.txt b/tests/test_github_issue1542/a.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_github_issue1542/expected-results/a.txt b/tests/test_github_issue1542/expected-results/a.txt new file mode 100644 index 000000000..e69de29bb diff --git a/tests/tests.py b/tests/tests.py index bd5702a0e..515e780fa 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1580,3 +1580,7 @@ def test_pipe_depend(): @skip_on_windows # no pipe support on windows def test_pipe_depend_target_file(): run(dpath("test_pipe_depend"), targets=["test.txt"], shouldfail=True) + + +def test_github_issue1542(): + run(dpath("test_github_issue1542"), dryrun=True)