pre-commit: Add a job that runs ament_pep257 Tools/ros2#30449
Merged
peterbarker merged 1 commit intoArduPilot:masterfrom Sep 3, 2025
Merged
Conversation
ament_pep257 Tools/ros2
8270e49 to
82378e9
Compare
82378e9 to
d63950a
Compare
d63950a to
647fe72
Compare
cclauss
added a commit
to cclauss/ardupilot
that referenced
this pull request
Jul 5, 2025
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 ```
cclauss
added a commit
to cclauss/ardupilot
that referenced
this pull request
Jul 5, 2025
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 ```
Contributor
Author
|
It would be also interesting to add a copyright pre-commit hook: |
Ryanf55
reviewed
Jul 12, 2025
Contributor
Author
|
Thanks for the review
Do you prefer the hook that uses |
9538915 to
c07aeaf
Compare
Contributor
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Tools/ros2/ardupilot_dds_tests/test/test_pep257.pyensures 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.
flake8plusflake8-docstringto run the 'ament-style` rules on Tools/ros2.ament_pep257on Tools/ros2.Quick equivalent commands:
How was this tested?
pre-commit run flake8 --all-filesto ensure no errors.pre-commit run ament-pep257 --all-filesto ensure no errors.Edit
Tools/ros2/ardupilot_sitl/src/ardupilot_sitl/utilities.pyand 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 texterror.