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

Incorrect shell indenting with snakefmt 0.8.2 and black 23.1.0 #186

Closed
GianlucaFicarelli opened this issue Mar 15, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@GianlucaFicarelli
Copy link

Hello, I get some unexpected formatting when using the current versions:

  • snakefmt 0.8.2
  • black 23.1.0
  • python 3.10

See these examples, produced after calling snakefmt Snakefile:

rule test1:
    input:
        "...",
    output:
        "...",
    shell:
        myfunc(
            "param1",
            [
                "item1",
            f"very_long_item2_{very_long_function(other_param)}"
                if some_very_long_condition
                else "",
            ],
        )


rule test2:
    input:
        "...",
    output:
        "...",
    shell:
        myfunc(
            "param1",
            [
                "item1",
            f"very_long_item2_{very_long_function(other_param)}"
                if some_very_long_condition
                else "",
                "item10",
                    "item11",
                    "item12",
                ]
                + [
                f"sub_{item}"
                for item in [
                    "item2",
                    "item3",
                ]
            ],
        )


rule test3:
    input:
        "...",
    output:
        "...",
    shell:
        myfunc(
            "item1",
            [
                "sub_item1",
            "sub_item2"
                if some_very_very_very_very_very_very_very_very_long_condition
                else "sub_item3",
                "sub_item4",
            ],
        )

For comparison, the same function calls, indented at the same level and formatted with black, are:

def test_comparison_with_black():
    def inner():
        myfunc(
            "param1",
            [
                "item1",
                f"very_long_item2_{very_long_function(other_param)}"
                if some_very_long_condition
                else "",
            ],
        )
        myfunc(
            "param1",
            [
                "item1",
                f"very_long_item2_{very_long_function(other_param)}"
                if some_very_long_condition
                else "",
                "item10",
                "item11",
                "item12",
            ]
            + [
                f"sub_{item}"
                for item in [
                    "item2",
                    "item3",
                ]
            ],
        )
        myfunc(
            "item1",
            [
                "sub_item1",
                "sub_item2"
                if some_very_very_very_very_very_very_very_very_long_condition
                else "sub_item3",
                "sub_item4",
            ],
        )

Instead, the format is correct when using these old versions:

  • snakefmt 0.4.2
  • black 20.8b1
  • python 3.10
@mbhall88
Copy link
Member

Could you please post an example before formatting?

@mbhall88 mbhall88 changed the title Incorrect format with snakefmt 0.8.2 and black 23.1.0 Incorrect shell indenting with snakefmt 0.8.2 and black 23.1.0 Mar 15, 2023
@GianlucaFicarelli
Copy link
Author

Could you please post an example before formatting?

Sure, the content before formatting can be the already formatted code as in the second snippet, that will be "unformatted" after processing it.

Here is the corresponding Snakefile that can be used as input:

rule test1:
    input:
        "...",
    output:
        "...",
    shell:
        myfunc(
            "param1",
            [
                "item1",
                f"very_long_item2_{very_long_function(other_param)}"
                if some_very_long_condition
                else "",
            ],
        )


rule test2:
    input:
        "...",
    output:
        "...",
    shell:
        myfunc(
            "param1",
            [
                "item1",
                f"very_long_item2_{very_long_function(other_param)}"
                if some_very_long_condition
                else "",
                "item10",
                "item11",
                "item12",
            ]
            + [
                f"sub_{item}"
                for item in [
                    "item2",
                    "item3",
                ]
            ],
        )


rule test3:
    input:
        "...",
    output:
        "...",
    shell:
        myfunc(
            "item1",
            [
                "sub_item1",
                "sub_item2"
                if some_very_very_very_very_very_very_very_very_long_condition
                else "sub_item3",
                "sub_item4",
            ],
        )

@mbhall88
Copy link
Member

This is fixed in v0.9.0

bricoletc added a commit to bricoletc/snakefmt that referenced this issue Jan 31, 2024
mbhall88 pushed a commit that referenced this issue Jan 31, 2024
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