Skip to content

Commit 6e0fae8

Browse files
[pre-commit for python and cmake]
Uses ruff Modifies pyproject.toml to add ruff setup README.md add Ruff badge. Modifies py files consequently.
1 parent c627ab3 commit 6e0fae8

18 files changed

+209
-139
lines changed

.pre-commit-config.yaml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
1-
# See https://pre-commit.com for more information
2-
# See https://pre-commit.com/hooks.html for more hooks
1+
ci:
2+
autoupdate_branch: 'devel'
33
repos:
44
- repo: https://github.com/pre-commit/mirrors-clang-format
5-
rev: v14.0.6
5+
rev: v15.0.7
66
hooks:
77
- id: clang-format
88
args: [--style=Google]
99
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: v3.2.0
10+
rev: v4.4.0
1111
hooks:
12-
- id: trailing-whitespace
13-
- id: end-of-file-fixer
14-
- id: check-yaml
1512
- id: check-added-large-files
13+
- id: check-ast
14+
- id: check-executables-have-shebangs
15+
- id: check-json
16+
- id: check-merge-conflict
17+
- id: check-symlinks
18+
- id: check-toml
19+
- id: check-yaml
20+
- id: debug-statements
21+
- id: destroyed-symlinks
22+
- id: detect-private-key
23+
- id: end-of-file-fixer
24+
- id: fix-byte-order-marker
25+
- id: mixed-line-ending
26+
- id: trailing-whitespace
27+
- repo: https://github.com/psf/black
28+
rev: 22.12.0
29+
hooks:
30+
- id: black
31+
- repo: https://github.com/charliermarsh/ruff-pre-commit
32+
rev: v0.0.259
33+
hooks:
34+
- id: ruff
35+
args: [--fix, --exit-non-zero-on-fix]
36+
- repo: https://github.com/cheshirekow/cmake-format-precommit
37+
rev: v0.6.13
38+
hooks:
39+
- id: cmake-format
40+
- repo: https://github.com/PyCQA/isort
41+
rev: 5.12.0
42+
hooks:
43+
- id: isort

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ include(cmake/ros.cmake)
3131
compute_project_args(PROJECT_ARGS LANGUAGES CXX)
3232
project(${PROJECT_NAME} ${PROJECT_ARGS})
3333

34-
#if(NOT CMAKE_CXX_STANDARD)
34+
# if(NOT CMAKE_CXX_STANDARD)
3535
set(CMAKE_CXX_STANDARD 17)
36-
#endif()
36+
# endif()
3737

3838
cmake_policy(SET CMP0057 NEW)
3939
find_package(ament_cmake REQUIRED)
@@ -83,5 +83,5 @@ install(DIRECTORY include/ DESTINATION include)
8383
# Install package information
8484
install(FILES package.xml DESTINATION share/${PROJECT_NAME})
8585

