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

Replacing ~autoflake, isort, and~ black with Ruff #101

Open
OtherBarry opened this issue Oct 25, 2023 · 9 comments · Fixed by #105
Open

Replacing ~autoflake, isort, and~ black with Ruff #101

OtherBarry opened this issue Oct 25, 2023 · 9 comments · Fixed by #105

Comments

@OtherBarry
Copy link

OtherBarry commented Oct 25, 2023

With the beta release of Ruff's formatter, ruff now contains the functionality of several of the tools in shed, and runs much faster.

See the ruff docs for the functionality it replaces:

I love the pyupgrade and refactor aspects of shed, but it's difficult to use with ruff, as the minor deviations mean I have to run ruff format, run shed, then run ruff format again in order to get the most out of both tools, which then negates a lot of the speed benefits of ruff.

Personally I think ruff should replace those tools within shed, but I would also be happy to have it as an option.

Happy to try for a PR of this if it's something other people are interested in.

@Zac-HD
Copy link
Owner

Zac-HD commented Oct 25, 2023

I started experimenting with this recently - master...use-ruff - and from memory the barriers were

  • no Python interface yet. Shelling out would be okay, but there's no way to configure ruff's isort support from the cli and --isolated is a strict requirement.
  • a couple of bugs, some of which have since been fixed - shed's tests will show them
  • I think there was one remaining thing handled by autoflake but not ruff, but that might have been isort related and/or already fixed

If you're interested in trying this out on ruff 0.1 and reporting upstream issues as needed, I think that would substantially accelerate things! My best guess for when I'd get back to it otherwise is "maybe December, maybe January, maybe later" 😅

@OtherBarry
Copy link
Author

Oh awesome - I'll play around with it in a fork and see how I go, though I also wouldn't have high hopes of getting anywhere soon.

@jakkdl
Copy link
Contributor

jakkdl commented Oct 25, 2023

another way of solving this would be to add a flag that configures which tools within shed that are run. Especially when there's some custom refactors that only exists within shed I see it as pretty valuable to have a way of accessing them without having to pull in all the other assumptions shed makes, so even if not going all the way of enabling/disabling individual tools I could see a --only-custom-refactor flag or similar.

Ruff does also implement pyupgrade as well.

@Zac-HD
Copy link
Owner

Zac-HD commented Oct 25, 2023

I'm generally against configuration options, and would prefer to just hold off until a ruff-based implementation can fully replace them.

Shipping a second CLI entrypoint, e.g. shed-refactor-only FILE [FILES], might make sense though.

@OtherBarry
Copy link
Author

I've made a draft PR #102 implementing ruff format and ruff check, using a temporary ruff.toml file, instead of trying to configure things by CLI. @Zac-HD let me know if you're ok with this approach, and I can start looking into why the inidividual tests are failing.

@jakkdl
Copy link
Contributor

jakkdl commented Oct 25, 2023

Shipping a second CLI entrypoint, e.g. shed-refactor-only FILE [FILES], might make sense though.

yeah that works.

Not having any configuration of black/autoflake/isort makes decent sense, but locking one out of configuring ruff is quite limiting. Though the PR does open up letting ruff read it's config file which does address that.

[Optional] Use existing ruff.toml / prproject.toml for ruff configuration if present

@Zac-HD
Copy link
Owner

Zac-HD commented Oct 25, 2023

@OtherBarry - I'd like to (continue) supporting formatting code from stdin on a read-only filesystem. This might mean that we have to wait for ruff's upcoming python interface before shed will support it.

@jakkdl if someone wants to configure ruff, I encourage them to use ruff! The whole point of shed is that it's the last formatting decision you need to make 😉

@Zac-HD
Copy link
Owner

Zac-HD commented Feb 22, 2024

https://docs.astral.sh/ruff/configuration/#the-config-cli-flag means we can now run in --isolated mode while still getting exactly the isort config we want 🎉

@jakkdl
Copy link
Contributor

jakkdl commented Mar 13, 2024

We still haven't replaced black with ruff format, though the original complaint of deviations between the tools should be resolved other than a few very minor cases of our codemods having overlap with ruffs. I haven't checked speed differences either, though ruff is presumably faster than autoflake+isort+pyupgrade. So there's a case for keeping the issue open, or open a separate one for removing Black.

@Zac-HD Zac-HD reopened this Mar 13, 2024
@Zac-HD Zac-HD changed the title Replacing black, autoflake and isort with Ruff Replacing ~~autoflake, isort, and~~ black with Ruff Mar 13, 2024
@Zac-HD Zac-HD changed the title Replacing ~~autoflake, isort, and~~ black with Ruff Replacing ~autoflake, isort, and~ black with Ruff Mar 13, 2024
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 a pull request may close this issue.

3 participants