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
GitHub Action to lint Python code with ruff #1771
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1771 +/- ##
==========================================
+ Coverage 97.41% 97.43% +0.01%
==========================================
Files 66 66
Lines 10839 10839
==========================================
+ Hits 10559 10561 +2
+ Misses 280 278 -2
... and 1 file with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I want be able to take a good look at this for a couple of days, probably. But a quick question - can you elaborate a bit on what this does better or differently than what we have currently? You mentioned speed and the intuitive annotations, but does this report on new/different categories of linting problems than our existing setup? |
I believe that the front page of https://beta.ruff.rs explains the advantages quite succinctly. If we did |
Okay, thanks for those links. I'll review them when I get a chance. |
.github/workflows/ruff.yml
Outdated
- uses: actions/checkout@v3 | ||
- run: pip install --user ruff | ||
- run: ruff --ignore=E402,F401,F403,F405,F541,F601,F811,F841 | ||
--format=github --line-length=214 --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.
As far as I understand, this replaces flake8, so it probably makes sense to remove the flake8 check if this will be used.
I wonder about that line length of 214 requirement. We also use black
, which uses 88 as the maximum line length, which ruff
also seems to use, so why this setting? In case it doesn't understand the noqa
comment, it would be better to switch off the check for line length, as it is already done by black
anyway.
Also, why all the exclusions? Apart from E402 (module-import-not-at-top-of-file) I see no reason for the rest.
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.
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.
Sorry, I don't understand what you mean.
I can see that this makefile is quite outdated and should probably be adapted or removed, though :)
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.
Let's leverage --format=github
to show where the errors are.
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.
Please review the first ten errors in the code listing... https://github.com/pydicom/pydicom/pull/1771/files
Let's agree that line-length
is currently different under psf/black
(best effort formatter) and ruff
(rules-based linter) but our goal is to make them the same.
- The difference because the former is guidance for a tool that formats code but not comments, docstrings, etc., and is deliberately timid about reformatting strings while the latter can be used as a trigger for one or more good-first-issues for interested contributors to shorten long lines that
psf/black
does not autofix.
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.
About the first ten errors: I think these are all things that can be either easily fixed, or these lines should get an exclusion comment. I just think it makes more sense to fix them instead of disabling the warnings.
As for line-length: as far as I could see, these are from generated code. It would make sense just to exclude these files from the check by a file-wide exclusion comment, if that is possible. The same is true for unused imports in __init__.py
.
Anyway, I'm not saying that you have to do all of it now - that is something that can also be handled later by somebody else. In this case I would like to at least remove the redundant flake8 check (it is redundant, right?), and write a new issue for enabling and fixing these warnings.
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.
pyproject.toml
added with appropriate settings and #1776 add to cover follow-on tasks.
b1e8dbf
to
4912ef5
Compare
[Ruff](https://beta.ruff.rs/) supports [over 500 lint rules](https://beta.ruff.rs/docs/rules) including bandit, isort, pylint, pyupgrade, and flake8 plus its plugins and is written in Rust for speed. The `ruff` Action uses minimal steps to run in ~10 seconds, rapidly providing intuitive GitHub Annotations to contributors. ![image](https://user-images.githubusercontent.com/3709715/223758136-afc386d2-70aa-4eff-953a-2c2d82ceea23.png)
.github/workflows/ruff.yml
Outdated
steps: | ||
- uses: actions/checkout@v3 | ||
- run: pip install --user ruff | ||
- run: ruff --format=github . |
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.
You left in the flake8 workflow - do you think it is still needed?
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 is wired into https://github.com/reviewdog/action-flake8 and I cannot tell if you need reviewdog
.
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.
Well, reviewdoc
does the same as ruff
, e.g. create annotation in the code, so if ruff
is better suited, we don't need it anymore. I see that you have removed it already.
I may have a look at the differences between the two later, but your changes look good to me so far.
Will wait for @darcymason for his opinion on the change.
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.
Hi all, I have limited time right now, but I'll try to take a better look later today.
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.
@mrbean-bremen, I wasn't sure if there was anything else you wanted to review, but I'll merge in and we can adapt in other PR(s) as needed...
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.
That's ok, I'm happy with that. There is still #1776 for improvements.
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.
Okay, had a pretty good look through. Thanks for this - it does make all this much leaner and looks easier to fine-tune as well.
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 ~10 seconds, rapidly providing intuitive GitHub Annotations to contributors.Describe the changes
The related issue or a description of the bug or feature that this PR addresses.
Tasks
doc/_build/html/index.html
)