-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Pre-Commit #4915
base: main
Are you sure you want to change the base?
Pre-Commit #4915
Conversation
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 went through about a quarter of the changes, however I think the vast majority of the python3 changes need to be reverted. It creates hundreds of linting errors for flake8 / pep57.
For example, do we want to introduce ruff and maybe mypy?
What are the advantages of these tools? Keep in mind we have some python3 linters already with pep57 / flake8 that come from ament that we use (and have CI jobs that run)
How should we integrate that into the CI?
We have the linters already in our CI, but it might be value to add in codespell or some others that not already running as github actions. I know we added this in Nav2 Docs recently with precommits in CI so you can use it as a template: https://github.com/ros-navigation/docs.nav2.org/blob/master/.github/workflows/precommit.yaml
What about other hooks?
Any suggestions @tonynajjar ?
Thank you Steve. Sorry for not pointing out, that the changes are just a preview of what would change with the current preliminary config. Did not meant to create review noise for you.
I would vote for using pre-commit as drop in replacement for the lint workflow. Running the linters as pre-commit hooks.
I like ruff mainly because of it's speed and support for multiple linter and formatters There also exiast a topic on ros discourse. |
One nice thing about that though is that they each show up in the GitHub UX as a separate job, which makes it easier for a developer to see where the error is and break down a laundry list of tasks into more bite-sized results (and the jobs are named after the task for immediate review knowledge about the nature of the failure). Is there a way to do something like that with precommit? An option we could have is to have the precommit mirror what we check with CI jobs and developers can enable precommit locally to run the workflow, but the workflows in CI run with inidividual jobs that match the set of precommit jobs (so we'd need to add a codespell, etc in our linting workflow). Perhaps not ruff since we have pep57 and flake8. I try to keep this project fully aligned with the ROS 2 best practices as a reference for other applications.
That sounds nice! Is there much we'd have to do to implement that? We honestly don't have much python anyway, so adding type hints on the returns of each method isn't actually a big deal (I think we can/should ignore |
The output of pre-commit is visible in the summary of a job. I normally setup git hooks in my dev env, so that i am not allowed to commit if pre-commit fails (output of pre-commit looks the same). Not sure if there is a pretty way to run each pre-commit hook as seperate job.
Wouldn't be maintaining parity between pre-commit and CI jobs an overhead?
I will open a separate issue regarding this. |
That's not automatic, they manually call it from a github action workflow https://github.com/ros-controls/ros2_control/tree/5d4933d2945b72bf2625a2a28c98107433c31d9d/.github/workflows. I agree turning it on in the dev environment makes sense for those that want to use it! I think that's the intent behind the ticket.
Sure, but if in exchange our CI has more clear failures to help developers fix those issues, I think that's worthwhile than piling everything into a single job that more junior engineers need to parse to find their issue(s). Keep in mind there's a wide array of developers that contribute to ROS 2 from the most junior writing the first bits of code in their career to Senior Staff Engineers. There are quite a few things in our process that are catered to the junior developers and hobbyists to lower the technical and process barriers of entry. Plus, its not like we modify linting often. We have never actually made an update to our |
So I tested a few things, but apparently the logs from ament_flake8 and ament_pep257 are too noisy to really work well with pre-commit. Maybe that's one of the reasons why the ros2_control people don't use ament for these. We could also decide to only run tools via pre-commit (e.g. codespell) that are not present in the lint workflow. Apart from that, I have had very good experiences with pre-commit and junior developers as they get feedback earlier and there is less “push and pray”. |
That is actually quite a bit of work, those profiles change not super infrequently - once every distro or so.
Sure, but at that point, why not just have a CI job do the additional items like codespell? Though, Nav2 doesn't have alot of python in general, so I think it would be OK to exclude the python linters from precommit if its just those and not the C++ ones. Don't let the enemy of 'good' be 'great' considering we have vastly more C++.
Personally, I actually run the tests before committing for the most part or manually execute |
The motivation behind my ticket was simply the frustration of finding out about linting issues "a little bit too late". It's still not terrible since the linters run first, but still the sooner the better. Putting the discussion of which additional linters to have aside for a bit, I think just having the |
4b53a4c
to
b80d5a1
Compare
Thank you @SteveMacenski for sharing your knowledge/ thoughts, i really appreciate this :). I have posted a minimal config file. |
Codecov ReportAll modified and coverable lines are covered by tests ✅ |
I do like the idea of adding static type checking for python3 & code spell in our CI and/or precommit. That's a good quality move! Can you add those into this PR? I think it would be good both in a CI job as well as the precommit I think the lint.yml can have the codespell and mypy run, no? Then they also run as fast, parallel jobs here as well |
cbae4e9
to
ed73ec8
Compare
@Nils-ChristianIseke, your PR has failed to build. Please check CI outputs and resolve issues. |
84d3796
to
680a4b9
Compare
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.
LGTM in general -- anything else you'd want to add here?
@tonynajjar please review the precommit config file, I can do the rest
nav2_rviz_plugins/src/particle_cloud_display/flat_weighted_arrows_array.cpp
Show resolved
Hide resolved
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 are a few PGM, SVG files that this modifies. We should make a rule to skip svg/pgm files since we'll have maps and svg design docs that shouldn't be modified
The linters aren't running for some reason |
Hi Steve I will ping you as soon as it's ready to review :) |
060b40a
to
1df96f4
Compare
6d34cae
to
5c763e2
Compare
d929331
to
6610713
Compare
6610713
to
385c098
Compare
385c098
to
5c763e2
Compare
Signed-off-by: Nils-ChristianIseke <[email protected]>
ad2adf7
to
8eff6f9
Compare
Signed-off-by: Nils-ChristianIseke <[email protected]>
08eddfe
to
276c889
Compare
This pull request is in conflict. Could you fix it @Nils-ChristianIseke? |
@SteveMacenski You can have a look now. There are some open questions from my side:
|
e2fd8a0
to
56987ff
Compare
} |
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.
Can we skip all json and css files? These are autogenerated
@@ -173,7 +173,7 @@ planner_server: | |||
plugin: "nav2_system_tests::NoValidPathErrorPlanner" | |||
no_viapoints_given: | |||
plugin: "nav2_system_tests::NoViapointsGivenErrorPlanner" | |||
cancelled: | |||
cancelled: # codespell:ignore cancelled |
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.
his needs to be updated since you changed the value in palnner_plugins
. This is a test, so easy enough. Just change here to canceled
and remove the codespell ignore
# pre-commit autoupdate | ||
# | ||
# See https://github.com/pre-commit/pre-commit | ||
exclude: ".pgm$|.svg$" |
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.
css / json
@@ -0,0 +1,90 @@ | |||
# To use: |
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.
@tonynajjar can you review just this file? I did the rest but I could use your eye on this to make sure you're also happy with it
I think we decided that precommit would be for local users only, not for CI, no? Or maybe I'm missing what you're saying
Yes! I thought I was a PR that did some of this already, but I'm having a hard time finding it. Maybe it was a comment in the ticket
Up to you, I don't feel strongly about it Overall, the last few review comments are tiny, I'm largely happy with this! |
Sorry, I had a typo: We could only execute things via pre-commit that are not available in the current ament workflows: Codespell and pre-commit-hooks. If we do so not much additional setup would be needed for CI. This would also reopen the CI discussion, as we have mainly been discussing whether pre-commit should replace the current CI workflow. And with this setup pre-commit would be neither a replacement nor a duplication but would run as a supplement in the CI. But if your earlier concern regarding pre-commit in CI was in general, then my bad for bringing it up again! Just wanted to make sure we’re on the same page. |
I'd be interested in Tony's thoughts, but personally I just run tests locally in my workflow so this feature isn't for me (but love adding codespell into our CI workflow!) :-) Is there a way to silence precommit steps that don't have error output? Somes docs review makes me think that |
#4769
Suggestion for a pre-commit configuration.
I've taken the one from ros2 control as a basis and added a few things I am using myself. I still need to put some work into it, but I wanted to provide this in advance as a basis for discussion.
For example, do we want to introduce ruff and maybe mypy?
What about other hooks?
How should we integrate that into the CI?