86-
#ROS 2 packaging
86+
# ROS 2 packaging
8787
ament_package()

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dynamic-graph bindings
44
[![Building Status](https://travis-ci.org/stack-of-tasks/dynamic_graph_bridge.svg?branch=master)](https://travis-ci.org/stack-of-tasks/dynamic_graph_bridge)
55
[![Pipeline status](https://gitlab.laas.fr/stack-of-tasks/dynamic_graph_bridge/badges/master/pipeline.svg)](https://gitlab.laas.fr/stack-of-tasks/dynamic_graph_bridge/commits/master)
66
[![Coverage report](https://gitlab.laas.fr/stack-of-tasks/dynamic_graph_bridge/badges/master/coverage.svg?job=doc-coverage)](http://projects.laas.fr/gepetto/doc/stack-of-tasks/dynamic_graph_bridge/master/coverage/)
7+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff)
78

89
This ROS package binds together the ROS framework with the
910
dynamic-graph real-time control architecture.

include/dynamic_graph_bridge/sot_loader.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <thread>
2929

3030
// ROS includes
31-
//#include "ros/ros.h"
31+
// #include "ros/ros.h"
3232
#include <tf2_ros/transform_broadcaster.h>
3333

3434
#include <sensor_msgs/msg/joint_state.hpp>

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tool.black]
2+
exclude = "cmake"
3+
4+
[tool.ruff]
5+
exclude = ["cmake"]
6+
extend-ignore = ["D203", "D213"]
7+
extend-select = ["A", "B", "C", "COM", "D", "EM", "EXE", "G", "N", "PTH", "RET", "RUF", "UP", "W", "YTT"]
8+
target-version = "py310"
9+
10+
[tool.isort]
11+
profile = "black"

scripts/remote_python_client.py

100644100755
Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
"""@package dynamic_graph_bridge
3+
"""@package dynamic_graph_bridge.
44
55
@file
66
@license License BSD-3-Clause
@@ -11,15 +11,18 @@
1111
1212
"""
1313

14+
import atexit
15+
import code
16+
1417
# Standard import.
1518
import optparse
16-
import os.path
17-
import code
1819
import os
19-
import sys
20+
import os.path
2021
import readline
21-
import atexit
2222
import signal
23+
import sys
24+
from pathlib import Path
25+
2326
import rclpy
2427

2528
# Used to connect to ROS services
@@ -28,44 +31,41 @@
2831

2932

3033
def signal_handler(sig, frame):
31-
"""
32-
Catch Ctrl+C and quit.
33-
"""
34+
"""Catch Ctrl+C and quit."""
3435
print("")
3536
print("You pressed Ctrl+C! Closing ros client and shell.")
3637
rclpy.try_shutdown()
3738
sys.exit(0)
3839

3940

4041
# Command history, auto-completetion and keyboard management
41-
python_history = os.path.join(os.environ["HOME"], ".dg_python_history")
42+
python_history = Path.join(os.environ["HOME"], ".dg_python_history")
4243
readline.parse_and_bind("tab: complete")
4344
readline.set_history_length(100000)
4445

4546

4647
def save_history(histfile):
47-
""" Write the history of the user command in a file """
48+
"""Write the history of the user command in a file."""
4849
readline.write_history_file(histfile)
4950

5051

5152
"""
52-
Read the current history if it exists and program its save upon the program end.
53+
Read the current history if it exists and program
54+
its save upon the program end.
5355
"""
5456
if hasattr(readline, "read_history_file"):
5557
try:
5658
readline.read_history_file(python_history)
57-
except IOError:
59+
except OSError:
5860
pass
5961
atexit.register(save_history, python_history)
6062

6163

6264
class DynamicGraphInteractiveConsole(code.InteractiveConsole):
63-
"""
64-
For the subtilities please read https://docs.python.org/3/library/code.html
65-
"""
65+
"""For the subtilities please read https://docs.python.org/3/library/code.html."""
6666

6767
def __init__(self):
68-
68+
"""Create interpreter in ROS for DG interactive console."""
6969
# Create the python terminal
7070
code.InteractiveConsole.__init__(self)
7171

@@ -78,19 +78,19 @@ def __init__(self):
7878
readline.set_completer(self.dg_completer.complete)
7979

8080
def runcode(self, code):
81-
"""
82-
Inherited from code.InteractiveConsole
81+
"""Inherited from code.InteractiveConsole.
8382
84-
We execute the code pushed in the cache `self.lines_pushed`. The code is
85-
pushed whenever the user press enter during the interactive session.
83+
We execute the code pushed in the cache `self.lines_pushed`.
84+
The code is pushed whenever the user press enter during the
85+
interactive session.
8686
see https://docs.python.org/3/library/code.html
8787
"""
8888
try:
8989
# we copy the line in a tmp var
9090
code_string = self.lines_pushed[:-1]
91-
result = self.ros_python_interpreter.run_python_command(
92-
code_string
93-
)
91+
rpi = self.ros_python_interpreter
92+
result = rpi.run_python_command(code_string)
93+
9494
self.write(result)
9595
if not result.endswith("\n"):
9696
self.write("\n")
@@ -101,17 +101,15 @@ def runcode(self, code):
101101
return False
102102

103103
def runsource(self, source, filename="<input>", symbol="single"):
104-
"""
105-
Inherited from code.InteractiveConsole
104+
"""Inherited from code.InteractiveConsole.
106105
107106
see https://docs.python.org/3/library/code.html
108107
"""
109108
try:
110109
c = code.compile_command(source, filename, symbol)
111110
if c:
112111
return self.runcode(c)
113-
else:
114-
return True
112+
return True
115113
except SyntaxError:
116114
self.showsyntaxerror()
117115
self.lines_pushed = ""
@@ -123,11 +121,9 @@ def runsource(self, source, filename="<input>", symbol="single"):
123121
return False
124122

125123
def push(self, line):
126-
"""
127-
Upon pressing enter in the interactive shell the user "push" a string.
128-
This method is then called with the string pushed.
129-
We catch the string to send it via the rosservice.
130-
"""
124+
"""Upon pressing enter in the interactive shell the user "push" a string."""
125+
"""This method is then called with the string pushed.
126+
We catch the string to send it via the rosservice."""
131127
self.lines_pushed += line + "\n"
132128
return code.InteractiveConsole.push(self, line)
133129

@@ -142,14 +138,9 @@ def push(self, line):
142138

143139
if args[:]:
144140
infile = args[0]
145-
response = dg_console.ros_python_interpreter.run_python_script(
146-
os.path.abspath(infile)
147-
)
148-
print(
149-
dg_console.ros_python_interpreter.run_python_command(
150-
"print('File parsed')"
151-
)
152-
)
141+
rpi = dg_console.ros_python_interpreter
142+
response = rpi.run_python_script(Path.abspath(infile))
143+
print(rpi.run_python_command("print('File parsed')"))
153144

154145
signal.signal(signal.SIGINT, signal_handler)
155146
dg_console.interact("Interacting with remote python server.")

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
exclude = cmake
3+
max-line-length = 88
4+
extend-ignore = E203

src/CMakeLists.txt

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ set(${PROJECT_NAME}_SOURCES
2020
)
2121
add_library(ros_bridge SHARED ${${PROJECT_NAME}_SOURCES}
2222
${${PROJECT_NAME}_HEADERS})
23-
target_include_directories(ros_bridge
23+
target_include_directories(
24+
ros_bridge
2425
PUBLIC $<INSTALL_INTERFACE:include>
2526
PRIVATE ${PROJECT_SOURCE_DIR}/include)
2627
target_link_libraries(
@@ -52,19 +53,21 @@ endif(NOT INSTALL_PYTHON_INTERFACE_ONLY)
5253
set(plugins ros_publish ros_subscribe)
5354
foreach(plugin ${plugins})
5455
get_filename_component(plugin_library_name ${plugin} NAME)
55-
add_library(${plugin_library_name} SHARED
56-
${PROJECT_SOURCE_DIR}/src/${plugin}.cpp #
57-
${PROJECT_SOURCE_DIR}/src/${plugin}.hpp #
56+
add_library(
57+
${plugin_library_name} SHARED ${PROJECT_SOURCE_DIR}/src/${plugin}.cpp #
58+
${PROJECT_SOURCE_DIR}/src/${plugin}.hpp #
5859
)
5960
if(SUFFIX_SO_VERSION)
6061
set_target_properties(${plugin_library_name} PROPERTIES SOVERSION
61-
${PROJECT_VERSION})
62+
${PROJECT_VERSION})
6263
endif(SUFFIX_SO_VERSION)
6364
target_link_libraries(
64-
${plugin_library_name} ${${plugin_library_name}_deps} ${catkin_LIBRARIES} ros_bridge
65+
${plugin_library_name} ${${plugin_library_name}_deps} ${catkin_LIBRARIES}
66+
ros_bridge
6567
dynamic_graph_bridge_msgs::dynamic_graph_bridge_msgs__rosidl_typesupport_cpp
6668
)
67-
target_include_directories(${plugin_library_name}
69+
target_include_directories(
70+
${plugin_library_name}
6871
PUBLIC $<INSTALL_INTERFACE:include>
6972
PRIVATE ${PROJECT_SOURCE_DIR}/include)
7073
if(NOT INSTALL_PYTHON_INTERFACE_ONLY)
@@ -86,7 +89,8 @@ foreach(plugin ${plugins})
8689
${PROJECT_NAME}-${PYTHON_LIBRARY_NAME}-wrap MODULE_HEADER
8790
"${CMAKE_CURRENT_SOURCE_DIR}/${plugin}-python.hh")
8891
endif()
89-
target_include_directories(${PROJECT_NAME}-${PYTHON_LIBRARY_NAME}-wrap
92+
target_include_directories(
93+
${PROJECT_NAME}-${PYTHON_LIBRARY_NAME}-wrap
9094
PUBLIC $<INSTALL_INTERFACE:include>
9195
PRIVATE ${PROJECT_SOURCE_DIR}/include)
9296
endif(BUILD_PYTHON_INTERFACE)
@@ -100,10 +104,11 @@ endif(BUILD_PYTHON_INTERFACE)
100104

101105
# Sot loader library
102106
add_library(sot_loader sot_loader.cpp sot_loader_basic.cpp)
103-
target_link_libraries(
107+
target_link_libraries(
104108
sot_loader Boost::program_options ${catkin_LIBRARIES} ros_bridge
105109
dynamic_graph_bridge_msgs::dynamic_graph_bridge_msgs__rosidl_typesupport_cpp)
106-
target_include_directories(sot_loader
110+
target_include_directories(
111+
sot_loader
107112
PUBLIC $<INSTALL_INTERFACE:include>
108113
PRIVATE ${PROJECT_SOURCE_DIR}/include)
109114
install(
@@ -114,10 +119,15 @@ install(
114119
# Stand alone embedded intepreter with a robot controller.
115120
add_executable(geometric_simu programs/geometric_simu.cpp)
116121
target_link_libraries(
117-
geometric_simu Boost::program_options ${CMAKE_DL_LIBS} ${catkin_LIBRARIES}
118-
ros_bridge sot_loader
122+
geometric_simu
123+
Boost::program_options
124+
${CMAKE_DL_LIBS}
125+
${catkin_LIBRARIES}
126+
ros_bridge
127+
sot_loader
119128
dynamic_graph_bridge_msgs::dynamic_graph_bridge_msgs__rosidl_typesupport_cpp)
120-
target_include_directories(geometric_simu
129+
target_include_directories(
130+
geometric_simu
121131
PUBLIC $<INSTALL_INTERFACE:include>
122132
PRIVATE ${PROJECT_SOURCE_DIR}/include)
123133
install(TARGETS geometric_simu DESTINATION lib/${PROJECT_NAME})

src/dynamic_graph/ros/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""@package dynamic_graph_bridge
1+
"""@package dynamic_graph_bridge.
22
33
@file __init__.py
44
@author Maximilien Naveau (maximilien.naveau@gmail.com)

0 commit comments

Comments
 (0)