Hey folks! Continuing a discussion from Github her...
# development
b
Hey folks! Continuing a discussion from Github here: https://github.com/pantsbuild/pants/issues/20084#issuecomment-1808881612 Would there be interest in migrating the Pants repo to use Ruff for formatting + linting? This could potentially provide large performance gains since Ruff is written in Rust, and would replace a variety of different tools (Black, Flake8, Autoflake, isort). Additionally, there’s a complication as we can’t opt into using Ruff as a tool for just a single goal (like
fmt
) as discussed here: https://pantsbuild.slack.com/archives/C0D7TNJHL/p1699632752483199. So to make things convenient, we have to use Ruff for formatting AND linting, or not at all. I have a branch up here with an example of the changes: https://github.com/krishnan-chandra/pants/tree/migrate-repo-ruff Let me know if you have any thoughts or questions!
c
just noting that we could use ruff for only lint or formatting, but would clutter our configuration and require use of aliases for runs from the command line. (so, not ideal, but doable)
from a performance perspective, I don’t feel I spend a ton of time waiting for these goals to run, so is not a huge deal for me either way…
g
Agreed on both points. I'm also not sure if my editor has support for e.g. ruff as a formatter, whereas it does for black and isort. Huge adoption pain-point if they aren't identical in result.
b
In terms of performance, the difference is about ~11 seconds with Black on my machine vs ~2 seconds with Ruff:
Copy code
11:23:03.99 [INFO] Completed: Add preambles - preamble made no changes.
11:23:05.79 [INFO] Completed: Format with Black - black made no changes.
...
11:23:13.58 [INFO] Completed: Format with docformatter - docformatter made no changes.
11:23:14.12 [INFO] Completed: Format with isort - isort made no changes.
11:23:14.27 [INFO] Completed: Add preambles - preamble made no changes.
11:23:14.50 [INFO] Completed: Format with isort - isort made no changes.
Copy code
11:24:28.18 [INFO] Completed: Add preambles - preamble made no changes.
...
11:24:30.57 [INFO] Completed: Format with ruff - ruff made no changes.
11:24:30.57 [INFO] Completed: Add preambles - preamble made no changes.
But @gorgeous-winter-99296 that’s a great point - editor/IDE integration is definitely important too
c
guessing those times are for the entire code base? I rarely do that, just the stuff I’ve been touching, which will be a handful of files only..
b
Yeah sorry, I just ran
./pants fmt ::
from the root of the repo
c
so cool perf improvement, I give ruff that. but for me, if it goes from a couple of seconds to sub-second, that’s not a huge deal.. 😉
b
Ya agreed, I don’t think 12 seconds for the entire repo is honestly that bad. But the nice thing is that I was able to replace 4 tools with 1 tool, which I think does simplify the surface area of support by a lot
c
otoh I don’t have the editor support issue, I think.. 🙂 but it’s a fair point to consider as well.
yea, that is a good win.
h
I think there's value in dogfooding what our users are using, so now I wonder what the state of ruff adoption is out there
b
In terms of large projects that have switched, the list in Ruff’s repo is pretty impressive: https://github.com/astral-sh/ruff#whos-using-ruff A lot of well-known names here including other tools like Mypy and Pylint
g
FWIW we use ruff as a linter a bunch, and I've enabled it in most of my Pants repos. But not as a formatter.