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

chore: set up ruff as a new linter/formatter #28158

Merged
merged 17 commits into from
Apr 25, 2024
Merged

chore: set up ruff as a new linter/formatter #28158

merged 17 commits into from
Apr 25, 2024

Conversation

mistercrunch
Copy link
Member

@mistercrunch mistercrunch commented Apr 20, 2024

SUMMARY

Ruff is great, and it's fast. All the cool kids are using it.

#edit -putting my latest comment as PR body:

This PR is meant as an experiment around whether it would make sense to add this package as part of the stack. I'll try and summarize my findings and recommendation after playing with it.

relevant: https://docs.astral.sh/ruff/faq/

Early impression are:

on the positive:

  • super fast and centralized in a comprehensive CLI (pretty much fully replaces pycln, pyupgrade, isort, black)
  • simplifying the code quality stack quite a bit. Many of those tools themselves are adopting ruff (pylint uses in its repo for instance). There's fair amount of cognitive load in dealing with disjointed tools with their own cli, config and quirks.
  • powerful / convenient features like --add-no-qa --ignore-noqa and --fix
  • it's taking over the python code-quality world fast, federating everything in a nifty, comprehensive toolkit

on the negative:

  • while it covers at lot, it's intricately incomplete, pylint is the less covered source where it cannot replace it fully at this time, for the others, it seems like ruff is "enough of a replacement" to justify rip & replace - here I'm thinking disabling duplicate rules with pylint might speed pylint sifnificantly
  • I hit some infinite linting loops and deadends in some area, pushing me to disable black, isort and pyupgrade. Our codebase is large, and while ruff is 99% compatible with all this, 1% is still a significant thing
  • this won't replace pylint as the coverage is still too low and pylint is powerful. I was thinking we may be able to disable rules in pylint that are covered and speed it up in the process

Overall I think the recommendation is likely to be "we should do this now" or "we should probably revisit in a little while", will update here once I form an opinion.

@mistercrunch mistercrunch requested a review from a team as a code owner April 20, 2024 01:09
@github-actions github-actions bot added risk:db-migration PRs that require a DB migration api Related to the REST API labels Apr 20, 2024
@mistercrunch mistercrunch marked this pull request as draft April 20, 2024 01:33
@villebro
Copy link
Member

Wait what, black is no longer the new black? I took a look at ruff, pretty great perf and overall promises. But let's test this carefully, as even many mature linters fall apart on the Superset codebase..

@john-bodley
Copy link
Member

It seems like perf is a big sell,

⚡️ 10-100x faster than existing linters (like Flake8) and formatters (like Black)

however I think Black only takes a few seconds to runs and thus any speed up is irrelevant from a UX perspective in my mind. I've never once thought "you know the main problem with Black is that it's too slow".

@mistercrunch would you mind including some links as to why we should be adopting this over Black et al.? Sure some of the auto-formatting looks great—including being more opinionated about blank lines—however on the flip side the one import per line (with the addition of the # noqa: F401 comment) seems—per the package name— a tad ruff.

@mistercrunch
Copy link
Member Author

Hey I should have written more originally when submitting this draft, but this is meant as an experiment around whether it would make sense to add this package as part of the stack. I'll try and summarize my findings and recommendation after playing with it.

Early impression are:

on the positive:

  • super fast
  • mostly replaces a lot of things (pylint, pyupdate, flake8, black, parts of pylint), simplifying the over stack quite a bit. Many of those tools themselves are adopting ruff (pylint uses in its repo for instance)
  • powerful / convenient features like --add-no-qa
  • it's taking over the python code-quality world fast, federating everything in a nifty, comprensive toolkit

on the negative:

  • while it covers at lot, it's intricately incomplete, pylint is the less covered source where it cannot replace it fully at this time
  • hit some infinite linting loops and deadends in some area, pushing me to disable black, isort and pyupgrade. Our codebase is large, and while ruff is 99% compatible with all this, 1% is still a significant thing

Overall I think the recommendation is likely to be "we should do this now" or "we should probably revisit in a little while "

@mistercrunch mistercrunch marked this pull request as ready for review April 24, 2024 01:49
@mistercrunch
Copy link
Member Author

@villebro @john-bodley - my recommendation is to move forward with this, speed and centralization of the tooling make things really nice. Big wins include:

  • speed - a fast CLI, you never wait on it to do anything, unlike pylint (takes minutes to lint the codebase) and seconds to operate in your IDE on a single file
  • one modern/comprehensive CLI with all the knobs and buttons you need. A lot of the other CLIs we're replacing are clunky and intricately different, don't always agree with each other, ...
  • quality of life features: --add-noqa and --ignore-noqa and having a --fix make things easy
  • momentum - this thing is getting better everyday

Copy link
Member

@hughhhh hughhhh left a comment

Choose a reason for hiding this comment

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

+1 to @mistercrunch comments on upgrading to this package.

@john-bodley for formatting >99.9% compatible to black reading the release statements

Optimized for adoption. Ruff’s formatter is designed as a drop-in replacement for Black. On Black-formatted Python projects, Ruff achieves >99.9% compatibility with Black, as measured by changed lines. When formatting the Django codebase, for example, Ruff and Black only differ on 34 out of 2,772 files. Focusing on compatibility enables projects to adopt the Ruff formatter with minimal disruption.
https://astral.sh/blog/the-ruff-formatter#

@mistercrunch
Copy link
Member Author

This one will conflict with everything (touching 574 files), I'd love to merge quickly(!)

@mistercrunch
Copy link
Member Author

Great resources here too -> https://docs.astral.sh/ruff/faq/

For those interested in the story behind the project -> https://www.youtube.com/watch?v=LCva0NOM2-o

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

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

Let's do this!

@mistercrunch mistercrunch merged commit 2d63722 into master Apr 25, 2024
28 checks passed
@mistercrunch mistercrunch deleted the ruff branch April 25, 2024 00:19
@mistercrunch
Copy link
Member Author

roadrunner-beep

qleroy pushed a commit to qleroy/superset that referenced this pull request Apr 28, 2024
jzhao62 pushed a commit to jzhao62/superset that referenced this pull request May 16, 2024
@andy-clapson
Copy link
Contributor

@mistercrunch did you try out uv ever? same folks and pretty wicked too.

@mistercrunch
Copy link
Member Author

mistercrunch commented Jul 26, 2024

@andy-clapson first I hear of it, but OMG if this delivers on its promises THE FUTURE IS HERE. Oh is it the same dude!? Yes!

We depend on pip-compile-multi, which isn't really well supported anymore. If uv has some support for managing/inheriting from multiple reqs file like we have in requirements/ it'd be really tempting to try and take that jump.

@mistercrunch
Copy link
Member Author

For the record, I opened an issue asking about our use cases -> astral-sh/uv#5487

@andy-clapson
Copy link
Contributor

Yeah, we started using it a few months back and it's extremely fast.
pip-compile-multi is new to me, though - I'm less sure about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the REST API preset-io risk:db-migration PRs that require a DB migration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants