-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[RFC] scripts: ci: check_compliance: Add python lint/format check #81070
base: main
Are you sure you want to change the base?
Conversation
Reporting or annotating issues can be done on a range rather than a single line. Add support for end line and end column. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
80df49f
to
80f2713
Compare
Why add exclusions? If someone adds a new file e.g. a runner from an external source, they would have to fix the file, but if an existing runner which does not comply is excluded, that can be updated forever going forwards without having to comply? Or is the idea that new exclusions would be added, in which case what would be the point of having the check if everything is excluded? |
This is up for debate of course, but the idea is to force new files to comply, while we gradually convert the existing ones. It could be brought up during a review to update a file you are touching to comply. |
This is something I asked about before because one of the files added from an external source, a uf2 one if I remember right, had some oddities about it, and someone said the file shouldn't be fixed because whilst it was being added to zephyr, it was not a zephyr file, and you then lose the ability to diff etc. |
I think this can be an exception, but that's what the exclude lists are for. |
can we use ruff to fix the issues in this PR? |
Kind of chicken and egg, the $ ruff format --check scripts/ci/check_compliance.py
Would reformat: scripts/ci/check_compliance.py
1 file would be reformatted
$ ruff check scripts/ci/check_compliance.py
Found 25 errors. |
so if this PR merged, can we then use ruff to auto fix issues? if not, this could be a heavy loading |
Yes! For the current selected rules: $ ruff check
...
Found 3713 errors.
[*] 1972 fixable with the `--fix` option (506 hidden fixes can be enabled with the `--unsafe-fixes` option). But I'd suggest doing fixes in separate PRs to make it easier to digest for reviewing, and it's best to double check automatic fixes. Formatting can be done too, but this would result in a lot of git churn. |
Add simple scripts to convert ruff check and ruff format output to toml exclude sections. These sections can be used to ignore baseline violations for an existing codebase. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Add a baseline toml file for current rule violations, and a default configuration file. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Add a compliance test using ruff, for both linting and formatting of newly added python files. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
Seems like a good idea, curious why did you pick ruff instead of black? (I know pretty much nothing about these) |
I think black is just a formatter while ruff does both linting & formatting? |
It's all packed into one tool, so it should never contradict itself, while using different linter and formatter tools might need exceptions. |
Introduction
As the codebase and contributions keep growing, so does all the python tooling.
This PR is intended to make python scripts more uniform and safe.
Proposed change
Add ruff as a linter and formatter for python files, and verify (new) files in CI.
Detailed RFC
Some hightlights:
ruff
is a drop-in replacement for many popular python tools, and it is super fast.Current enabled linter rules:
Many more can be added/enabled but this is a solid baseline.
Concerns
Existing files do not comply, so they are explicitly excluded. Ideally these are gradually converted to comply.
Formatting is obviously opinionated, but I do think for python we should follow the popular kids, which are
black
andruff
.