Skip to content

Commit 8ffe7df

Browse files
authored
🖤 Add Black formatter for Python files. (#936)
1 parent e7bab63 commit 8ffe7df

25 files changed

+666
-483
lines changed

‎.pre-commit-config.yaml‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,17 @@ repos:
4343

4444
# PyDocStyle
4545
- repo: https://github.com/PyCQA/pydocstyle
46-
rev: 6.2.2
46+
rev: 6.3.0
4747
hooks:
4848
- id: pydocstyle
4949
args: ["--ignore=D100,D101,D102,D103,D104,D105,D106,D107,D203,D212,D404"]
5050

51+
- repo: https://github.com/psf/black
52+
rev: 23.1.0
53+
hooks:
54+
- id: black
55+
args: ["--line-length=99"]
56+
5157
- repo: https://github.com/pycqa/flake8
5258
rev: 6.0.0
5359
hooks:
@@ -117,7 +123,7 @@ repos:
117123
exclude: CHANGELOG\.rst$
118124

119125
- repo: https://github.com/pre-commit/pygrep-hooks
120-
rev: v1.9.0
126+
rev: v1.10.0
121127
hooks:
122128
- id: rst-backticks
123129
exclude: CHANGELOG\.rst$

‎controller_manager/controller_manager/__init__.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
load_controller,
2222
reload_controller_libraries,
2323
switch_controllers,
24-
unload_controller
24+
unload_controller,
2525
)
2626

2727
__all__ = [
28-
'configure_controller',
29-
'list_controller_types',
30-
'list_controllers',
31-
'list_hardware_components',
32-
'list_hardware_interfaces',
33-
'load_controller',
34-
'reload_controller_libraries',
35-
'switch_controllers',
36-
'unload_controller',
28+
"configure_controller",
29+
"list_controller_types",
30+
"list_controllers",
31+
"list_hardware_components",
32+
"list_hardware_interfaces",
33+
"load_controller",
34+
"reload_controller_libraries",
35+
"switch_controllers",
36+
"unload_controller",
3737
]

‎controller_manager/controller_manager/controller_manager_services.py‎

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from controller_manager_msgs.srv import ConfigureController, \
16-
ListControllers, ListControllerTypes, ListHardwareComponents, ListHardwareInterfaces, \
17-
LoadController, ReloadControllerLibraries, SwitchController, UnloadController
15+
from controller_manager_msgs.srv import (
16+
ConfigureController,
17+
ListControllers,
18+
ListControllerTypes,
19+
ListHardwareComponents,
20+
ListHardwareInterfaces,
21+
LoadController,
22+
ReloadControllerLibraries,
23+
SwitchController,
24+
UnloadController,
25+
)
1826

1927
import rclpy
2028

@@ -24,68 +32,90 @@ def service_caller(node, service_name, service_type, request, service_timeout=10
2432

2533
if not cli.service_is_ready():
2634
node.get_logger().debug(
27-
f'waiting {service_timeout} seconds for service {service_name} to become available...')
35+
f"waiting {service_timeout} seconds for service {service_name} to become available..."
36+
)
2837
if not cli.wait_for_service(service_timeout):
29-
raise RuntimeError(f'Could not contact service {service_name}')
38+
raise RuntimeError(f"Could not contact service {service_name}")
3039

31-
node.get_logger().debug(f'requester: making request: {request}\n')
40+
node.get_logger().debug(f"requester: making request: {request}\n")
3241
future = cli.call_async(request)
3342
rclpy.spin_until_future_complete(node, future)
3443
if future.result() is not None:
3544
return future.result()
3645
else:
37-
raise RuntimeError(f'Exception while calling service: {future.exception()}')
46+
raise RuntimeError(f"Exception while calling service: {future.exception()}")
3847

3948

4049
def configure_controller(node, controller_manager_name, controller_name):
4150
request = ConfigureController.Request()
4251
request.name = controller_name
43-
return service_caller(node, f'{controller_manager_name}/configure_controller',
44-
ConfigureController, request)
52+
return service_caller(
53+
node, f"{controller_manager_name}/configure_controller", ConfigureController, request
54+
)
4555

4656

4757
def list_controllers(node, controller_manager_name):
4858
request = ListControllers.Request()
49-
return service_caller(node, f'{controller_manager_name}/list_controllers',
50-
ListControllers, request)
59+
return service_caller(
60+
node, f"{controller_manager_name}/list_controllers", ListControllers, request
61+
)
5162

5263

5364
def list_controller_types(node, controller_manager_name):
5465
request = ListControllerTypes.Request()
55-
return service_caller(node,
56-
f'{controller_manager_name}/list_controller_types',
57-
ListControllerTypes, request)
66+
return service_caller(
67+
node, f"{controller_manager_name}/list_controller_types", ListControllerTypes, request
68+
)
5869

5970

6071
def list_hardware_components(node, controller_manager_name):
6172
request = ListHardwareComponents.Request()
62-
return service_caller(node, f'{controller_manager_name}/list_hardware_components',
63-
ListHardwareComponents, request)
73+
return service_caller(
74+
node,
75+
f"{controller_manager_name}/list_hardware_components",
76+
ListHardwareComponents,
77+
request,
78+
)
6479

6580

6681
def list_hardware_interfaces(node, controller_manager_name):
6782
request = ListHardwareInterfaces.Request()
68-
return service_caller(node, f'{controller_manager_name}/list_hardware_interfaces',
69-
ListHardwareInterfaces, request)
83+
return service_caller(
84+
node,
85+
f"{controller_manager_name}/list_hardware_interfaces",
86+
ListHardwareInterfaces,
87+
request,
88+
)
7089

