Moving to Ruff
Closed this issue · 4 comments
This is more of an FYI for devs than an actual issue
Motivation
We changed to using Ruff instead of black and flake8 (#599 and pygfx/pygfx#859). The reason is that it provides a modern unified tool that provides several advantages: it's very fast, can be configured via pyproject.toml, has loads of linting rules, has support for auto-fixing some linting errors, and has good integration with VSCode and Github.
Adjusting workflows
My main concern with switching to Ruff is that it forces devs to adjust their workflow.
Ruff's formatting is nearly compatible with black
. There are a few cases where they want to format code differently. I removed the 3 cases where this happened, but at some point someone will introduce such a case.
So, some tips:
New workflow (CLI commands)
black .
->ruff format
flake8 .
->ruff check
How to use Ruff and Black in VSCode
When you use VSCode, you may want to install the Ruff
extension. Apart from formatting python file when you save them, you also get in-line linting errors (and sometimes options to autofix them).
When you already use the common Black Formatter
extension, I found that the format-on-save stopped working if both extensions are active. A way to fix this is to disable the Ruff
extension, and only in workspaces where you use ruff, you enable ruff and disable black. Or the other way around.
Or you can just keep using the Black Formatter
extension, and make a habit to run ruff format
before a push.
Would it make sense to include a pre commit config that has the ruff steps included?
Since ruff changes quite frequently, not pinning a version and using latest does sneak in some unrelated formatting changes into PRs at time.
Would it make sense to include a pre commit config that has the ruff steps included?
That sounds like a good idea! What's the community standard for doing this? Is https://pre-commit.com the way to go?
Is https://pre-commit.com/ the way to go?
Yes, I am a fan of pre-commit
for this.
I made a PR adding this and some install instructions here.
I think this has been up long enough :)