Skip to content

Commit af3a133

Browse files
JelmerdwMax Waterhout
andauthored
Add pydoclint (#186)
* Add ruff checks to the pyproject.toml Signed-off-by: Max Waterhout <[email protected]> * Add docstrings to rcdt_actions Signed-off-by: Max Waterhout <[email protected]> * add docstrings to rcdt_franka Signed-off-by: Max Waterhout <[email protected]> * Added docstrings to pyflow package Signed-off-by: Max Waterhout <[email protected]> * Added docstrings to rcdt_gazebo Signed-off-by: Max Waterhout <[email protected]> * added docstring to moveit Signed-off-by: Max Waterhout <[email protected]> * added docstring to rcdt_sensors Signed-off-by: Max Waterhout <[email protected]> * Added docstrings to rcdt_joystick Signed-off-by: Max Waterhout <[email protected]> * Added docstrings to rcdt_mobile_manipulator Signed-off-by: Max Waterhout <[email protected]> * added docstrings to rcdt_panther Signed-off-by: Max Waterhout <[email protected]> * Added docstrings to rcdt_utilities Signed-off-by: Max Waterhout <[email protected]> * Added docstring to rcdt_detection Signed-off-by: Max Waterhout <[email protected]> * Update ruff configuration to include DOC in select and remove exclusion for rcdt_detection Signed-off-by: Max Waterhout <[email protected]> * Added preview mode and extra ruff functions to the pyproject.toml Signed-off-by: Max Waterhout <[email protected]> * Add norecursedirs option to pytest configuration Signed-off-by: Max Waterhout <[email protected]> * Ruff format Signed-off-by: Max Waterhout <[email protected]> * Ruff and Ty fixes Signed-off-by: Max Waterhout <[email protected]> * Use Any as type. Signed-off-by: Jelmer de Wolde <[email protected]> * Add pydoclint to docker. Signed-off-by: Jelmer de Wolde <[email protected]> * Install flake8 bin via apt. Signed-off-by: Jelmer de Wolde <[email protected]> * Add pydoclint to workflow. Signed-off-by: Jelmer de Wolde <[email protected]> * Undo ignore of ruff rule. Signed-off-by: Jelmer de Wolde <[email protected]> * Add documentation. Signed-off-by: Jelmer de Wolde <[email protected]> --------- Signed-off-by: Max Waterhout <[email protected]> Signed-off-by: Jelmer de Wolde <[email protected]> Co-authored-by: Max Waterhout <[email protected]>
1 parent d379983 commit af3a133

File tree

26 files changed

+104
-126
lines changed

26 files changed

+104
-126
lines changed

.github/workflows/linting.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ jobs:
2121
- run: ruff format --check
2222
- run: ruff check
2323

24+
pydoclint:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: actions/setup-python@v5
29+
with:
30+
python-version: "3.10"
31+
- run: pip install pydoclint
32+
- run: pydoclint ros2_ws/src
33+
2434
clang-format:
2535
runs-on: ubuntu-latest
2636
steps:

dockerfiles/install_scripts/dev_packages.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pip install pytest-timeout
1111
pip install ruff
1212
pip install ty
1313
pip install termcolor
14+
pip install pydoclint[flake8]
15+
pip install Flake8-pyproject
1416

1517
# Specifying numpy range to work with ROS and Ultralytics:
1618
pip install "numpy>=1.23.0,<2.0"
@@ -20,6 +22,7 @@ pip install "transforms3d>=0.4.2"
2022

2123
sudo apt update
2224
sudo apt install -y \
25+
flake8 \
2326
ros-humble-navigation2 \
2427
ros-humble-nav2-bringup \
2528
ros-humble-slam-toolbox

docs/content/workflows.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ We make use of different Github workflows to automatically validate the code in
1010

1111
## Linting
1212

13-
The Linting workflow contains three checks:
13+
The Linting workflow contains the following checks:
1414

1515
- **ruff**:\
1616
Checks the format and style of the .py files in this repository, using the rules specified in *pyproject.toml*.
1717

18+
-**pydoclint**\:
19+
Checks the docstring of the .py files in the rosw_ws/src directory, using the rules specified in *pyproject.toml*. These checks might be implemented in Ruff in the [future](https://github.com/astral-sh/ruff/issues/12434), but for now we use pydoclint for the additional checks not available in Ruff.
20+
1821
- **clang-format**:\
1922
Checks the format of the .cpp, .h and .hpp files in this repository.
2023

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,17 @@ extra-paths = [
3131
"ros2_ws/src/rcdt_utilities/",
3232
"ros2_ws/src/rcdt_gazebo/",
3333
]
34+
35+
# Settings of pydoclint, also in flake8 to use in vscode:
36+
[tool.flake8]
37+
style = "google"
38+
skip-checking-short-docstrings = false
39+
allow-init-docstring = true
40+
check-style-mismatch = true
41+
select = "DOC"
42+
43+
[tool.pydoclint]
44+
style = "google"
45+
skip-checking-short-docstrings = false
46+
allow-init-docstring = true
47+
check-style-mismatch = true

ros2_ws/src/rcdt_actions/rcdt_actions/definitions/definitions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ class Sequence:
190190
actions: list[Action]
191191
node: Node | None = None
192192
goal_handle: ServerGoalHandle | None = None
193-
last_result = None
194-
success = True
195-
index = 0
193+
last_result: object = None
194+
success: bool = True
195+
index: int = 0
196196

197197
def reset(self) -> None:
198198
"""Reset the sequence to its initial state."""

ros2_ws/src/rcdt_actions/src_py/action_executor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ def callback(self, goal_handle: ServerGoalHandle) -> Sequence.Result:
7272
return result
7373

7474

75-
def main(args: str = None) -> None:
76-
"""Main function to initialize the ROS 2 node and start the action executor."""
75+
def main(args: str | None = None) -> None:
76+
"""Main function to initialize the ROS 2 node and start the action executor.
77+
78+
Args:
79+
args (str | None): Command line arguments. Defaults to None.
80+
"""
7781
rclpy.init(args=args)
7882
executor = MultiThreadedExecutor()
7983
node = ActionExecutor()

ros2_ws/src/rcdt_detection/rcdt_detection/mask_properties.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
Quaternion,
1919
)
2020
from rclpy import logging
21-
from typing_extensions import Self
2221

2322
from rcdt_detection.image_manipulation import three_to_single_channel
2423

@@ -237,7 +236,7 @@ def mode_depth(self) -> float:
237236
masked_depth_values = self.depth_image[self.single_channel > 0]
238237
return np.bincount(masked_depth_values).argmax()
239238

240-
def refined_mask(self) -> Self:
239+
def refined_mask(self) -> "MaskProperties":
241240
"""Returns a refined mask based on the mode depth value.
242241
243242
The refined mask is created by applying a condition that keeps only the pixels within a certain range around the mode depth value.

ros2_ws/src/rcdt_detection/src_py/get_mask_properties.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ class GetMaskProperties(Node):
2121
2222
This node provides a service that takes a mask, depth image, and camera info,
2323
and returns properties such as contour, bounding box, centroid, and average hue.
24-
25-
Attributes:
26-
node_name (str): The name of the node.
27-
service_name (str): The name of the service provided by this node.
2824
"""
2925

3026
def __init__(self) -> None:

ros2_ws/src/rcdt_detection/src_py/get_rgbd_from_topic.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ class GetRGBDFromTopic(Node):
1919
2020
This node provides a service that waits for an RGBD message on a specified topic
2121
and returns the RGB image, depth image, and their respective camera info.
22-
23-
Attributes:
24-
node_name (str): The name of the node.
25-
service_name (str): The name of the service provided by this node.
2622
"""
2723

2824
def __init__(self) -> None:

ros2_ws/src/rcdt_detection/src_py/pose_from_pixel.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ class PoseFromPixel(Node):
2121
2222
This node provides a service that takes a pixel location and depth image,
2323
and returns the 3D pose of that pixel in the camera's coordinate frame.
24-
25-
Attributes:
26-
node_name (str): The name of the node.
27-
service_name (str): The name of the service provided by this node.
2824
"""
2925

3026
def __init__(self) -> None:

0 commit comments

Comments
 (0)