Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions ros2topic/ros2topic/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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."""

Expand Down
2 changes: 1 addition & 1 deletion ros2topic/ros2topic/verb/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ros2topic/ros2topic/verb/pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down