Skip to content

Commit 23fef82

Browse files
GaspardRbayraktar1
andauthored
fix: --delete-all-output ignores --dry-run (snakemake#3265)
<!--Add a description of your PR here--> Fixes snakemake#3264 ### QC <!-- Make sure that you can tick the boxes below. --> * [ ] 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). Should I add a test case for this? <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a dry run option for output deletion, allowing users to simulate deletions before execution. - Enhanced workflow commands to improve file and directory management during output operations. - **Bug Fixes** - Corrected a file path reference in deletion validation to ensure more reliable output handling. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: bayraktar1 <[email protected]>
1 parent cc04085 commit 23fef82

File tree

7 files changed

+118
-2
lines changed

7 files changed

+118
-2
lines changed

src/snakemake/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@ def args_to_api(args, parser):
20932093
elif args.archive:
20942094
dag_api.archive(args.archive)
20952095
elif args.delete_all_output:
2096-
dag_api.delete_output()
2096+
dag_api.delete_output(dryrun=args.dryrun)
20972097
elif args.delete_temp_output:
20982098
dag_api.delete_output(only_temp=True, dryrun=args.dryrun)
20992099
else:

tests/test_delete_all_output/Snakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rule delete_all_output:
1313
python -m snakemake --cores 1 -s Snakefile_inner all && \
1414
rm nothere && \
1515
python -m snakemake --cores 1 -s Snakefile_inner --delete-all-output all && \
16-
test -f infile && test ! -f intermediate && test ! -f somedir/final && \
16+
test -f infile && test ! -f intermediate && test ! -f some_dir/final && \
1717
test ! -d empty_dir && test ! -L dangling && test ! -d full_dir
1818
"""
1919

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
shell.executable("bash")
2+
3+
4+
rule all:
5+
input:
6+
"delete_all_output",
7+
"delete_temp_output",
8+
output:
9+
touch("all_ok"),
10+
11+
12+
rule delete_all_output:
13+
output:
14+
touch("delete_all_output"),
15+
shell:
16+
"""
17+
echo $PATH
18+
ls
19+
python -m snakemake --cores 1 -s Snakefile_inner all && \
20+
rm nothere && \
21+
python -m snakemake --cores 1 -s Snakefile_inner --dry-run --delete-all-output all && \
22+
test -f infile && test -f intermediate && test -f some_dir/final && \
23+
test -d empty_dir && test -L dangling && test -d full_dir
24+
"""
25+
26+
27+
rule delete_temp_output:
28+
output:
29+
touch("delete_temp_output"),
30+
shell:
31+
"""
32+
python -m snakemake --cores 1 -s Snakefile_inner --notemp temp && \
33+
python -m snakemake --cores 1 -s Snakefile_inner --dry-run --delete-temp-output temp && \
34+
test -f infile && test -f temp_intermediate && \
35+
test -d temp_empty_dir && test -d temp_full_dir && test -f temp_keep
36+
"""
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
shell.executable("bash")
2+
3+
4+
rule all:
5+
input:
6+
"some_dir/final",
7+
"empty_dir",
8+
"full_dir",
9+
10+
11+
rule a:
12+
input:
13+
"infile",
14+
output:
15+
"intermediate",
16+
"dangling",
17+
touch(protected("protected")),
18+
shell:
19+
"ln -s {input} {output[0]} && touch nothere && ln -s nothere {output[1]}"
20+
21+
22+
rule b:
23+
input:
24+
"intermediate",
25+
output:
26+
touch("some_dir/final"),
27+
28+
29+
rule c:
30+
output:
31+
directory("empty_dir"),
32+
shell:
33+
"mkdir empty_dir"
34+
35+
36+
rule d:
37+
output:
38+
directory("full_dir"),
39+
shell:
40+
"mkdir full_dir && touch full_dir/somefile"
41+
42+
43+
rule e:
44+
input:
45+
"infile",
46+
output:
47+
temp("temp_intermediate"),
48+
shell:
49+
"touch {output}"
50+
51+
52+
rule f:
53+
input:
54+
"temp_intermediate",
55+
output:
56+
directory(temp("temp_empty_dir")),
57+
shell:
58+
"mkdir temp_empty_dir"
59+
60+
61+
rule g:
62+
input:
63+
"temp_intermediate",
64+
output:
65+
directory(temp("temp_full_dir")),
66+
shell:
67+
"mkdir temp_full_dir && touch temp_full_dir/somefile"
68+
69+
70+
rule temp:
71+
input:
72+
"temp_empty_dir",
73+
"temp_full_dir",
74+
output:
75+
touch("temp_keep"),

tests/test_github_issue_3265_respect_dryrun_delete_all/expected-results/all_ok

Whitespace-only changes.

tests/test_github_issue_3265_respect_dryrun_delete_all/infile

Whitespace-only changes.

tests/tests.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def test_delete_all_output():
4444
run(dpath("test_delete_all_output"))
4545

4646

47+
@skip_on_windows
48+
def test_github_issue_3265_respect_dryrun_delete_all():
49+
run(dpath("test_github_issue_3265_respect_dryrun_delete_all"))
50+
51+
4752
def test_github_issue_14():
4853
"""Add cleanup_scripts argument to allow the user to keep scripts"""
4954
# Return temporary directory for inspection - we should keep scripts here

0 commit comments

Comments
 (0)