-
-
Notifications
You must be signed in to change notification settings - Fork 409
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 pre-commit hook with Black #1573
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1573 +/- ##
=======================================
Coverage 61.87% 61.87%
=======================================
Files 63 63
Lines 5852 5852
=======================================
Hits 3621 3621
Misses 2231 2231
Continue to review full report at Codecov.
|
Is this related to your issue? psf/black#1667 |
@epassaro, no, I don't think it's related. In that issue people got confused and thought that Black config doesn't get passed when used by pre-commit. However in our case it definitely gets passed. print("long", "long", "long", "long", "long", "long", "long", "long", "long", "long") This is 85 chars long, so should be formatted according to our config. And it does get formatted when I try to commit. So it somehow picks up line length config from .toml but ignores excluded files config 🤔 I'm just going to ask in pre-commit/Black community now. |
Alright, I think it is an unavoidable limitation because pre-commit basically runs Black against individual files (if you do the same with Black directly it will also format). So exclude files/dirs should be duplicated in pre-commit config for Black :/ See this comment for a similar question about |
By default Black excludes files in .gitignore and a bunch of others. If you use Then I just copied that explicit exclude list to |
Should I split this into two PRs according to #1563? |
@jaladh-singhal implemented |
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.
Everything looks great - thanks for effort @Molkree. This will surely save users from enabling black on their own but I'm not sure if it's advantageous enough that we should add pre-commit hooks for black, why:
- If contributor's code hasn't followed black formatting, black checking workflow will fail on PR and prevent us from merging it unless it is formatted.
- This will add
pre-commit
as new dependency and except black, we don't need it as of now for anything else - even for black it's optional (as mentioned in 1st point).
@wkerzendorf @andrewfullard should have final say in this.
This was already discussed in #1170 and I haven't seen any objections. And in #1405 you mentioned "enforcing by pre-commit hook will be in another PR" :O What has changed since January? |
Rebased on master to solve merge conflict in README.rst |
IMHO |
@Molkree #1398 made it possible to enforce black (though not necessarily by pre-commit hook that I mentioned at that time thinking that's the only way to do it). Good reminder BTW, I've closed #1170 |
Before a pull request is accepted, it must meet the following criteria:
|
That's true but in my opinion "please install pre-commit once if you want to contribute" is better than "please run Black before each commit if you want to contribute". Just a matter of convenience, everyone can forget to run formatter (just look at PRs, 2 out of the last 10 had commits fixing Black). |
@epassaro Also is this your opinion or request for change as a member of Tardis? |
This needs rebasing |
@andrewfullard, rebased |
Hm, I see there's a failing check, should I add myself to .mailmap? |
Yes please, that should fix the failure. |
We recently moved to the new Astropy package template. I want to keep their |
@andrewfullard, mailmap fixed |
@epassaro I'd like your review on this. |
I'll review this soon 🤞 |
After some discussion this has been considered unnecessary because we have the PR check in place for |
Description
pre-commit
to the conda environment file.pre-commit
config with Black to the root. Install withpre-commit install
.pre-commit
badge to Readme.Opening this early but I have encountered one issue. When I commit something that shouldn't pass Black it correctly gets changed. I have tested line longer than 80 chars but shorter than default 88 chars to check thatResolved, see comments below.pre-commit
Black sees Black config. But at the same time, it still tries to modify files that it shouldn't. I have changed something insidetardis/montecarlo
which should be excluded from the check but when I try to commit it formats there as well 🤔 Not sure if it's my mistake or Black/pre-commit limitation, help is appreciated here.Motivation and context
This is part of #1572.
How has this been tested?
Type of change
Checklist
Not yet, will add it next. I guess only need to mention it in Git workflow and Code quality Black section.