Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix string resource definition in CLI and profile #2627

Merged
merged 7 commits into from Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion snakemake/cli.py
Expand Up @@ -81,7 +81,7 @@ def parse_set_resources(args):
assignments = defaultdict(dict)
if args is not None:
for entry in args:
key, value = parse_key_value_arg(entry, errmsg=errmsg)
key, value = parse_key_value_arg(entry, errmsg=errmsg, strip_quotes=False)
key = key.split(":")
if len(key) != 2:
raise ValueError(errmsg)
Expand Down
5 changes: 3 additions & 2 deletions snakemake/common/__init__.py
Expand Up @@ -60,12 +60,13 @@ def mb_to_mib(mb):
return int(math.ceil(mb * 0.95367431640625))


def parse_key_value_arg(arg, errmsg):
def parse_key_value_arg(arg, errmsg, strip_quotes=True):
try:
key, val = arg.split("=", 1)
except ValueError:
raise ValueError(errmsg + f" (Unparseable value: {repr(arg)})")
val = val.strip("'\"")
if strip_quotes:
val = val.strip("'\"")
return key, val


Expand Down
4 changes: 2 additions & 2 deletions snakemake/resources.py
Expand Up @@ -532,10 +532,10 @@ def generic_callable(val, threads_arg, **kwargs):
if not is_file_not_found_error(e, kwargs["input"]):
# Missing input files are handled by the caller
raise WorkflowError(
"Failed to evaluate default resources value "
"Failed to evaluate resources value "
f"'{val}'.\n"
" String arguments may need additional "
"quoting. Ex: --default-resources "
"quoting. E.g.: --default-resources "
"\"tmpdir='/home/user/tmp'\".",
e,
)
Expand Down
33 changes: 0 additions & 33 deletions tests/Snakefile

This file was deleted.

9 changes: 9 additions & 0 deletions tests/test_resource_string_in_cli_or_profile/Snakefile
@@ -0,0 +1,9 @@
# fails when submitted as
# $ snakemake --executor slurm -j2 --workflow-profile ./profiles/ --default-resources slurm_account=m2_zdvhpc

rule all:
input: "a.out"

rule test1:
output: "a.out"
shell: "touch {output}"
Empty file.
@@ -0,0 +1,4 @@
set-resources:
test1:
slurm_partition: "smp"
slurm_extra: "'--nice=150'"
11 changes: 11 additions & 0 deletions tests/tests.py
Expand Up @@ -1969,6 +1969,17 @@ def test_issue1256():
assert "line 9" in stderr


def test_resource_string_in_cli_or_profile():
test_path = dpath("test_resource_string_in_cli_or_profile")
profile = os.path.join(test_path, "profiles")
# workflow profile is loaded by default
run(
test_path,
snakefile="Snakefile",
shellcmd=f"snakemake --workflow-profile {profile} -c1 --default-resources slurm_account=foo other_resource='--test'",
)


def test_queue_input():
run(dpath("test_queue_input"))

Expand Down