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

Else branch after conditional include breaks depending on subsequent code #239

Open
lczech opened this issue Jul 11, 2024 · 2 comments
Open

Comments

@lczech
Copy link

lczech commented Jul 11, 2024

I think this is a regression of #115, or an extension of the issue reported there.

Minimal example, using snakefmt v0.10.2:

if condition:
    include: "my_rule.smk"
else:
    raise Exception("Condition not given")

if other_condition:
    rule other_rule:
        input:
            somefile

The error is:

snakefmt.exceptions.InvalidPython: Black error:
Cannot parse: 3:0: else:

Removing the second conditional part however solves this, despite that part not having anything to do with the condition that causes the problem.

My current workaround is to rewrite the else branch as

if not condition:
    raise Exception("Condition not given")

but since in my actual code I have a few elif befor that, this is quite cumbersome.

@lczech
Copy link
Author

lczech commented Jul 11, 2024

Just ran into a similar, but slightly different variant of this while trying to format another file.

Minimal example:

if condition_1:

    include: "rule_1.smk"

elif condition_2:

    pass

else:

    raise Exception("Invalid conditions")

Fails with

snakefmt.exceptions.InvalidPython: Black error:
Cannot parse: 1:0: elif condition_2:
(Note reported line number may be incorrect, as snakefmt could not determine the true line number)

Here, removing either the elif, or the else branch then works. However, interestingly, it also works to replace the pass under condition 2 by another include statement:

if condition_1:

    include: "rule_1.smk"

elif condition_2:

    include: "dummy.smk"

else:

    raise Exception("Invalid conditions")

This works.

@mbhall88
Copy link
Member

Oh, very weird. I'll take a look soon hopefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants