You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
black seems to be where the community is going -- NumPy is planning on using it I think (?), and from a quick look it looks like pandas and scikit-learn already do or are headed in that direction. I'm sure @agramfort has opinions/experience to share here :)
It's possible to make a single big commit that makes all the changes, then add this to a git blame ignore file, which removes the potential blame pollution which (to me) was a big barrier to adoption.
So overall +1 for moving to black from me using whatever pre-commit hooks or whatever pandas and scikit-learn have done (despite me actually not particularly liking how black code ends up looking sometimes!).
I can volunteer to help people rebase or merge PRs that are broken by the changes if they need help.
cc @cbrnr who mentioned wanting longer than 79 char line length, this would be one way to do it.
Thanks for opening your first issue here @larsoner 😆!
I'm reluctant to go all Black. Of course this alleviates us from all style-related issues, but on the other hand we sometimes want to use custom formatting to improve readability. This is just not possible with Black.
My vote is to just allow a line length of 92 characters for new code, so no changes are necessary for existing code. Of course, people are then free to rewrap a whole file as part of some other change.
you're so European minded Clemens :)
I would say it's either 0 or 1. Either we go with Black and follow what
sklearn / numpy do or we don't change.
let's not be exceptions here.
I'm not familiar with Black but I have a vague recollection that I didn't like some of the formatting rules it applies. What would be the benefit of switching to Black (apart from the fact that it seems to be a trend now)?
Currently I'm +1 on staying how it is.
@mmagnuski the benefit is that Black auto-formats everything. The issue is that Black auto-formats everything. So there is no in between if for some reason (readability) you would like to have some custom formatting.
standards are always a middle ground and a compromise. If you deviate
from the standard then it's useless and you are back to exceptions and
it can do more harm than good. Accept the standard as it is or don't
consider it.
I am in favor of black. I have adopted it for most of my projects and the few times that I have run into issues are heavily outweighed by the consistency, readability, and "ease of reading across projects" that black provides me with.
The issues that i have run into are furthermore typically minor: For example "I want this list to be in one line!" and then black puts it into multiple lines. I can really live with that.
I also use black together with isort to properly sort imports and with flake8 + flake8-docstrings to enforce a reasonable docstring formatting (numpy format).
That's not a good argument, especially not for MNE-Python. We recommend conda instead of pip, which would be the official tool hosted at PyPA (OK, it's not PSF, but it's basically the same thing).
do you think these situations outweigh the situations where our custom formatting currently makes readability worse? (especially "cross project readability")
I have not used Black extensively, so my experience is limited. I'm using a style which is already pretty close to Black, so maybe y'all are right and we should do it. It's probably really a lot better than our current style.
I looked more into what Black does and I think I'm fine with it. Things I don't like so much I can get used to. I'll test the vscode extension and will likely use it locally.
Is there something like pre-commit that will only run when you push instead of when you commit?
To answer my own question, apparently you can put any executable file into .git/hooks/pre-push so presumably we could set it up so that black runs before pushes, and aborts the push if the check fails.
just a note that after we do this, we should also add a .git-blame-ignore-revs file with the commit hash of the black-and-isort commits. See here for explanation:
There may be a few commits in the history we would want to add to that file as well? Not sure, sometimes big moves end up squashed in along with real code changes.
Does anyone have time in the near future to tackle the switch to Black formatting? Once this is implemented, I can enable Black as a pre-commit hook in #11541.
It would be nice to get #11152 in first if possible since it's big. Maybe #11064, too, but since I'm authoring that I'm not as worried about the rebase/merge. But I have this marked for 1.4 so it should hopefully get done within the next month.
please don't use black in a PR that changes things. I would prefer to have
only reformatting
in one PR so I don't have to scratch my head when reviewing.
Activity
welcome commentedon May 17, 2022
Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴🏽♂️
cbrnr commentedon May 17, 2022
Thanks for opening your first issue here @larsoner 😆!
I'm reluctant to go all Black. Of course this alleviates us from all style-related issues, but on the other hand we sometimes want to use custom formatting to improve readability. This is just not possible with Black.
My vote is to just allow a line length of 92 characters for new code, so no changes are necessary for existing code. Of course, people are then free to rewrap a whole file as part of some other change.
agramfort commentedon May 17, 2022
cbrnr commentedon May 17, 2022
I hope this is a compliment 😄?
If you really want all or nothing, I'm going to vote against Black.
Can we maybe still do a quick poll just to see what others think?
# noqaas a last resort)larsoner commentedon May 17, 2022
+0 on 1
+1 on 2
-1 on 3
agramfort commentedon May 17, 2022
mmagnuski commentedon May 18, 2022
I'm not familiar with Black but I have a vague recollection that I didn't like some of the formatting rules it applies. What would be the benefit of switching to Black (apart from the fact that it seems to be a trend now)?
Currently I'm +1 on staying how it is.
cbrnr commentedon May 18, 2022
@mmagnuski the benefit is that Black auto-formats everything. The issue is that Black auto-formats everything. So there is no in between if for some reason (readability) you would like to have some custom formatting.
agramfort commentedon May 18, 2022
cbrnr commentedon May 18, 2022
Black is not a standard, it's an opinionated formatter. Line lengths can be set even in Black (https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length), so in my opinion we could set only a new line length (to 92 or 88). I'm happy with our style, it's just the line lengths that bother me.
mmagnuski commentedon May 18, 2022
@cbrnr @agramfort
I'm also happy with our style (much more than what Black does). And I'm happy with current line limit - @cbrnr when is it an issue?
cbrnr commentedon May 18, 2022
Everytime. It's just not enough characters, I almost always have to break it up into multiple lines.
Most recent example: https://github.com/mne-tools/mne-python/pull/10638/files
With 92 characters, the line could have stayed one line:
Now it's this:
mmagnuski commentedon May 18, 2022
I'm neutral on changing the line limit - I rarely encounter such edge cases. And I'd be fine with:
in this particular case. :)
But I understand it can be a bit frustrating at times, when you are forced to perform line-length exercises.
sappelhoff commentedon May 18, 2022
I am in favor of black. I have adopted it for most of my projects and the few times that I have run into issues are heavily outweighed by the consistency, readability, and "ease of reading across projects" that black provides me with.
The issues that i have run into are furthermore typically minor: For example "I want this list to be in one line!" and then black puts it into multiple lines. I can really live with that.
I also use black together with isort to properly sort imports and with flake8 + flake8-docstrings to enforce a reasonable docstring formatting (numpy format).
6 remaining items
cbrnr commentedon May 19, 2022
I still think there are more people not using it.
That's not a good argument, especially not for MNE-Python. We recommend
condainstead ofpip, which would be the official tool hosted at PyPA (OK, it's not PSF, but it's basically the same thing).I have not used Black extensively, so my experience is limited. I'm using a style which is already pretty close to Black, so maybe y'all are right and we should do it. It's probably really a lot better than our current style.
mmagnuski commentedon May 19, 2022
I looked more into what Black does and I think I'm fine with it. Things I don't like so much I can get used to. I'll test the vscode extension and will likely use it locally.
agramfort commentedon May 20, 2022
we discussed during the MNE office hours.
I agreed that switching black is a way forward, although sticking with default black config.
please put your 👍 below this comment if you are on board
mmagnuski commentedon May 20, 2022
Ah, I keep forgetting about the MNE hours. I will try to join you next time!
drammock commentedon May 21, 2022
To answer my own question, apparently you can put any executable file into
.git/hooks/pre-pushso presumably we could set it up so thatblackruns before pushes, and aborts the push if the check fails.drammock commentedon Jun 15, 2022
just a note that after we do this, we should also add a
.git-blame-ignore-revsfile with the commit hash of the black-and-isort commits. See here for explanation:https://akrabat.com/ignoring-revisions-with-git-blame/
There may be a few commits in the history we would want to add to that file as well? Not sure, sometimes big moves end up squashed in along with real code changes.
larsoner commentedon Jun 15, 2022
For a template to follow we can look at numpy/numpydoc#394 which IIRC was done following what NumPy did
Yes this will be true for the last 2-3 years. But there are probably some before that that we could include, though
I'm thinking this could be an early PR in the 1.2 cycle
cbrnr commentedon Mar 9, 2023
Does anyone have time in the near future to tackle the switch to Black formatting? Once this is implemented, I can enable Black as a pre-commit hook in #11541.
larsoner commentedon Mar 9, 2023
It would be nice to get #11152 in first if possible since it's big. Maybe #11064, too, but since I'm authoring that I'm not as worried about the rebase/merge. But I have this marked for 1.4 so it should hopefully get done within the next month.
cbrnr commentedon Mar 9, 2023
Could/should we start using Black style in PRs even before the big one is merged? It wouldn't hurt, right?
larsoner commentedon Mar 9, 2023
Yes people can start doing that if they want
agramfort commentedon Mar 12, 2023
cbrnr commentedon Mar 12, 2023
I only meant in new code. But it doesn't really work anyway because we're changing our line length from 79 to 88.