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

Regression in 0.8.0: some comments cause "InvalidPython: Black error:" #169

Closed
corneliusroemer opened this issue Dec 20, 2022 · 7 comments · Fixed by #173
Closed

Regression in 0.8.0: some comments cause "InvalidPython: Black error:" #169

corneliusroemer opened this issue Dec 20, 2022 · 7 comments · Fixed by #173
Labels
bug Something isn't working

Comments

@corneliusroemer
Copy link

corneliusroemer commented Dec 20, 2022

Testing new release 0.8.0 I noticed a small regression

if config.get("s3_dst"):
    rule one:
        # test
        # test
        output:
            touch("data/one.txt"),

Does not format with:

InvalidPython: Black error:
Cannot parse: 5:0: <line number missing in source>Snakefmt(snakefmt:black-error:invalid-python)

Two comments in a row don't work, maybe this isn't valid snakemake? Not sure.

This is not a big bug, as one can simply put a triple quoted string there instead. Also it's good that it simply fails formatting rather than formatting to something that changes semantics.

cc @mbhall88

@mbhall88
Copy link
Member

This is valid snakemake. It will be an issue in snakefmt - comments are surprisingly difficult to deal with.

@mbhall88 mbhall88 added the bug Something isn't working label Dec 20, 2022
@ptrebert
Copy link

fwiw, here is another example that triggers that error:

rule foo:
    input:
        [],
    run:
        # some comment
        x = 3

@corneliusroemer
Copy link
Author

Ooh, that latter bug is nastier @ptrebert as it's much more likely to be in common use. Did you find that by running 0.8.0 on a standard code base?

@ptrebert
Copy link

stuff like that is flagged in several of my snakemake files. I would definitely agree that this is quite common (or should be, because we all diligently comment our code, right 😉 )

@y9c
Copy link

y9c commented Dec 27, 2022

Any double comment lines will cause the error?

configfile: "config.yaml"

# AAA
# BBB

BATCH =        "20220202"

This one also cause error in version 0.8.

[DEBUG]
snakefmt.exceptions.InvalidPython: Black error:

Cannot parse: 4:0:     BATCH = "20220202"

(Note reported line number may be incorrect, as snakefmt could not determine the true line number)

@corneliusroemer corneliusroemer changed the title Small regression in 0.8.0 Regression in 0.8.0: some comments cause "InvalidPython: Black error:" Jan 25, 2023
@corneliusroemer
Copy link
Author

corneliusroemer commented Jan 25, 2023

Another example of probably the same bug:

onstart:
    # Saves onstart Slack message thread timestamp to file SLACK_TS_FILE
    shell(
        f"./bin/notify-on-start {config.get('build_name', 'unknown')} {SLACK_TS_FILE}"
    )

Workaround with docstring """ comment """ doesn't work here, need to add the comment as inline after the )

corneliusroemer added a commit to nextstrain/mpox that referenced this issue Jan 25, 2023
corneliusroemer added a commit to nextstrain/mpox that referenced this issue Jan 25, 2023
@mbhall88
Copy link
Member

Thanks, I'm currently working on this issue, hopefully will have something in the next day or two

mbhall88 added a commit to mbhall88/snakefmt that referenced this issue Jan 27, 2023
mbhall88 added a commit to mbhall88/snakefmt that referenced this issue Jan 27, 2023
* add failing test for comment in run block

snakemake#169 (comment)

* fix incorrect test

* add and fix two tests

* fix test case with two comments in global context

* add test with comment after onstart
mbhall88 added a commit that referenced this issue Feb 2, 2023
* add failing test for comment in run block

#169 (comment)

* fix incorrect test

* add and fix two tests

* fix test case with two comments in global context

* add test with comment after onstart
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

Successfully merging a pull request may close this issue.

4 participants