-
Notifications
You must be signed in to change notification settings - Fork 19.3k
pre-commit: Add a job that runs ament_pep257 Tools/ros2
#30449
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
base: master
Are you sure you want to change the base?
pre-commit: Add a job that runs ament_pep257 Tools/ros2
#30449
Conversation
ament_pep257 Tools/ros2
8270e49
to
82378e9
Compare
82378e9
to
d63950a
Compare
d63950a
to
647fe72
Compare
In `test_[test_copyright.py` and `test_pep257.py`, do not assume that the current working directory is `Tools/ros2` but use a relative path instead. An alternative to: * ArduPilot#30449 % `uvx --with=ament-lint-pep257 pytest Tools/ros2/ardupilot_dds_tests/test/test_pep257.py` ``` 1 passed, 1 warning in 0.20s ``` Edit Tools/ros2/ardupilot_sitl/src/ardupilot_sitl/utilities.py and add a leading or trailing space inside the docstring, and save the file. % `uvx --with=ament-lint-pep257 pytest Tools/ros2/ardupilot_dds_tests/test/test_pep257.py` ``` 1 failed, 1 warning in 0.23s ```
In `test_copyright.py` and `test_pep257.py`, do not assume that the current working directory is `Tools/ros2` but use a relative path instead. An alternative to: * ArduPilot#30449 % `uvx --with=ament-lint-pep257 pytest Tools/ros2/ardupilot_dds_tests/test/test_pep257.py` ``` 1 passed, 1 warning in 0.20s ``` Edit Tools/ros2/ardupilot_sitl/src/ardupilot_sitl/utilities.py and add a leading or trailing space inside the docstring, and save the file. % `uvx --with=ament-lint-pep257 pytest Tools/ros2/ardupilot_dds_tests/test/test_pep257.py` ``` 1 failed, 1 warning in 0.23s ```
It would be also interesting to add a copyright pre-commit hook: |
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.
Thanks for the review
Do you prefer the hook that uses |
9538915
to
c07aeaf
Compare
Works for
|
c07aeaf
to
a01252b
Compare
46c0980
to
25b20e8
Compare
25b20e8
to
a3211a6
Compare
a3211a6
to
c8905dc
Compare
[`Tools/ros2/ardupilot_dds_tests/test/test_pep257.py`](https://github.com/ArduPilot/ardupilot/blob/master/Tools/ros2/ardupilot_dds_tests/test/test_pep257.py) ensures [PEP 257 – Docstring Conventions](https://peps.python.org/pep-0257) compliance for all Python files in Tools/ros2. Partially addresses the concern at * ArduPilot#30426 (comment) Here are two solutions (we should pick just one) that replicate this functionality in pre-commit. 1. Use `flake8` plus `flake8-docstring` to run the 'ament-style` rules on Tools/ros2. 2. Run [`ament_pep257`](https://pypi.org/project/ament-lint-pep257) on Tools/ros2. Quick equivalent commands: ``` uv tool run --with=flake8-docstrings flake8 --select=D \ --ignore=D100,D101,D102,D103,D104,D105,D106,D107,D203,D212,D404 Tools/ros2 uv tool run --from=ament-lint-pep257 ament_pep257 Tools/ros2 > /dev/null ``` How was this tested? 1. Run both equivalent commands to ensure no errors. 2. `pre-commit run flake8 --all-files` to ensure no errors. 3. `pre-commit run ament-pep257 --all-files` to ensure no errors. Edit `Tools/ros2/ardupilot_sitl/src/ardupilot_sitl/utilities.py` and add a leading or trailing space inside the docstring, and save the file. Rerun the four commands to ensure that each raises a `D210: No whitespaces allowed surrounding docstring text` error.
c8905dc
to
40d830e
Compare
Tools/ros2/ardupilot_dds_tests/test/test_pep257.py
ensures PEP 257 – Docstring Conventions compliance for all Python files in Tools/ros2.Partially addresses the concern at
Here are two solutions (we should pick just one) that replicate this functionality in pre-commit.
flake8
plusflake8-docstring
to run the 'ament-style` rules on Tools/ros2.ament_pep257
on Tools/ros2.Quick equivalent commands:
How was this tested?
pre-commit run flake8 --all-files
to ensure no errors.pre-commit run ament-pep257 --all-files
to ensure no errors.Edit
Tools/ros2/ardupilot_sitl/src/ardupilot_sitl/utilities.py
and add a leading or trailing space inside the docstring, and save the file.Rerun the four commands to ensure that each raises a
D210: No whitespaces allowed surrounding docstring text
error.