Skip to content

Conversation

@kieran-ryan
Copy link
Contributor

@kieran-ryan kieran-ryan commented Jun 24, 2025

Migrates Python formatting to ruff from black to speed up formatting by multiples (see below benchmarks); and for robustness improvements; such as those applied by the formatting of this merge request to string formatting, trailing commas rather than a mixture with and without; improved formatting of arguments, whitespace line handling, etc. - though all of which are included with later releases of various Python formatter tools.

The ruff formatter is "designed as a drop-in replacement for Black". The caching in particular improves development workflows with tools such as IDEs and hooks.

Ruff's default configuration is a superset of those specified by the black configuration within the pyproject.toml; and thus only required extension to the custom path src/buildstream/_protos.

Raising based on observation and in case of interest.

Benchmarks

Cold Runs

Black Ruff Delta % Change
13.86s 2.07s 11.79s -85%
Screenshots
Black
Ruff

Warm Runs

Black Ruff Delta % Change
12.31s 0.54s 11.77s -95.6%
Screenshots
Black
Ruff

This speeds up formatting by multiples, uses ruff's cache on subsequent;
and runs and works well in conjunction with IDEs and hooks. Designed as
a drop-in replacement for black.
@kieran-ryan kieran-ryan changed the title Migrate Python formatter to ruff from black Migrate Python formatting to ruff from black Jun 24, 2025
@kieran-ryan kieran-ryan marked this pull request as ready for review June 24, 2025 23:12
@cs-shadow
Copy link
Member

hi @kieran-ryan , I'd be in favor of this change in principle.

Although it may be good to float this on the mailing list first as it may be a little bit of disruptive change for people who may be in the habit of running Black.

Especially because it seems like Ruff would do more reformatting than "just" a drop-in replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants