Skip to content

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Jun 24, 2025

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.

  1. Use flake8 plus flake8-docstring to run the 'ament-style` rules on Tools/ros2.
  2. Run ament_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.

@cclauss cclauss changed the title pre-commit: Add a job that runs ament_pep257 Tools/ros2 pre-commit: Add a job that runs ament_pep257 Tools/ros2 Jun 24, 2025
@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch from 8270e49 to 82378e9 Compare June 24, 2025 08:29
@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch from 82378e9 to d63950a Compare June 25, 2025 10:50
@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch from d63950a to 647fe72 Compare July 5, 2025 15:21
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
```
@cclauss
Copy link
Contributor Author

cclauss commented Jul 5, 2025

It would be also interesting to add a copyright pre-commit hook:

@Ryanf55 Ryanf55 self-requested a review July 12, 2025 04:46
Copy link
Contributor

@Ryanf55 Ryanf55 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, a nice improvement, but perhaps theres a way to avoid duplicating the specific ament rules here.

Works on my system as intended.
image

@cclauss
Copy link
Contributor Author

cclauss commented Jul 12, 2025

Thanks for the review

Here are two solutions (we should pick just one)

Do you prefer the hook that uses flake8-docstrings or the one that uses ament_pep257?

@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch from 9538915 to c07aeaf Compare July 12, 2025 18:02
@Ryanf55
Copy link
Contributor

Ryanf55 commented Jul 12, 2025

Works for

Thanks for the review

Here are two solutions (we should pick just one)

Do you prefer the hook that uses flake8-docstrings or the one that uses ament_pep257?

ament_pep257 please

@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch from c07aeaf to a01252b Compare July 12, 2025 20:59
@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch 3 times, most recently from 46c0980 to 25b20e8 Compare August 13, 2025 07:09
@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch from 25b20e8 to a3211a6 Compare August 15, 2025 07:18
@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch from a3211a6 to c8905dc Compare August 31, 2025 11:18
[`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.
@cclauss cclauss force-pushed the pre-commit_ament-lint-pep257_Tools-ros2 branch from c8905dc to 40d830e Compare September 2, 2025 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants