diff --git a/ros2topic/ros2topic/api/__init__.py b/ros2topic/ros2topic/api/__init__.py index dbded8efa..00f82e015 100644 --- a/ros2topic/ros2topic/api/__init__.py +++ b/ros2topic/ros2topic/api/__init__.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import importlib - from time import sleep import rclpy @@ -23,6 +21,7 @@ from rclpy.validate_full_topic_name import validate_full_topic_name from ros2cli.node.strategy import NodeStrategy from ros2msg.api import message_type_completer +from rosidl_runtime_py import import_message_type def get_topic_names_and_types(*, node, include_hidden_topics=False): @@ -54,24 +53,6 @@ def __call__(self, prefix, parsed_args, **kwargs): parsed_args, self.include_hidden_topics_key)) -def import_message_type(topic_name, message_type): - # TODO(dirk-thomas) this logic should come from a rosidl related package - try: - package_name, message_name = message_type.split('/', 2) - if not package_name or not message_name: - raise ValueError() - except ValueError: - raise RuntimeError('The passed message type is invalid') - - # TODO(sloretz) node API to get topic types should indicate if action or msg - middle_module = 'msg' - if topic_name.endswith('/_action/feedback'): - middle_module = 'action' - - module = importlib.import_module(package_name + '.' + middle_module) - return getattr(module, message_name) - - class TopicTypeCompleter: """Callable returning an existing topic type or all message types.""" diff --git a/ros2topic/ros2topic/verb/echo.py b/ros2topic/ros2topic/verb/echo.py index 91e75cf31..07f21f082 100644 --- a/ros2topic/ros2topic/verb/echo.py +++ b/ros2topic/ros2topic/verb/echo.py @@ -20,9 +20,9 @@ from rclpy.validate_full_topic_name import validate_full_topic_name from ros2cli.node.direct import DirectNode from ros2topic.api import get_topic_names_and_types -from ros2topic.api import import_message_type from ros2topic.api import TopicNameCompleter from ros2topic.verb import VerbExtension +from rosidl_runtime_py import import_message_type from rosidl_runtime_py import message_to_csv from rosidl_runtime_py import message_to_yaml diff --git a/ros2topic/ros2topic/verb/pub.py b/ros2topic/ros2topic/verb/pub.py index 967f4acfc..16a9da0f8 100644 --- a/ros2topic/ros2topic/verb/pub.py +++ b/ros2topic/ros2topic/verb/pub.py @@ -16,10 +16,10 @@ import rclpy from ros2cli.node import NODE_NAME_PREFIX -from ros2topic.api import import_message_type from ros2topic.api import TopicNameCompleter from ros2topic.api import TopicTypeCompleter from ros2topic.verb import VerbExtension +from rosidl_runtime_py import import_message_type from rosidl_runtime_py import set_message_fields import yaml