Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse middle_module from message type in ros2topic #278

Closed
wants to merge 2 commits into from
Closed
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
9 changes: 5 additions & 4 deletions ros2topic/ros2topic/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@ def __call__(self, prefix, parsed_args, **kwargs):
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('/')
if not package_name or not message_name or not all(message_name):
package_name, middle_module, message_name = message_type.split('/')
if not middle_module:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic doesn't seem to make any sense. In which case would not middle_module be True?

middle_module = 'msg'
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should just support any number of parts, e.g. '.'.join([package_name] + message_name[:-1]).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it not generally make sense to unify this logic and have it in a central place? I know of at least one more other location where we duplicate the same logic:
https://github.com/ros2/ros2cli/blob/master/ros2service/ros2service/verb/call.py#L61-L72

Copy link
Member

@jacobperron jacobperron Jun 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. There's a TODO at the top of this function. I'm not sure what package it should belong in (or if a new package needs to be created).

return getattr(module, message_name[-1])
return getattr(module, message_name)


class TopicTypeCompleter:
Expand Down