snakefmt corrupts heredoc string
See original GitHub issuesnakefmt v0.4.0 reformats this rule:
rule one:
output:
out_file="out.txt",
shell:
r"""
cat <<'EOF'> tmp.txt
touch {output}
EOF
bash tmp.txt
"""
into:
rule one:
output:
out_file="out.txt",
shell:
r"""
cat <<'EOF'> tmp.txt
touch {output}
EOF
bash tmp.txt
"""
the reformatted indentation makes the heredoc invalid since bash expects the closing EOF
at the start of the line. When execute it I get:
snakemake -p -j 1
Building DAG of jobs...
Using shell: /bin/bash
Provided cores: 1 (use --cores to define parallelism)
Rules claiming more threads will be scaled down.
Job stats:
job count min threads max threads
----- ------- ------------- -------------
all 1 1 1
one 1 1 1
total 2 1 1
Select jobs to execute...
[Tue Oct 26 09:06:30 2021]
rule one:
output: out.txt
jobid: 1
resources: tmpdir=/tmp
cat <<'EOF'> tmp.txt
touch out.txt
EOF
bash tmp.txt
/bin/bash: line 6: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
Waiting at most 5 seconds for missing files.
I tried to upgrade to snakefmt 0.4.4 using mamba. This maybe a separate issue, I get:
mamba update snakefmt # Completes OK and installs 0.4.4
snakefmt -h
Traceback (most recent call last):
File "/home/dario/miniconda3/envs/tritume/bin/snakefmt", line 6, in <module>
from snakefmt.snakefmt import main
File "/home/dario/miniconda3/envs/tritume/lib/python3.6/site-packages/snakefmt/snakefmt.py", line 9, in <module>
from black import get_gitignore
File "/home/dario/miniconda3/envs/tritume/lib/python3.6/site-packages/black/__init__.py", line 48, in <module>
from black.files import find_project_root, find_pyproject_toml, parse_pyproject_toml
File "/home/dario/miniconda3/envs/tritume/lib/python3.6/site-packages/black/files.py", line 26, in <module>
from black.handle_ipynb_magics import jupyter_dependencies_are_installed
File "/home/dario/miniconda3/envs/tritume/lib/python3.6/site-packages/black/handle_ipynb_magics.py", line 15, in <module>
from typing_extensions import TypeGuard
ImportError: cannot import name 'TypeGuard'
Issue Analytics
- State:
- Created 2 years ago
- Comments:18 (8 by maintainers)
Top Results From Across the Web
Increased indenting of shell strings · Issue #121 - GitHub
When running with snakefmt, it wants to format this to. rule a: shell: "(kallisto quant ... snakefmt corrupts heredoc string #123.
Read more >snakefmt - PyPI
As snakefmt has a Conda recipe, there is a matching image built for each ... input: files = expand("long/string/to/data/files/gets_broken_by_black/{sample}.
Read more >Snakefmt - :: Anaconda.org
noarch v0.7.0. conda install. To install this package run one of the following: conda install -c bioconda snakefmt. Description.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bricoletc :
I suspect that is going to be tricky because
EOF
is not a special keyword. You can delimit the heredoc with any string you like (well, not any string…). Other tricky cases could be like:Personally, I would leave the content of the strings alone and just re-align the opening and closing quotes.
I would be happy for r-strings to be left alone (I got the habit of always using r-strings for shell directives unless required otherwise) but I would still consider it a bug. A user may write a heredoc without r-formatting and find it broken after snakefmt.