-
Notifications
You must be signed in to change notification settings - Fork 441
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
switch to pre-commit #2392
switch to pre-commit #2392
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2392 +/- ##
==========================================
- Coverage 93.60% 93.53% -0.07%
==========================================
Files 74 74
Lines 15831 15831
==========================================
- Hits 14818 14808 -10
- Misses 1013 1023 +10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. LGTM with a small fix.
Co-authored-by: Tetsuo Koyama <tkoyama010@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, I've been meaning to do that for a while but never got around to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great addition which will save a lot of time :)
I haven't tested it locally, but what happens if multiple formatting steps would fail (e.g. both black
and isort
have to modify files)? Do you have to commit again for each separate step or are all changes performed at once, requiring only a single new commit attempt afterwards?
Also does the error message explicitly say to try and commit again, because otherwise it might be quite confusing as to why commiting failed exactly?
Co-authored-by: Andras Deak <adeak@users.noreply.github.com>
The attempted commit is aborted and changes are made to the local workspace, in the case of black and isort. You have to One additional benefit of pre-commit is that it runs against the code being committed, which prevents errors when you forget to stage changes. |
Added in a few other pre-commit checks:
|
tl;dr
Let's use
pre-commit
to simplify our lives and make it easier and more fun to contribute.Problem
We're quite strict about our code standards, and that's great! We're writing consistent, readable code that many people feel comfortable contributing to. The problem with our existing approach is it's:
This makes it really, really annoying to ensure commits meet coding standards as one has to fire off one or more make commands and remember to do it.
Proposed Solution
This PR suggests we use pre-commit as done in pandas/.pre-commit-config.yaml to:
pre-commit
works on all major OSes, and is installed with:and then can be (manually) used with:
or "installed" as a pre-commit hook with:
where it will be run after every commit:
It only checks the files staged for the commit and is therefore wicked fast, something we want if we want contributors to want to use this tool. Best part is if something needs to be autoformatted by
black
orisort
, you run the tool, it modifies the files and tells you it failed, and then you simply commit again.It's super automatic and means we won't have to keep coming back to failed PRs because we had a character of whitespace on L2087.
Implementations
This PR removes:
requirements_style.txt
andrequirements_static.txt
and these versions are now tracked in.pre-commit-config.yaml
.Makefile
. "There should be one-- and preferably only one --obvious way to do it."