Skip to content

Commit b9d0b48

Browse files
Merge pull request #1 from snakemake/throw-java-opt-errors
implement changes in snakemake-wrappers PR 204
2 parents fcec76f + a311d98 commit b9d0b48

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

snakemake_wrapper_utils/java.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1+
import sys
2+
13
def get_java_opts(snakemake):
24
"""Obtain java_opts from params, and handle resource definitions in resources."""
35

46
java_opts = snakemake.params.get("java_opts", "")
57
# Getting memory in megabytes, if java opts is not filled with -Xmx parameter
68
# By doing so, backward compatibility is preserved
7-
if "mem_mb" in snakemake.resources.keys() and not "-Xmx" in java_opts:
9+
if "mem_mb" in snakemake.resources.keys():
10+
if "-Xmx" in java_opts:
11+
sys.exit("You have specified resources.mem_mb and provided `-Xmx` in params.java_opts. For Java memory specifications, please only use resources.mem_mb.")
12+
if "-Xmx" in extra:
13+
sys.exit("You have specified resources.mem_mb and provided `-Xmx` in params.extra. For Java memory specifications, please only use resources.mem_mb.")
814
java_opts += " -Xmx{}M".format(snakemake.resources["mem_mb"])
915

1016
# Getting memory in gigabytes, for user convenience. Please prefer the use
1117
# of mem_mb over mem_gb as advised in documentation.
12-
elif "mem_gb" in snakemake.resources.keys() and not "-Xmx" in java_opts:
18+
elif "mem_gb" in snakemake.resources.keys():
19+
if "-Xmx" in java_opts:
20+
sys.exit("You have specified resources.mem_gb and provided `-Xmx` in params.java_opts. For Java memory specifications, please only use resources.mem_mb.")
21+
if "-Xmx" in extra:
22+
sys.exit("You have specified resources.mem_gb and provided `-Xmx` in params.extra. For Java memory specifications, please only use resources.mem_mb.")
1323
java_opts += " -Xmx{}G".format(snakemake.resources["mem_gb"])
1424

1525
# Getting java temp directory from output files list, if -Djava.io.tmpdir
1626
# is not provided in java parameters. By doing so, backward compatibility is
1727
# not broken.
18-
if "java_temp" in snakemake.output.keys() and not "-Djava.io.tmpdir" in java_opts:
28+
if "java_temp" in snakemake.output.keys():
29+
if "-Djava.io.tmpdir" in java_opts:
30+
sys.exit("You have specified output.java_temp and provided `-Djava.io.tmpdir` in params.java_opts. Please choose the one you intended and remove the other specification.")
1931
java_opts += " -Djava.io.tmpdir={}".format(snakemake.output["java_temp"])
2032

2133
return java_opts

0 commit comments

Comments
 (0)