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
{{ message }}
Repository navigation
We may be able to ditch Black in favor of just Ruff #12255
Ruff has started offering formatting functionality a couple of months back, in addition to just lining. They claim they tested it on large codebases like Django and it yields >99.9% identical results to Black. Differences are e.g. that it would complain about comments exceeding the max. line length, while Black doesn't.
In any case, we could theoretically drop Black from our CI and pre-commit hooks and simply use Ruff for everything. This would speed up the pre-commit checks.
WOW, I just ran ruff format mne/ and it immediately returns, it's blazingly fast! Changes 39 files, though.
Then I ran Black again and it took like 10 seconds or so.
Conclusion: Ruff is just incredibly fast, but formats the occasional line differently than Black. It's more aggressive to keep line lengts below the maximum; e.g., we currently have with Black
raiseValueError(
"Number of channels in the Info object (%s) and ""the data array (%s) do not match. "% (len(pos["chs"]), data.shape[0])
+info_help
)
(3rd line exceeds line length limit!)
and Ruff formats it as:
raiseValueError(
"Number of channels in the Info object (%s) and ""the data array (%s) do not match. "% (len(pos["chs"]), data.shape[0])
+info_help
)
But there's also cases where it helps make full use of the line length limit, e.g., it changes this:
no strong feeling here. Faster is better, for sure, and we should probably switch to Ruff eventually (also eliminates a dependency), but I'd be willing to wait a few more months to let the folks at Astral iron out a few more wrinkles in the Ruff formatter (such as the failure to merge the strings). Which, BTW, you should report upstream if it's not already been reported.
Are the examples you give exhaustive in terms of the kinds of situations that are handled differently?
such as the failure to merge the strings). Which, BTW, you should report upstream if it's not already been reported.
I think Black does similar things if I'm not mistaken. The Ruff docs actually show this behavior in examples, so apparently it's not considered a bug. I still think it's kind of weird …
I like it, I'm 👍 for replacing Black with Ruff. The differences seem to be small, but they make sense (the list of differences contains good arguments why Ruff is doing it like that). In the case of string concatenation, users can always manually format it the way it looks best.
such as the failure to merge the strings). Which, BTW, you should report upstream if it's not already been reported.
I think Black does similar things if I'm not mistaken. The Ruff docs actually show this behavior in examples, so apparently it's not considered a bug. I still think it's kind of weird …
Activity
hoechenberger commentedon Dec 2, 2023
WOW, I just ran
ruff format mne/and it immediately returns, it's blazingly fast! Changes 39 files, though.Then I ran Black again and it took like 10 seconds or so.
Conclusion: Ruff is just incredibly fast, but formats the occasional line differently than Black. It's more aggressive to keep line lengts below the maximum; e.g., we currently have with Black
(3rd line exceeds line length limit!)
and Ruff formats it as:
But there's also cases where it helps make full use of the line length limit, e.g., it changes this:
to this:
Didn't reduce the number of lines required, but makes line 2 longer. Should've merge the String, though?!
drammock commentedon Dec 2, 2023
no strong feeling here. Faster is better, for sure, and we should probably switch to Ruff eventually (also eliminates a dependency), but I'd be willing to wait a few more months to let the folks at Astral iron out a few more wrinkles in the Ruff formatter (such as the failure to merge the strings). Which, BTW, you should report upstream if it's not already been reported.
Are the examples you give exhaustive in terms of the kinds of situations that are handled differently?
hoechenberger commentedon Dec 2, 2023
I think Black does similar things if I'm not mistaken. The Ruff docs actually show this behavior in examples, so apparently it's not considered a bug. I still think it's kind of weird …
See here: https://docs.astral.sh/ruff/formatter/black/#implicit-string-concatenations-in-attribute-accesses
I'm not sure, I only checked the changes the Ruff formatter proposes for a handful of the 39 files it wants to touch :)
But yes, certainly no rush here! Just wanted to share this with you, esp. the speed was really impressive to me :)
Thre's an exhaustive list of differences between Ruff and Black here:
https://docs.astral.sh/ruff/formatter/black/
agramfort commentedon Dec 4, 2023
cbrnr commentedon Dec 4, 2023
I like it, I'm 👍 for replacing Black with Ruff. The differences seem to be small, but they make sense (the list of differences contains good arguments why Ruff is doing it like that). In the case of string concatenation, users can always manually format it the way it looks best.
hoechenberger commentedon Dec 4, 2023
What I'll do is I'll make a PR where we can see all the proposed changes and then evaluate how and whether to move forward, okay? :)
hoechenberger commentedon Dec 4, 2023
See #12261
I think it looks good / reasonable
hoechenberger commentedon Dec 4, 2023
I just checked our
maincodebase and we already have hundreds of such lines there, introduced by Black.