Skip to content

Commit 9dc3f85

Browse files
committed
fix non standard interface locations. (#1186)
Signed-off-by: Tim Wendt <techtasie@gmail.com>
1 parent 992b08b commit 9dc3f85

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

ros2interface/ros2interface/verb/show.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@
1414

1515
import argparse
1616
import sys
17+
import os
1718
import typing
1819

20+
from ament_index_python.packages import \
21+
get_package_share_directory, \
22+
PackageNotFoundError
23+
from ament_index_python.resources import get_resource
24+
1925
from ros2interface.api import type_completer
2026
from ros2interface.verb import VerbExtension
2127
from rosidl_adapter.parser import \
@@ -25,7 +31,6 @@
2531
MessageSpecification, \
2632
parse_message_string, \
2733
SERVICE_REQUEST_RESPONSE_SEPARATOR
28-
from rosidl_runtime_py import get_interface_path
2934

3035

3136
class InterfaceTextLine:
@@ -108,9 +113,23 @@ def _get_interface_lines(interface_identifier: str) -> typing.Iterable[Interface
108113
raise ValueError(
109114
f"Invalid name '{interface_identifier}'. Expected three parts separated by '/'"
110115
)
111-
pkg_name, _, msg_name = parts
116+
pkg_name, msg_type, msg_name = parts
117+
118+
try:
119+
share_dir = get_package_share_directory(pkg_name)
120+
except PackageNotFoundError:
121+
raise ValueError(f"Unknown package '{pkg_name}'")
122+
123+
interfaces, _ = get_resource('rosidl_interfaces', pkg_name)
124+
interfaces = interfaces.splitlines()
125+
126+
interface = [f for f in interfaces if f.endswith(msg_name + '.' + msg_type)]
127+
if len(interface) == 0:
128+
raise LookupError(
129+
f"Interface '{msg_type}/{msg_name}' not found in package '{pkg_name}'"
130+
)
112131

113-
file_path = get_interface_path(interface_identifier)
132+
file_path = os.path.join(share_dir, interface[0])
114133
with open(file_path) as file_handler:
115134
for line in file_handler:
116135
yield InterfaceTextLine(

ros2interface/test/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def test_show_not_an_interface(self):
527527
assert interface_command.exit_code == 1
528528
assert launch_testing.tools.expect_output(
529529
expected_lines=[re.compile(
530-
r"Could not find the interface '.+NotAMessageTypeName\.idl'"
530+
r"Interface 'msg/NotAMessageTypeName' not found in package 'test_msgs'"
531531
)],
532532
text=interface_command.output,
533533
strict=True

0 commit comments

Comments
 (0)