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

Dropping black formatter for ruff #2085

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Dropping black formatter for ruff #2085

wants to merge 8 commits into from

Conversation

john-science
Copy link
Member

@john-science john-science commented Feb 26, 2025

What is the change?

Here I dropped the black linter from the project entirely, and switched to using ruff. This meant I had to:

  • Remove black from pyproject.toml and the CI
  • Update ruff to 0.9.7.
  • Changed the ruff target-version from Python 3.9 to Python 3.13
  • Format ARMI with ruff (notice this make a TON of small changes for line length).
  • Added ruff format to CI.
  • Updated the docs to remove black and add ruff format.

Why is the change being made?

  1. ruff format is ~30 times faster than black
  2. This will make reduce the number of dependencies we have.

Checklist

@john-science john-science added the enhancement New feature or request label Feb 26, 2025
@john-science john-science requested a review from ntouran February 26, 2025 17:48
@john-science john-science removed the request for review from ntouran February 26, 2025 17:51
@john-science john-science requested a review from ntouran February 26, 2025 18:06
@keckler
Copy link
Member

keckler commented Feb 26, 2025

Question -- Is this going to cause issues for people that currently have the black formatter automatically triggered by their IDE? Or are the two formatters supposedly totally compatible in terms of their formatting rules?

@john-science
Copy link
Member Author

Question -- Is this going to cause issues for people that currently have the black formatter automatically triggered by their IDE? Or are the two formatters supposedly totally compatible in terms of their formatting rules?

ruff says they copied the black formatting one-for-one, and this is a drop-in replacement:

https://docs.astral.sh/ruff/faq/#how-does-ruffs-formatter-compare-to-black

But, certainly, the entire idea here is that users just stop using black, and go with ruff. (Your internal code bases will follow suit, in in a month or so, by the way.)

Part of the impetus here is people complain to me that black is too slow kind of a lot. Well ruff format is 30 times faster: https://astral.sh/blog/the-ruff-formatter

Thoughts?

@ntouran
Copy link
Member

ntouran commented Feb 26, 2025

Question -- Is this going to cause issues for people that currently have the black formatter automatically triggered by their IDE?

yes! they will fight to a degree.


# Setting line-length to 120 (though blacks default is 88)
# Setting line-length to 120
line-length = 120
Copy link
Member

Choose a reason for hiding this comment

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

you sure you don't want to take this opportunity to go to the ruff and black default of 88? 88 is great! https://docs.astral.sh/ruff/settings/#line-length https://stackoverflow.com/a/578318/1279313

otherwise this looks great.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried. Even going down to 100 meant I had over 400 files that required manual changes. (Things like docstrings couldn't be automatically reformatted.)

And I do not have time for manually touching >1,000 lines to make them shorter.

(Also, as a personal preference, I might go 100, but 88 feels a bit too narrow when you have a lot of math on the same line.)

@john-science john-science requested a review from ntouran February 26, 2025 19:04
@opotowsky opotowsky marked this pull request as draft February 26, 2025 22:41
@opotowsky
Copy link
Member

Question -- Is this going to cause issues for people that currently have the black formatter automatically triggered by their IDE? Or are the two formatters supposedly totally compatible in terms of their formatting rules?

Since ppl are fond of VSCode and this will cause problems for folks while we convert to this, John has graciously agreed to delay this PR. So I marked it as draft. There will be an adjustment period, but we will plan to get everything downstream converted. Only folks who work on ARMI will have to battle the conflicting formatters. ruff on the command line will fix that easily though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants