-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Use Black #7197
Use Black #7197
Conversation
The CI failures are unrelated. |
I am in favor, given that we can always swap out for a different formatter in the future. The biggest benefit is that we can stop thinking about formatting. /cc @scikit-image/core |
I'm just gonna stand aside on this one. 😂 But I will say I'd rather we used |
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.
Very much in favor and very curious to try it out in practice. @jarrodmillman thanks for the "do-ocratic" approach.
.git-blame-ignore-revs
Outdated
@@ -6,3 +6,6 @@ f4978b11499e499cc006c417b3bf0ccf245ca72c | |||
|
|||
# Adopt ruff and cython-lint (gh-6729) | |||
b22ecff8d52eeb59e5d1d2e7fcc7962b4a0a84ce | |||
|
|||
# Adopt black (gh-7197) | |||
3588b3074f7ebc8c740523c9b3279efcdb796e75 |
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.
I assume that you plan to make a merge commit? Otherwise this hash will not be current once merged.
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.
Yes, but I am also expecting to have to rewrite history a few times before we merge.
rr, cc, val = circle_perimeter_aa(8, 8, 7) | ||
img[rr, cc] = val * 255 | ||
# fmt: off |
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.
Did you comb through the entire diff or did you use an automated process to find these? I am happy to include these exceptions were it makes sense.
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.
I just visually scanned the git diff
and added it for a few examples that I thought looked better before. I am not sure if we want to do that more or less than I already did.
@jni wrote:
#5006 (comment) for the record 😅 @stefanv wrote:
Here's a shy 👍 from me. Basically I support this move (thanks, @jarrodmillman) as long as we can include exceptions such as #5006 (comment). |
aeafc50
to
a0ee0ed
Compare
@@ -152,6 +152,10 @@ Metrics = [ | |||
'.spin/cmds.py:asv' | |||
] | |||
|
|||
[tool.black] | |||
target-version = ['py39', 'py310', 'py311', 'py312'] | |||
skip-string-normalization = 1 |
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.
This tells black to leave quotes as is.
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.
Is everyone ok with 90c line lengths?
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.
I personally do not mind. 90c has become quite common as the default setting across the popular text editors.
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.
I much prefer 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.
I prefer having the 8 or 9 extra characters per line.
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.
I mainly wanted to highlight the colorful term: "80 chars line limit olympics" :)
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.
Look if you want to abandon the commitment to excellence and olympic glory and settle for the mediocrity of the "Black 88 char line regional athletics meet", be my guest. 😜
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.
It is well known that our eyes, by default, can only take in 50-75 characters without jumping. That is the next axis along which we need to train ourselves to improve. For that purpose, I suggest decreasing font size by 9.1%, while keeping any existing terminal layout.
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.
If we fail to retrain our biology, there is still hope: since Black is going to do Whatever It Wants with our code anyway, there is no reason not to use an automated tool to rewrap to 80 characters before editing! We call this Virtualized Wrapping. The robustness of such a roundtripping approach is left as an exercise for the developer.
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.
That's actually pretty genius @stefanv! I don't ever have to look at black formatting again if I set up my post-checkout hooks correctly! 😍
Before merging this, I wanted to check on how many lines exceed 79 before and after applying this PR. This isn't meant to change anyone's mind, I was just curious. I wrote this little script (
Here is the output on main:
Here is the output on this branch:
So this PR increases the percentage of lines longer than 79 characters by about 0.6% from 1.6% to 2.2%. |
I also decided to check the branch with the line length set to Here is the output:
So when we tell black to wrap at 79 characters, we still have 1.4% of the lines longer than 79 chacters. I figured this was a better comparison than to the main branch, since we currently aren't enforcing any line length limits. |
I am going to rebase this, rerun black, and update the git-blame-ignore hash tomorrow morning. After that I plan to merge this. Please let me know if you want me to wait. |
Thanks @jarrodmillman! I'm excited for |
I do see a few places which we missed and might want to clean up over time (e.g. _skeletonize.py#L219-L741) or using a simple script to scan for likely candidates. But feel okay with giving that a low priority. :) |
Description
Fixes #7195. I use black for almost every other project I work on and I have become used to its formatting and prefer to rely on it rather than spending my time thinking about formatting. The discussion on the developer's list seemed to be generally ok with using black with some minor concerns. I decided to just make the PR and see what happens.
In e7f6abc, I told black to avoid reformatting some np arrays. I can remove that or redo it to include more. I just didn't want to spend too much time on this PR until I got some feedback from others.