[Preview] Toolchain upgrade (black, flake8 -> ruff)

Hey folks, if has been a while since we introduced black for formatting python source code.
Keeping a consistent look and feel across the project, I think has been a success.

But there is a new kid in town: ruff [0]
What sticks out to me, is not so much that it is “10-100x faster than existing linters (like Flake8) and formatters (like Black)”, but that it consolidates the tasks of black, isort and flake8 into one tool, that it allows to auto-fix more issues than black alone and that it can even serve as a language-server (lsp) for better editor support (neovim in my case).
The formatting decisions taken by ruff are intentionally almost the same as by black.

I expect us to eventually switch completely to using ruff. But for now I will prepare a showcase for this transition in the Pulp CLI repository. So stay tuned.

[0] Ruff

4 Likes

First shots look promising:

No objections to this. Fewer tools and configurations to keep track of sounds good to me.

A look at the formatting results in the given example looks perfectly fine, with two caveats:

  1. I personally liked the ability to throw in a newline in between pulp-specific and non-pulp dependency groups, it looks like maybe it may not like that?

  2. I would like to see the impact on one of the plugins, where the different warnings ignored by the previous flake8 config might reappear. I seem to recall most of those on the ignore list were worthy of being there.

1 Like

We didn’t do isort yet on pulp plugins, but there is even a setting i think for exactly what you are talking about there:
https://docs.astral.sh/ruff/settings/#lint_isort_sections

We adopted ruff in the pulp-cli world and it seems to work really smooth. So i will probably start with pr’s in the plugin template soon.

Here you go:

1 Like

Not saying this switch is a bad idea, not even saying the analogy really works, but the opening argument did remind me of: xkcd: Standards :laughing:

4 Likes

This change landed and will be rolled out in the next ci update prs. In order to reformat and lint code pre-commit, you should now run ruff format and ruff check respectively.
In some cases you can even use ruff check --fix to get some of the offenses out of the way.

1 Like

In case you have uv installed, uvx ruff ... is a rather easy way to run it in an isolated environment.

You can also use ruff to help modernize the codebase of a pulp plugin. For example I would suggest to run ruff check --extend-select UP,FURB --fix and see if any of the suggestions look appealing.