7190

7291
def load_controller(node, controller_manager_name, controller_name):
7392
request = LoadController.Request()
7493
request.name = controller_name
75-
return service_caller(node, f'{controller_manager_name}/load_controller',
76-
LoadController, request)
94+
return service_caller(
95+
node, f"{controller_manager_name}/load_controller", LoadController, request
96+
)
7797

7898

7999
def reload_controller_libraries(node, controller_manager_name, force_kill):
80100
request = ReloadControllerLibraries.Request()
81101
request.force_kill = force_kill
82-
return service_caller(node,
83-
f'{controller_manager_name}/reload_controller_libraries',
84-
ReloadControllerLibraries, request)
85-
86-
87-
def switch_controllers(node, controller_manager_name, deactivate_controllers,
88-
activate_controllers, strict, activate_asap, timeout):
102+
return service_caller(
103+
node,
104+
f"{controller_manager_name}/reload_controller_libraries",
105+
ReloadControllerLibraries,
106+
request,
107+
)
108+
109+
110+
def switch_controllers(
111+
node,
112+
controller_manager_name,
113+
deactivate_controllers,
114+
activate_controllers,
115+
strict,
116+
activate_asap,
117+
timeout,
118+
):
89119
request = SwitchController.Request()
90120
request.activate_controllers = activate_controllers
91121
request.deactivate_controllers = deactivate_controllers
@@ -95,12 +125,14 @@ def switch_controllers(node, controller_manager_name, deactivate_controllers,
95125
request.strictness = SwitchController.Request.BEST_EFFORT
96126
request.activate_asap = activate_asap
97127
request.timeout = rclpy.duration.Duration(seconds=timeout).to_msg()
98-
return service_caller(node, f'{controller_manager_name}/switch_controller',
99-
SwitchController, request)
128+
return service_caller(
129+
node, f"{controller_manager_name}/switch_controller", SwitchController, request
130+
)
100131

101132

102133
def unload_controller(node, controller_manager_name, controller_name):
103134
request = UnloadController.Request()
104135
request.name = controller_name
105-
return service_caller(node, f'{controller_manager_name}/unload_controller',
106-
UnloadController, request)
136+
return service_caller(
137+
node, f"{controller_manager_name}/unload_controller", UnloadController, request
138+
)

‎controller_manager/controller_manager/launch_utils.py‎

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
from launch_ros.actions import Node
2020

2121

22-
def generate_load_controller_launch_description(controller_name,
23-
controller_type=None,
24-
controller_params_file=None):
22+
def generate_load_controller_launch_description(
23+
controller_name, controller_type=None, controller_params_file=None
24+
):
2525
"""
2626
Generate launch description for loading a controller using spawner.
2727
@@ -44,38 +44,53 @@ def generate_load_controller_launch_description(controller_name,
4444
4545
"""
4646
declare_controller_mgr_name = DeclareLaunchArgument(
47-
'controller_manager_name', default_value='controller_manager',
48-
description='Controller manager node name'
47+
"controller_manager_name",
48+
default_value="controller_manager",
49+
description="Controller manager node name",
4950
)
5051
declare_unload_on_kill = DeclareLaunchArgument(
51-
'unload_on_kill', default_value='false',
52-
description='Wait until the node is interrupted and then unload controller'
52+
"unload_on_kill",
53+
default_value="false",
54+
description="Wait until the node is interrupted and then unload controller",
5355
)
5456

5557
spawner_arguments = [
5658
controller_name,
57-
'--controller-manager',
58-
LaunchConfiguration('controller_manager_name')
59+
"--controller-manager",
60+
LaunchConfiguration("controller_manager_name"),
5961
]
6062

6163
if controller_type:
62-
spawner_arguments += ['--controller-type', controller_type]
64+
spawner_arguments += ["--controller-type", controller_type]
6365

6466
if controller_params_file:
65-
spawner_arguments += ['--param-file', controller_params_file]
67+
spawner_arguments += ["--param-file", controller_params_file]
6668

6769
# Setting --unload-on-kill if launch arg unload_on_kill is "true"
6870
# See https://github.com/ros2/launch/issues/290
69-
spawner_arguments += [PythonExpression(
70-
['"--unload-on-kill"', ' if "true" == "',
71-
LaunchConfiguration('unload_on_kill'), '" else ""']
72-
)]
71+
spawner_arguments += [
72+
PythonExpression(
73+
[
74+
'"--unload-on-kill"',
75+
' if "true" == "',
76+
LaunchConfiguration("unload_on_kill"),
77+
'" else ""',
78+
]
79+
)
80+
]
7381

74-
spawner = Node(package='controller_manager', executable='spawner',
75-
arguments=spawner_arguments, shell=True, output='screen')
82+
spawner = Node(
83+
package="controller_manager",
84+
executable="spawner",
85+
arguments=spawner_arguments,
86+
shell=True,
87+
output="screen",
88+
)
7689

77-
return LaunchDescription([
78-
declare_controller_mgr_name,
79-
declare_unload_on_kill,
80-
spawner,
81-
])
90+
return LaunchDescription(
91+
[
92+
declare_controller_mgr_name,
93+
declare_unload_on_kill,
94+
spawner,
95+
]
96+
)

0 commit comments

Comments
 (0)