Skip to content
Open
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
25 changes: 22 additions & 3 deletions ros2interface/ros2interface/verb/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@
# limitations under the License.

import argparse
import os
import sys
import typing

from ament_index_python.packages import \
get_package_share_directory, \
PackageNotFoundError
from ament_index_python.resources import get_resource

from ros2interface.api import type_completer
from ros2interface.verb import VerbExtension
from rosidl_adapter.parser import \
Expand All @@ -25,7 +31,6 @@
MessageSpecification, \
parse_message_string, \
SERVICE_REQUEST_RESPONSE_SEPARATOR
from rosidl_runtime_py import get_interface_path


class InterfaceTextLine:
Expand Down Expand Up @@ -108,9 +113,23 @@ def _get_interface_lines(interface_identifier: str) -> typing.Iterable[Interface
raise ValueError(
f"Invalid name '{interface_identifier}'. Expected three parts separated by '/'"
)
pkg_name, _, msg_name = parts
pkg_name, msg_type, msg_name = parts

try:
share_dir = get_package_share_directory(pkg_name)
except PackageNotFoundError:
raise LookupError(f"Unknown package '{pkg_name}'")

interfaces, _ = get_resource('rosidl_interfaces', pkg_name)
interfaces = interfaces.splitlines()

interface = [f for f in interfaces if f.endswith(msg_name + '.' + msg_type)]
if len(interface) == 0:
raise LookupError(
f"Interface '{msg_type}/{msg_name}' not found in package '{pkg_name}'"
)

file_path = get_interface_path(interface_identifier)
file_path = os.path.join(share_dir, interface[0])
with open(file_path) as file_handler:
for line in file_handler:
yield InterfaceTextLine(
Expand Down
2 changes: 1 addition & 1 deletion ros2interface/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def test_show_not_an_interface(self):
assert interface_command.exit_code == 1
assert launch_testing.tools.expect_output(
expected_lines=[re.compile(
r"Could not find the interface '.+NotAMessageTypeName\.idl'"
r"Interface 'msg/NotAMessageTypeName' not found in package 'test_msgs'"
)],
text=interface_command.output,
strict=True
Expand Down