From 936ea3cfc9dbf84180bc3f63466857a4b3198250 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Tue, 16 May 2023 17:35:44 +0000 Subject: [PATCH] Fixes from review. Signed-off-by: Chris Lalancette --- ros2cli/ros2cli/helpers.py | 11 +++++++++++ ros2service/ros2service/api/__init__.py | 2 +- ros2service/ros2service/verb/echo.py | 12 +----------- ros2topic/ros2topic/api/__init__.py | 10 ---------- ros2topic/ros2topic/verb/echo.py | 2 +- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/ros2cli/ros2cli/helpers.py b/ros2cli/ros2cli/helpers.py index 2dd83400a..3cfd1a44e 100644 --- a/ros2cli/ros2cli/helpers.py +++ b/ros2cli/ros2cli/helpers.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from argparse import ArgumentTypeError import functools import inspect import os @@ -96,3 +97,13 @@ def wrapper(*args, **kwargs): return func(*args, **kwargs) wrapper.__signature__ = inspect.signature(func) return wrapper + + +def unsigned_int(string): + try: + value = int(string) + except ValueError: + value = -1 + if value < 0: + raise ArgumentTypeError('value must be non-negative integer') + return value diff --git a/ros2service/ros2service/api/__init__.py b/ros2service/ros2service/api/__init__.py index cfd99d1d5..ad8162f01 100644 --- a/ros2service/ros2service/api/__init__.py +++ b/ros2service/ros2service/api/__init__.py @@ -41,7 +41,7 @@ def get_service_class(node: Node, service_name: str, include_hidden_services: bo The service should be running for this function to find the service type. :param node: The node object of rclpy Node class. - :param service_name: The name of the service. + :param service_name: The fully-qualified name of the service. :param include_hidden_services: Whether to include hidden services while finding the list of currently running services. :return: diff --git a/ros2service/ros2service/verb/echo.py b/ros2service/ros2service/verb/echo.py index a2669aaf7..54af5b290 100644 --- a/ros2service/ros2service/verb/echo.py +++ b/ros2service/ros2service/verb/echo.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from argparse import ArgumentTypeError from typing import TypeVar import rclpy from rclpy.qos import QoSPresetProfiles +from ros2cli.helpers import unsigned_int from ros2cli.node.strategy import NodeStrategy from ros2service.api import get_service_class from ros2service.api import ServiceNameCompleter @@ -32,16 +32,6 @@ MsgType = TypeVar('MsgType') -def unsigned_int(string): - try: - value = int(string) - except ValueError: - value = -1 - if value < 0: - raise ArgumentTypeError('value must be non-negative integer') - return value - - class EchoVerb(VerbExtension): """Echo a service.""" diff --git a/ros2topic/ros2topic/api/__init__.py b/ros2topic/ros2topic/api/__init__.py index 265c85bc0..7b5b4f94a 100644 --- a/ros2topic/ros2topic/api/__init__.py +++ b/ros2topic/ros2topic/api/__init__.py @@ -29,16 +29,6 @@ from rosidl_runtime_py.utilities import get_message -def unsigned_int(string): - try: - value = int(string) - except ValueError: - value = -1 - if value < 0: - raise ArgumentTypeError('value must be non-negative integer') - return value - - def positive_int(string): try: value = int(string) diff --git a/ros2topic/ros2topic/verb/echo.py b/ros2topic/ros2topic/verb/echo.py index 339fb0b91..7f669c17c 100644 --- a/ros2topic/ros2topic/verb/echo.py +++ b/ros2topic/ros2topic/verb/echo.py @@ -24,6 +24,7 @@ from rclpy.qos import QoSProfile from rclpy.qos import QoSReliabilityPolicy from rclpy.task import Future +from ros2cli.helpers import unsigned_int from ros2cli.node.strategy import add_arguments as add_strategy_node_arguments from ros2cli.node.strategy import NodeStrategy from ros2topic.api import add_qos_arguments @@ -31,7 +32,6 @@ from ros2topic.api import positive_float from ros2topic.api import qos_profile_from_short_keys from ros2topic.api import TopicNameCompleter -from ros2topic.api import unsigned_int from ros2topic.verb import VerbExtension from rosidl_runtime_py import message_to_csv from rosidl_runtime_py import message_to_yaml