Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snakefmt adds wrong indentation #124

Closed
FelixMoelder opened this issue Nov 22, 2021 · 8 comments · Fixed by #164
Closed

snakefmt adds wrong indentation #124

FelixMoelder opened this issue Nov 22, 2021 · 8 comments · Fixed by #164
Labels
help wanted Extra attention is needed

Comments

@FelixMoelder
Copy link
Collaborator

FelixMoelder commented Nov 22, 2021

It looks like snakefmt 0.4.4 adds wrong indentations when formatting a snakemake rule containing a if-else-closure.

As an example the following output will be created for a proper formatted rule:

--- original
+++ new
     params:
         datasources=(
             "-s {}".format(" ".join(config["annotations"]["dgidb"]["datasources"]))
-            if config["annotations"]["dgidb"].get("datasources", "")
-            else ""
+        if config["annotations"]["dgidb"].get("datasources", "")
+        else ""
         ),
     output:
         "results/calls/{prefix}.dgidb.bcf",

A minimal example is attached.
Snakefile.zip

@johanneskoester
Copy link
Contributor

This is the full rule:

rule annotate_dgidb:
    input:
        "results/calls/{prefix}.bcf",
    params:
        datasources=(
            "-s {}".format(" ".join(config["annotations"]["dgidb"]["datasources"]))
            if config["annotations"]["dgidb"].get("datasources", "")
            else ""
        ),
    output:
        "results/calls/{prefix}.dgidb.bcf",
    log:
        "logs/annotate-dgidb/{prefix}.log",
    conda:
        "../envs/rbt.yaml"
    resources:
        dgidb_requests=1,
    shell:
        "rbt vcf-annotate-dgidb {input} {params.datasources} > {output} 2> {log}"

@johanneskoester
Copy link
Contributor

The part with the if config else is moved to the left.

@mbhall88
Copy link
Member

mbhall88 commented Dec 1, 2021

I think this is potentially connected to #115. I'm pretty vague on how the if-else parsing works. @bricoletc might be better able to figure this out.

@bricoletc
Copy link
Collaborator

bricoletc commented Dec 2, 2021

Apologies I've got low bandwith at the moment, with my last year of thesis, (and @mbhall88 is defending his!) however i will take a look at it in the next few weeks

@siebrenf
Copy link

siebrenf commented Dec 6, 2021

This also happens with nesting outside (but in combination with) rules. Here is a minimal example:

if True:
    def func1():
        """this function will stay indented"""
        pass

    rule break_snakefmt_044:
        shell: ""

    def func2():
        """this function will be unindented"""
        pass

@corneliusroemer
Copy link

I think this label could get a help wanted label? Assuming it's doable for a non-maintainer to tackle.

@mbhall88 mbhall88 added the help wanted Extra attention is needed label Sep 6, 2022
@mbhall88
Copy link
Member

mbhall88 commented Sep 6, 2022

Feel free to tackle this @corneliusroemer. It has been bugging me too. I'm still trying to figure out a couple of issues on #151 and then I was going to try and tackle this. But feel free to have a go 👍

mbhall88 added a commit to mbhall88/snakefmt that referenced this issue Dec 1, 2022
mbhall88 added a commit to mbhall88/snakefmt that referenced this issue Dec 7, 2022
@mbhall88
Copy link
Member

mbhall88 commented Dec 8, 2022

I wonder if anyone would like to test out #164 as that fixes the two examples in this issue?

bricoletc added a commit to mbhall88/snakefmt that referenced this issue Dec 9, 2022
* Bugfix: Hard-coded tab length
* Bugfix: indent level passed to black str formatting
* Refactor: 'after_if' testing
mbhall88 added a commit that referenced this issue Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants