Skip to content

Commit

Permalink
fix: correctly set params in bash scripts (#3188)
Browse files Browse the repository at this point in the history
<!--Add a description of your PR here-->

This PR tweaks the Bash script test to trigger the bug raised in #3187 

### 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.
* [ ] 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).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Tests**
	- Enhanced error handling in the script with improved shell options.
- Added a conditional test to validate parameters before executing
existing commands.
- Updated input parameter in the `bash` rule for clarity without
affecting functionality.
- **New Features**
- Improved parameter handling in the Bash script generation process for
enhanced functionality.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: coderabbitai[bot] <136622811 coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
mbhall88 and coderabbitai[bot] authored Nov 11, 2024
1 parent 5f651d2 commit 07ddab5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
12 changes: 10 additions & 2 deletions snakemake/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 419,8 @@ def encode_snakemake(self, smk: Snakemake) -> str:
for var in vars(smk):
val = getattr(smk, var)
if var in self.namedlists:
aa = f"{self.prefix}_{var.strip('_').lower()}={self.encode_namedlist(val)}"
suffix = "params" if var == "_params_store" else var.strip("_").lower()
aa = f"{self.prefix}_{suffix}={self.encode_namedlist(val)}"
arrays.append(aa)
elif var in self.dicts:
aa = f"{self.prefix}_{var.strip('_').lower()}={self.dict_to_aa(val)}"
Expand Down Expand Up @@ -1438,7 1439,14 @@ def generate_preamble(
scriptdir=path.get_basedir().get_path_or_uri(),
)

namedlists = ["input", "output", "log", "resources", "wildcards", "params"]
namedlists = [
"input",
"output",
"log",
"resources",
"wildcards",
"_params_store",
]
dicts = ["config"]
encoder = BashEncoder(namedlists=namedlists, dicts=dicts)
preamble = encoder.encode_snakemake(snakemake)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_script/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 104,7 @@ rule:
rule bash:
input:
"test2.in",
named_input="test.in",
named="test.in",
output:
"bash.out"
params:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_script/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 1,7 @@
#!/usr/bin/env bash
set -euo pipefail
exec 2> "${snakemake_log[0]}"
test "${snakemake_params[string]}" = "foo"

echo "The first input file is ${snakemake_input[0]}" > "${snakemake_output[0]}" 2> "${snakemake_log[0]}"
echo "The named input file is ${snakemake_input[named]}" >> "${snakemake_output[0]}" 2>> "${snakemake_log[0]}"
Expand Down

0 comments on commit 07ddab5

Please sign in to comment.