|
14 | 14 |
|
15 | 15 | import argparse |
16 | 16 | import sys |
| 17 | +import os |
17 | 18 | import typing |
18 | 19 |
|
| 20 | +from ament_index_python.packages import \ |
| 21 | + get_package_share_directory, \ |
| 22 | + PackageNotFoundError |
| 23 | +from ament_index_python.resources import get_resource |
| 24 | + |
19 | 25 | from ros2interface.api import type_completer |
20 | 26 | from ros2interface.verb import VerbExtension |
21 | 27 | from rosidl_adapter.parser import \ |
|
25 | 31 | MessageSpecification, \ |
26 | 32 | parse_message_string, \ |
27 | 33 | SERVICE_REQUEST_RESPONSE_SEPARATOR |
28 | | -from rosidl_runtime_py import get_interface_path |
29 | 34 |
|
30 | 35 |
|
31 | 36 | class InterfaceTextLine: |
@@ -108,9 +113,23 @@ def _get_interface_lines(interface_identifier: str) -> typing.Iterable[Interface |
108 | 113 | raise ValueError( |
109 | 114 | f"Invalid name '{interface_identifier}'. Expected three parts separated by '/'" |
110 | 115 | ) |
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 | + ) |
112 | 131 |
|
113 | | - file_path = get_interface_path(interface_identifier) |
| 132 | + file_path = os.path.join(share_dir, interface[0]) |
114 | 133 | with open(file_path) as file_handler: |
115 | 134 | for line in file_handler: |
116 | 135 | yield InterfaceTextLine( |
|
0 commit comments