recap-build/recap

Look at replacing pyright/black with ruff (or something else)

Closed this issue · 4 comments

Here's a summary of python tools that tell you something's wrong with your code and maybe try to fix it:

Category Tool
Code formatters black, autopep8, isort, docformatter, pydocstringformatter
Type checkers pyright, mypy, pytpe, pyre-check
Error/smell checkers pylint, pyflakes (+autoflake)
Multi-tools flake8, ruff
Other checkers mccabe (complexity), bandit (security), yesqa (remove type ignores), semgrep (generic platform)

There are other feedback/fix mechanisms that do other things, but if you're just wanting something that removes unused imports your options appear to be:

autoflake8 is the most targeted solution. If you wanted a single tool to rule them all then ruff looks pretty great (and is rust fast!) but is in beta. pyflakes and pylint do a a handful of things and are older+slower.

In terms of how to integrate a tool into the dev workflow, you could set up:

  • editor integration
  • pre-commit hooks
  • documented commands
  • CI/CD checks as a backstop to the other faster feedback mechanisms

Originally posted by @mjperrone in #347 (comment)

After doing some digging, it looks like ruff would only replace isort and pylint. It's not a type checker (like pyright/mypy). It ?might? replace black with --fix? I'm not sure.. most of the docs suggest to run black along side.

I tested ruff out on the Recap codebase. It does not appear to be able to fix everything with --fix the way that black does. That annoys me, since previously pdm run style would fix everything and prep it for commit. With Ruff, you can run style and the PR will still fail if certain rules fail (because Ruff can't fix them). Given this, I'm going to leave the tools as they are.

Ah, good to know. I guess ruff isn't an all in one replacement. In their FAQ they even says it's designed to be run alongside black, not instead of

Circling back to the original concern of removing unused imports, you probably would want to set up https://pypi.org/project/autoflake/ for just that. It can fix the files --in-place

Adding autoflake here: #372