Skip to content

Commit

Permalink
fix: fix quoting issues when passing complex apptainer args to spawne…
Browse files Browse the repository at this point in the history
…d jobs (#2898)

Fixes #2808 and
#2872 by using base64
encoding when passing apptainer args to spawned jobs.

### 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).
  • Loading branch information
johanneskoester committed May 27, 2024
1 parent 31a9c9b commit b07e2e0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions snakemake/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@ def get_argument_parser(profiles=None):
"--singularity-args",
default="",
metavar="ARGS",
parse_func=maybe_base64(str),
help="Pass additional args to apptainer/singularity.",
)

Expand Down
2 changes: 1 addition & 1 deletion snakemake/spawn_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def general_args(
skip=not shared_deployment,
),
w2a("deployment_settings.apptainer_prefix"),
w2a("deployment_settings.apptainer_args"),
w2a("deployment_settings.apptainer_args", base64_encode=True),
w2a("resource_settings.max_threads"),
self.get_shared_fs_usage_arg(executor_common_settings),
w2a(
Expand Down
2 changes: 2 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def run(
storage_provider_settings=None,
shared_fs_usage=None,
benchmark_extended=False,
apptainer_args="",
):
"""
Test the Snakefile in the path.
Expand Down Expand Up @@ -366,6 +367,7 @@ def run(
conda_frontend=conda_frontend,
conda_prefix=conda_prefix,
deployment_method=deployment_method,
apptainer_args=apptainer_args,
),
snakefile=Path(original_snakefile if no_tmpdir else snakefile),
workdir=Path(path if no_tmpdir else tmpdir),
Expand Down
6 changes: 6 additions & 0 deletions tests/test_singularity/qsub
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
echo `date` >> qsub.log
tail -n1 $1 >> qsub.log
# simulate printing of job id by a random number
echo $RANDOM
sh $1
11 changes: 11 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,17 @@ def test_singularity():
run(dpath("test_singularity"), deployment_method={DeploymentMethod.APPTAINER})


@skip_on_windows
@connected
def test_singularity_cluster():
run(
dpath("test_singularity"),
deployment_method={DeploymentMethod.APPTAINER},
cluster="./qsub",
apptainer_args="--bind /tmp:/tmp",
)


@skip_on_windows
def test_singularity_invalid():
run(
Expand Down

0 comments on commit b07e2e0

Please sign in to comment.