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

[Tooling] Switch from flake8 to ruff #15362

Merged
merged 8 commits into from
Jun 20, 2023
Merged

[Tooling] Switch from flake8 to ruff #15362

merged 8 commits into from
Jun 20, 2023

Conversation

dosisod
Copy link
Contributor

@dosisod dosisod commented Jun 3, 2023

To quote Ruff's README: "An extremely fast Python linter, written in Rust".

In my testing Ruff takes 200ms to lint the entire codebase whereas flake8 takes about 5.5 seconds (27x slower). Running pre-commit run -a only takes about 2.3 seconds now, which should make local dev work a bit faster (assuming you run linters regularly).

Ruff includes a lot of rules out of the box, including all the (important) rules from flake8, flake8-bugbear, flake8-noqa, and many more. Having all these built-in rules makes it much easier to incrementally enable checks/flags without having to install tons of flake8 plugins. You can see a full list of common flake8 plugins Ruff supports here.

I made sure that the configs matched as close as I could get them. Some minor rules like line indentation and such aren't in Ruff since they are always just disabled. Ruff also ignores everything in the .gitignore file, so that cleans up the exclude section.

Lastly, the test-data folder seemed to have its own .flake8 config file, but it was disabled in the setup.cfg file. I migrated the config over, but it doesn't really matter because it is being ignored anyways. Is this intentional?

To quote Ruff's README: "An extremely fast Python linter, written in Rust".

In my testing Ruff takes 200ms to lint the entire codebase whereas flake8
takes about 5.5 seconds (27x slower). Running `pre-commit run -a` only takes
about 2.3 seconds now, which should make local dev work a bit faster (assuming
you run linters regularly).

Ruff includes a lot of rules out of the box, including all the (important)
rules from `flake8`, `flake8-bugbear`, `flake8-noqa`, and many more. Having
all these built-in rules makes it much easier to incrementally improve the
codebase without having to install tons of flake8 plugins.

I made sure that the configs matched as close as I could get them. Some minor
rules like line indentation and such aren't in Ruff since they are always just
disabled. Ruff also ignores everything in the `.gitignore` file, so that cleans
up the exclude section.

Lastly, the `test-data` section seemed to have its own `.flake8` config file,
but it was disabled in the `setup.cfg` file. I migrated the config over, but
it doesn't really matter because it is being ignored anyways. Is this
intentional?
pyproject.toml Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 16, 2023

I experimented with this a bit. It makes linting much faster. It seems particularly nice now that we've migrated to Black, as linting is somewhat less important than it used to be -- many style issues can be auto-fixed. Waiting for a lint run that usually only finds some missing imports seems wasteful to me.

Does anybody else have thoughts about this? I'm positive about this, but I'd like to hear if somebody else has opinions.

@AlexWaygood
Copy link
Member

I'm +1 on this. Ruff is incredibly fast, and the autofixes are pretty nice. The tool is newer than flake8, but it's also very actively developed, so I'm confident any bugs in ruff would be fixed pretty quickly if we stumbled upon them.

pyproject.toml Show resolved Hide resolved
@github-actions

This comment has been minimized.

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I posted some comments about config. I like the autofixes.

I started using ruff at work this week for autofix reasons. I ran into like five bugs, but two were already fixed when I went to report, a third was fixed very fast, a fourth was upstream in the rust parser, and none would affect mypy's usage here. Overall, works well and I'm in favour!

pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
test-requirements.txt Show resolved Hide resolved
@github-actions

This comment has been minimized.

pyproject.toml Outdated Show resolved Hide resolved
Co-authored-by: Alex Waygood <[email protected]>
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja merged commit 304997b into python:master Jun 20, 2023
20 checks passed
@dosisod dosisod deleted the ruff branch June 26, 2023 18:07
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

Successfully merging this pull request may close these issues.

6 participants