diff --git a/docs/snakefiles/deployment.rst b/docs/snakefiles/deployment.rst index 0a0aedcef..fe4b2031d 100644 --- a/docs/snakefiles/deployment.rst +++ b/docs/snakefiles/deployment.rst @@ -353,7 +353,15 @@ Post-deployment scripts must be placed next to their corresponding environment-f └── interproscan.post-deploy.sh The path of the conda environment can be accessed within the script via ``$CONDA_PREFIX``. +Importantly, if the script relies on certain shell specific syntax, (e.g. `set -o pipefail` for bash), make sure to add a matching shebang to the script, e.g.: +.. code-block:: bash + + #!env bash + set -o pipefail + # ... + +If no shebang line like above (``#!env bash``) is provided, the script will be executed with the ``sh`` command. .. _conda_named_env: diff --git a/docs/snakefiles/rules.rst b/docs/snakefiles/rules.rst index fb195befc..8b0e604da 100644 --- a/docs/snakefiles/rules.rst +++ b/docs/snakefiles/rules.rst @@ -27,6 +27,7 @@ Inside the shell command, all local and global variables, especially input and o Here, input and output (and in general any list or tuple) automatically evaluate to a space-separated list of files (i.e. ``path/to/inputfile path/to/other/inputfile``). From Snakemake 3.8.0 on, adding the special formatting instruction ``:q`` (e.g. ``"somecommand {input:q} {output:q}")``) will let Snakemake quote each of the list or tuple elements that contains whitespace. +By default shell commands will be invoked with ``bash`` shell (unless the workflow specifies a different default shell via ``shell.executable(...)``). Instead of a shell command, a rule can run some python code to generate the output: diff --git a/snakemake/deployment/conda.py b/snakemake/deployment/conda.py index cb0bb2359..a80a88a19 100644 --- a/snakemake/deployment/conda.py +++ b/snakemake/deployment/conda.py @@ -350,8 +350,16 @@ def execute_deployment_script(self, env_file, deploy_file): os.path.relpath(path=deploy_file, start=os.getcwd()) ) ) + + # Determine interpreter from shebang or use sh as default. + interpreter = "sh" + with open(deploy_file, "r") as f: + first_line = next(iter(f)) + if first_line.startswith("#!"): + interpreter = first_line[2:].strip() + shell.check_output( - self.conda.shellcmd(self.address, "sh {}".format(deploy_file)), + self.conda.shellcmd(self.address, f"{interpreter} {deploy_file}"), stderr=subprocess.STDOUT, ) diff --git a/test.sh b/test.sh new file mode 100755 index 000000000..8001ceb0e --- /dev/null +++ b/test.sh @@ -0,0 +1,5 @@ +set -o pipefail + +echo $BASH + +echo test