question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

snakefmt corrupts heredoc string

See original GitHub issue

snakefmt 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:closed
  • Created 2 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
dariobercommented, Jun 27, 2022

@bricoletc :

some regexp capturing EOF, e.g. "<<['"]EOF

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:

shell:
    """
    python -c "
    ...some properly indented python code here. Possibly containing raw-formatted strings...?
    "
    """

Personally, I would leave the content of the strings alone and just re-align the opening and closing quotes.

1reaction
dariobercommented, Oct 29, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found