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

Moving to Ruff #602

Open
almarklein opened this issue Sep 26, 2024 · 3 comments
Open

Moving to Ruff #602

almarklein opened this issue Sep 26, 2024 · 3 comments

Comments

@almarklein
Copy link
Member

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.

@almarklein almarklein pinned this issue Sep 26, 2024
@Vipitis
Copy link
Contributor

Vipitis commented Sep 26, 2024

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.

@almarklein
Copy link
Member Author

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?

@claydugo
Copy link
Contributor

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.

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

No branches or pull requests

3 participants