-
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
Conversation
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? |
Rebased on |
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 <[email protected]>
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 <[email protected]>
Add a baseline toml file for current rule violations, and a default configuration file. Signed-off-by: Pieter De Gendt <[email protected]>
Add a compliance test using ruff, for both linting and formatting of newly added python files. Signed-off-by: Pieter De Gendt <[email protected]>
Update:
|
@pdgendt where do you want to go from here? It's titled and tagged as RFC but arguably good to go. Maybe arch wg? (though it's not really an architectural change but seems like any change with wide impact goes there these days) |
I was thinking the same thing, wanted to bring this up during some workgroup meeting. Could be for arch or process? Maybe we need a tooling working group? CC @carlescufi @nashif any suggestions? |
I think process would be the "correct-er" one but if you want visibility arch is the one to go, I suggest bringing it up there. |
are we going to keep pylint? |
There's no conflict between these two, there is some overlap but I haven't added any of the We might favor enabling the |
but it is suboptimal if we have two linters doing python, at leasr from a developer experience. For example, if there is a violation that is detected by both, will we get two warnings? |
Presumably, yes. But I haven't looked into the overlaps of the current configurations, this can be optimized on the go. As you can see from the excludes file, there are a lot of linter issues that |
I think that before doing this (or at least as part of this) we should at least batch fix the files that are obviously not imported and meant to track an external project, I guess anything under arch, doc, samples, script, tests... |
I was going to do it the other way around, this PR is to prevent any new issues from this point forward. |
Yup that makes sense. |
|
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
.