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

Add experimental backend for ruff with lint and fmt goals #17945

Merged
merged 3 commits into from
Jan 28, 2023

Conversation

ozturkberkay
Copy link
Contributor

Hi,

Ruff is a fast Python linter & formatter written in Rust. I wanted to integrate Pants with ruff for my personal projects. I was curious if the pants community would be interested in this.

Ruff can be used to replace Flake8 (plus a variety of plugins), isort, pydocstyle, yesqa, eradicate, pyupgrade, and autoflake, all while executing tens or hundreds of times faster than any individual tool.

Ruff goes beyond the responsibilities of a traditional linter, instead functioning as an advanced code transformation tool capable of upgrading type annotations, rewriting class definitions, sorting imports, and more.

This is my first time contributing to Pants, so please bear with me :)

@tdyas tdyas added category:new feature backend: Python Python backend-related issues labels Jan 7, 2023
@thejcannon
Copy link
Member

One thing we should discuss is implementing it as a fixer or as a formatter (or both?).

Ruff is special in that it has some fixes, and some formats. I wonder if we can implement it as 2 plugins, each doing "the right thing". Or maybe it's just simpler as 1.

It would also help if ruff itself had the distinction...

@cczona
Copy link
Member

cczona commented Jan 9, 2023

Possibly a crazy idea, but what if it was one plugin that the user chooses whether to run as a formatter or fixer? So it's the user's responsibility to decide whether they intend ruff to make mods?

@thejcannon
Copy link
Member

In that case, it's be the build owner making the decision for everyone, which isn't ideal as only a subset of people use --loop and would care.

@thejcannon
Copy link
Member

Since this is marked experimental I'm fine with whichever goal you choose. As long as we track this in a tracking issue, 🚀

@sureshjoshi
Copy link
Member

Since this is marked experimental I'm fine with whichever goal you choose. As long as we track this in a tracking issue, 🚀

Is it marked experimental right now?

@thejcannon
Copy link
Member

Oops I just read the title and assumed. @ozturkberkay I'd be happy to see this get in if we marked it experimental. Probably a much easier path forward.

@thejcannon
Copy link
Member

(and for completeness here's the ruff issue: astral-sh/ruff#455

@ozturkberkay
Copy link
Contributor Author

@thejcannon I followed the existing code (add_trailing_comma) as a reference to make ruff an experimental formatter. Please lmk if there is more to be done.

@ozturkberkay ozturkberkay marked this pull request as ready for review January 9, 2023 18:24
@thejcannon
Copy link
Member

I launched CI 🚀

@benjyw
Copy link
Contributor

benjyw commented Jan 27, 2023

Hi @ozturkberkay! I'm not sure why CI is failing, but we had a similar issue a while back, which we fixed, so could you merge latest main onto your changes and push them? That might sort it out.

@stuhood stuhood enabled auto-merge (squash) January 27, 2023 22:35
@stuhood stuhood merged commit bb67f02 into pantsbuild:main Jan 28, 2023
@thejcannon
Copy link
Member

For the difference between fix and fmt, this just got closed: astral-sh/ruff#455 (comment)

@benjyw
Copy link
Contributor

benjyw commented Jan 29, 2023

Woohoo! @ozturkberkay thanks for the contribution and for your patience throughout the code review process. I think this is worth a blog post!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: Python Python backend-related issues category:new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants