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

Add snakefmt to pre-commit #352

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MilesCranmer
Copy link
Contributor

@MilesCranmer MilesCranmer commented Apr 28, 2023

Seems like a good addition given the number of snakemake files and the fact that black is already used for Python:

This repository provides formatting for Snakemake files. It follows the design and specifications of Black.

@dfm
Copy link
Member

dfm commented Apr 28, 2023

This looks great too! Can you fix the conflicts and try to see what the pre-commit failure is being caused by? Here is the error log:

trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
isort....................................................................Passed
black-jupyter............................................................Passed
pycln....................................................................Passed
snakefmt.................................................................Failed
- hook id: snakefmt
- exit code: 1

snakefmt.exceptions.InvalidPython: Black error:
```
Cannot parse: 89:0: else:
```

Seems to be a syntax error somewhere, but it's not very clear :D

@MilesCranmer
Copy link
Contributor Author

This syntax error happens on master as well. It's due to build.smk on this line:

This is at the limits of my snakemake knowledge as I didn't even know you could have rules within if statements. Any idea?

@MilesCranmer
Copy link
Contributor Author

Nevermind I fixed it. Snakefiles are a little too expressive for my taste; it was some issue where it couldn't tell where a block ended and the next one began, so I put a pass at one indent down so the formatter could figure out it had to exit the scope.

@@ -18,44 +22,39 @@ workdir: paths.user().repo.as_posix()
# What kind of run is this? (clean, build, etc.)
run_type = get_run_type()

if not (paths.user().temp / "config.json").exists() and run_type != "clean":
raise exceptions.MissingConfigFile()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made a second if statement instead of an else. But I'm not sure if onsuccess refers to the original if statement or not?

Also - with this exception raised at the top, does the rest even need to be embedded in an if statement?

Copy link
Member

@dfm dfm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some tiny inline comments, but this otherwise looks great!

# Remove old flags
for file in paths.user().flags.glob("*"):
file.unlink()


# Set up custom logging for Snakemake
# Set up custom logging for Snakemake
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This formatting is wrong. Are there settings that we can change in snakefmt?


if run_type != "clean":
raise exceptions.MissingConfigFile()
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After adding the new conditional at the top, this isn't still needed anymore, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are correct.

Actually, could the entire if statement be removed now, since the check is at the top?

@MilesCranmer
Copy link
Contributor Author

It looks like this might be a bug in snakefmt: snakemake/snakefmt#190 and snakemake/snakefmt#186

We could wait to merge this until those bugs are fixed, lest it produces a bug on our side due to incorrect formatting. Wdyt?

@dfm
Copy link
Member

dfm commented May 1, 2023

Sounds like a plan to me!

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

Successfully merging this pull request may close these issues.

2 participants