Replace black with ruff linter / formatter #392
Merged
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.
Problem
While researching how to integrate some rust extensions into our python, I heard about this alternative tool for code formatting that also does linting. This tool is much faster than black and can also do codestyle linting to enforce some best practices for python.
Ruff is implemented by Astral, which is a company aiming to create a "cargo for python" type experience with python tools that are implemented in rust making them both fast and reliable. I'm interested in some other stuff they are doing (e.g. uv for dependency management), but this seemed like a lower stakes way to test the waters with their stuff.
Solution
Main changes are in:
The rest of this large diff is due to formatting and lint fixes for various code style things.
These checks can be run manually with
poetry run ruff check --fix
andpoetry run ruff format
, but otherwise they should automatically be triggered by pre-commit hooks. I documented this in CONTRIBUTING.Type of Change
Test Plan
Tests should still be green. No functional impact expected.