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

flake8 precommit hook #1449

Merged
merged 5 commits into from
Jan 5, 2023
Merged

flake8 precommit hook #1449

merged 5 commits into from
Jan 5, 2023

Conversation

mstimberg
Copy link
Member

Continuing the work started with #1435 to make Brian's code more readable and "best practice" compatible, this adds another precommit hook, this time for flake8. It will flag common issues such as local variables or imports that are never used, or minor stylistic issues such as using not element in list instead of element not in list. I configured it in a conservative way to not be too radical/annoying for Brian's code base, e.g. I excluded all tests and __init__.py files, since they use wildcard imports quite extensively.

Not sure anyone cares about this very much, but tagging @oleksii-leonov, @bdevans, @denisalevi just in case 😋

In particular, the code no longer triggers the following flake8
messages:
B001, B004, B006, B008, B009
E101, E231, E262, E302, E712, E713, E714, E741
F481, F541
W191, W291, W293
Copy link
Contributor

@bdevans bdevans left a comment

Choose a reason for hiding this comment

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

Looks good to me!
Just one point to mention, there are now several files to keep in sync with versions of dependencies e.g. .pre-commit-config.yaml and .devcontainer/dev-requirements.txt. Would it be possible to consolidate them all into one location that gets read by the others?

@mstimberg
Copy link
Member Author

Thanks @bdevans.

Just one point to mention, there are now several files to keep in sync with versions of dependencies e.g. .pre-commit-config.yaml and .devcontainer/dev-requirements.txt. Would it be possible to consolidate them all into one location that gets read by the others?

I was wondering about the same thing, but I did not find an easy solution. We could use an approach like the one described here: pre-commit/pre-commit#945 (comment) , which would mean that pre-commit wouldn't install anything but just use what is installed on the system. This would be ok for running the pre-commit hooks in the CI, but for running them locally it would mean that we lose the isolation that pre-commit provides. The user could update a tool locally, and thereby potentially change the result of applying the hooks – this would be very confusing if the commit then gets refused by the CI on GitHub.
Going the other way, i.e. somehow parsing .pre-commit-config.yaml and using it to pip install requirements is probably the better way. If anyone wants to have a go at anything like that, please go ahead 😉

@mstimberg mstimberg merged commit bf170ee into master Jan 5, 2023
@mstimberg mstimberg deleted the flake8-precommit branch January 5, 2023 18:00
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