style: Use ruff format
instead of black .
for improved user experience
#5023
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #4922
As discussed in #4922, I'm implementing the switch from black to ruff format. It is a drop in replacement with some limited known deviations
From ruff's docs: https://docs.astral.sh/ruff/formatter/#philosophy
Like black, ruff format commits to keeping a stable style for a year, and they work together to stay aligned with black choices, if black does it in time.
Black, while faster that it was, is still python, and was becoming slow sometimes, and if used regularly, or even as a save hook on your IDE, is slow.
For example, just before preparing this PR, I compared black 25 and ruff 0.9.4, both without cache, on a performing computer from 2019:
black:
ruff:
The experience is simply unmatched.
As for concerns about immatureness: Black has slow developpement, and this repo started when it was young. Ruff is still new, but rapid development. ruff format has been available since their 0.0.289 release in september 2023 (according to their pre-commit repo), which is found on the 8th page of tags on github: https://github.com/astral-sh/ruff/tags?after=v0.1.3. They announced the availability in october 2023 https://astral.sh/blog/the-ruff-formatter. At their developpement cadence, and from following them since a while (before their formatter existed), I estimate that it equates to more than 3 years maturity. I don't see any fear to go there, its way "simpler" that the rules and fixes we rely on here from ruff itself.
For the differences, its a one-time change, and this PR here contains the deviations that they choose to be better than black, amongst other enabling work and fixes.
Some other nice additions ruff format brings that black doesn't yet:
Upcoming work, after introducing ruff format:
This PR also includes 2 small fixes noted in the black 25 preparatory PR:
libraster.Rast_copy_cats()
invocationOther: