Skip to content

Commit

Permalink
fix: Enable values with an = sign in default_resources (#2340)
Browse files Browse the repository at this point in the history
### Description

In the default_resources block in a profile, variables cannot contain =
signs; this is, however, needed to specify slurm_extra (e.g.,
--mail-type=none). The reason is in
https://github.com/snakemake/snakemake/blob/main/snakemake/resources.py#L23:
the argument is split by the = sign; this leads to an error if the
result contains more than 2 elements (which occurs when there is more
than one = sign).

Closes #2290 

### 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).

---------

Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
  • Loading branch information
3 people committed Aug 3, 2023
1 parent ad6eaef commit c1c9229
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion snakemake/resources.py
Expand Up @@ -20,7 +20,7 @@ class DefaultResources:
@classmethod
def decode_arg(cls, arg):
try:
return arg.split("=")
return arg.split("=", maxsplit=1)
except ValueError:
raise ValueError("Resources have to be defined as name=value pairs.")

Expand Down
17 changes: 17 additions & 0 deletions tests/test_slurm.py
Expand Up @@ -80,3 +80,20 @@ def test_slurm_complex():
]
),
)


@skip_on_windows
def test_slurm_extra_arguments():
"""Make sure arguments to default resources
are allowed to contain = signs, which is needed
for extra slurm arguments"""
run(
dpath("test_slurm_mpi"),
slurm=True,
show_failed_logs=True,
use_conda=True,
default_resources=DefaultResources(
["slurm_account=runner", "slurm_partition=debug",
"slurm_extra='--mail-type=none'"]
),
)

0 comments on commit c1c9229

Please sign in to comment.