Replace isort with ruff check and black with ruff format#75
Replace isort with ruff check and black with ruff format#75joanise merged 4 commits intoReadAlongs:mainfrom
Conversation
dhdaines
left a comment
There was a problem hiding this comment.
Yes, I like ruff quite a bit. Looks like it isn't conflicting with the existing formatting (and also finds an error). As long as CI passes I say good!
py/soundswallower/__init__.py
Outdated
| from ._soundswallower import Endpointer # noqa: F401 | ||
| from ._soundswallower import FsgModel # noqa: F401 | ||
| from ._soundswallower import Vad # noqa: F401 | ||
| from ._soundswallower import ( # noqa: F401 |
There was a problem hiding this comment.
We don't need noqa: F401 here: all these names are used in __all__, so they're not "imported but unused".
Removing it and re-running isort collapses this import statement to just one line, and I assume (and hope!) ruff will do the same.
There was a problem hiding this comment.
Ah, looking at the history, we did need F401 at some point, just not anymore.
There was a problem hiding this comment.
There is a rule for that... RUF100. https://docs.astral.sh/ruff/rules/unused-noqa/
There was a problem hiding this comment.
ah, I had forgotten all about __all__ and gotten out of the habit of using it, thanks for the reminder!
There was a problem hiding this comment.
I tend to avoid __all__ in general, just like I never use import *, but in a top-level situation like this, where you're importing stuff into __init__.py just so others can do from soundswallower import foo, putting those names into __all__ as you have done is the right thing to do.
|
If I deliberately disorder the imports and a file and run |
| - id: ruff | ||
| args: [ --fix ] | ||
| - id: ruff-format |
There was a problem hiding this comment.
Much better, thank you! We can reduce noise by reverting these lines:
| - id: ruff | |
| args: [ --fix ] | |
| - id: ruff-format | |
| - id: ruff-format | |
| - id: ruff | |
| args: [ --fix ] |
While the end result is effectively the same, things that are fixed by ruff-format don't get reported as errors by ruff in this order, but they do in the other order.
There was a problem hiding this comment.
Please read https://docs.astral.sh/ruff/integrations/#pre-commit
When running with --fix, Ruff's lint hook should be placed before Ruff's formatter hook...
There was a problem hiding this comment.
Fair enough. I guess it's a bit of a chicken and egg problem: ruff-format fixes things ruff complains about, but also stuff ruff --fix introduces, I guess I can live with the duplicate warnings.
PR Goal?
Streamline Python linting and formatting.
https://docs.astral.sh/ruff is an extremely fast Python linter and code formatter, written in Rust. With over 800 linting rules, ruff can be used to replace Flake8 (plus dozens of plugins), Black, isort, pydocstyle, pyupgrade, autoflake, and more, all while executing tens or hundreds of times faster than any individual tool.
Add linting tests for bugbear, comprehensions, code complexity, pylint, etc.
Fixes?
Feedback sought?
Priority?
Tests added?
How to test?
Confidence?
Version change?