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

ci: replace Python linter flake8 with ruff #3302

Closed
wants to merge 3 commits into from
Closed

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Apr 11, 2023

Ruff supports over 500 lint rules and can be used to replace Flake8 (plus dozens of plugins), isort, pydocstyle, yesqa, eradicate, pyupgrade, and autoflake, all while executing (in Rust) tens or hundreds of times faster than any individual tool.

The ruff Action uses minimal steps to run in ~5 seconds, rapidly providing intuitive GitHub Annotations to contributors.

image

@nschonni

@cclauss cclauss changed the title ci: replace flake8 with ruff ci: replace Python linter flake8 with ruff Apr 11, 2023
@@ -0,0 +1,14 @@
# https://beta.ruff.rs
name: lint_python
on:
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@cclauss cclauss Apr 12, 2023

Choose a reason for hiding this comment

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

This is a bad practice when tools are fast.

build git:(ruff) % time ruff .

ruff .  0.01s user 0.03s system 74% cpu 0.065 total

Ruff will lint the entire CPython codebase in 0.29 seconds with no cache so we are saving no time by attempting to hide files from the linter and could easily miss faults in code added to this repo in the future.

Copy link
Member

Choose a reason for hiding this comment

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

It's not about tool speed, it's about not running jobs that can have unrelated job failures on a PR

.github/workflows/lint_python.yml Outdated Show resolved Hide resolved
"YTT", # flake8-2020
]
ignore = [
"B904",
Copy link
Member

Choose a reason for hiding this comment

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

Are this ignores TODOs or forever things? Sometimes useful to document why/how the might be fixed if someone has an interest to try and address them later

Copy link
Contributor Author

@cclauss cclauss Apr 12, 2023

Choose a reason for hiding this comment

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

I will let others determine if/when they want to reduce the ignore list

Rule information is easy to acquire: ruff rule B904

raise-without-from-inside-except (B904)

Derived from the flake8-bugbear linter.

Message formats:

  • Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

"S701"
]
line-length = 223
target-version = "py37"
Copy link
Member

Choose a reason for hiding this comment

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

If the target is going to stay 3.7 for now, maybe the CI should keep the pinned version that I dropped in the other PR

Copy link
Contributor Author

@cclauss cclauss Apr 12, 2023

Choose a reason for hiding this comment

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

See #3301 (comment)

Ruff does not run on Python so it changes in similar ways to flake8 but only based on --target-version=pyXX.

Just like Node.js, Python has a release cycle: https://devguide.python.org/versions

Py37 will reach EOL in two months.

"S110",
"S701"
]
line-length = 223
Copy link
Member

Choose a reason for hiding this comment

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

Guessing this was to get it passing, rather than a preferred line length like the old 250 value

Copy link
Contributor Author

@cclauss cclauss Apr 12, 2023

Choose a reason for hiding this comment

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

88 is the preferred value for Python code. The goal here is to set high water marks so that if a contributor wants to go beyond that level they will need to justify their actions in the code reviews of their pull requests. The same is true of max-args, max-branches, max-complexity, etc.

Co-authored-by: Nick Schonning <nschonni@gmail.com>
@github-actions github-actions bot added the stale label Feb 10, 2024
@github-actions github-actions bot closed this Mar 11, 2024
@cclauss cclauss deleted the ruff branch March 11, 2024 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants