-
Notifications
You must be signed in to change notification settings - Fork 166
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
Conversation
@@ -0,0 +1,14 @@ | |||
# https://beta.ruff.rs | |||
name: lint_python | |||
on: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest copying the filters from https://github.com/nodejs/build/pull/3301/files#diff-14721317565b7c66355f276ec27762054b12f390afd6c35fba85cfaf77d311c7R2, but adding pyproject.toml
to the lists
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
"YTT", # flake8-2020 | ||
] | ||
ignore = [ | ||
"B904", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling
"S701" | ||
] | ||
line-length = 223 | ||
target-version = "py37" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
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.
@nschonni