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

Bug: formatting break code when: if, for, and long char in two functions #190

Open
Hocnonsense opened this issue Apr 8, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Hocnonsense
Copy link

snakefmt cannot format this code:

if 1:

    rule a:
        input:
            a="a",
        run:
            for i in range(3):
                a = print(
                    "a",
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                )
                b = print(
                    print(
                        "sssssssssssssssssssssssssssssssssssssssssssssssss",
                        b="b"
                    )
                )

    rule b:
        shell:
            "echo 1"

However, when I delete a "s" in line 14 or add a comma in line 15, snakefmt will work well. What happened? Thanks

@mbhall88
Copy link
Member

What do you mean by

snakefmt cannot format this code

Please be more specific and provided the version of snakefmt you are using and any error messages and output

@Hocnonsense
Copy link
Author

I'm sorry.

I tried to make a demo snakefile with this codes:

if 1:

    rule a:
        input:
            a="a",
        run:
            for i in range(3):
                a = print(
                    "a",
                    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                )
                b = print(
                    print(
                        "sssssssssssssssssssssssssssssssssssssssssssssssss",
                        b="b"
                    )
                )

    rule b:
        shell:
            "echo 1"

and I ran snakemake like this:

$ snakefmt -V
snakefmt, version 0.8.4
$ snakefmt test.smk
[INFO] Writing formatted content to 2023/04/11.smk
[INFO] All done 🎉
$ snakefmt test.smk
snakefmt.exceptions.InvalidPython: Black error:
\`\`\`
Cannot parse: 12:0:             b = print(
\`\`\`

then I reopened this file, and the code changed like this:

if 1:

    rule a:
        input:
            a="a",
        run:
            for i in range(3):
                a = print(
                    "a",
                        "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
                    )
                    b = print(
                        print(
                    "sssssssssssssssssssssssssssssssssssssssssssssssss", b="b"
                    )
                )

    rule b:
        shell:
            "echo 1"

Obviously, the code was broken by snakefmt

@mbhall88 mbhall88 added the bug Something isn't working label Apr 11, 2023
@mbhall88
Copy link
Member

Thanks. Yep, this is a bug indeed. We'll try getting around to this soon. Thanks for the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants