Skip to content
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

Switch from black to ruff format #4559

Merged
merged 5 commits into from
Aug 28, 2024

Conversation

StevenMaude
Copy link
Contributor

@StevenMaude StevenMaude commented Aug 22, 2024

Fixes #4542.

ruff format is considerably faster than black, while maintaining almost entirely the same formatting output. After deleting the cache for both and running against job-server commit 241415f:

$ time ruff format .
warning: The following rules may cause conflicts when used with the formatter: `ISC001`. To avoid unexpected behavior, we recommend disabling these rules, either by removing them from the `select` or `extend-select` configuration, or adding them to the `ignore` configuration.
9 files reformatted, 402 files left unchanged

real	0m0.073s
…
$ time black .
All done! ✨ 🍰 ✨
411 files left unchanged.

real	0m1.345s
…

(Note: the Ruff warning is fixed in this PR; it's because the configuration's not updated on the main branch where I ran the above.)

As a bonus, this also removes several additional development dependencies.

It gives a warning when running the Ruff formatter.

This rule can cause the linter and formatter to conflict, meaning you need to
rerun `ruff check --fix` again after `ruff format`.

See astral-sh/ruff#8272 (comment)
`outputs/` was the only Black exclusion not being excluded for Ruff, so
also add that exclusion there.
This also removes several transitive dependencies.
@StevenMaude StevenMaude force-pushed the steve/switch-from-black-to-ruff-format branch from ea905d0 to 79eb8a5 Compare August 22, 2024 12:13
Copy link
Member

@iaindillingham iaindillingham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of questions, but otherwise 🚀

Comment on lines 177 to +178
$BIN/ruff check --fix .
$BIN/ruff format .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does check --fix do that format doesn't do?

Copy link
Contributor Author

@StevenMaude StevenMaude Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruff check runs the linter and fixes any automatically fixable issues it finds (example: removing unused imports), but ruff check doesn't run the formatter.

It's planned for ruff to eventually unify the two, which will reduce this to a single command instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to read up on the difference between linting and formatting!

@@ -121,6 +109,7 @@ exclude = [
"docs",
"htmlcov",
"node_modules",
"outputs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I've missed something, static is already included below.

outputs was the only entry for the Black excludes, that wasn't listed already in Ruff's excludes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My error. Sorry!

@iaindillingham iaindillingham merged commit 105d170 into main Aug 28, 2024
8 checks passed
@iaindillingham iaindillingham deleted the steve/switch-from-black-to-ruff-format branch August 28, 2024 08:34
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.

Switch from black to ruff for formatting
3 participants