Skip to content

Commit e665ade

Browse files
authored
Support available typesupport specification in CLI extension (#133)
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 18f325a commit e665ade

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

rosidl_generator_py/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ if(BUILD_TESTING)
7676
APPEND_LIBRARY_DIRS "${_append_library_dirs}"
7777
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_py"
7878
)
79-
endif()
8079

81-
ament_add_pytest_test(test_cli_extension test/test_cli_extension.py
82-
PYTHON_EXECUTABLE "${BUILDTYPE_PYTHON_EXECUTABLE}"
83-
)
80+
ament_add_pytest_test(test_cli_extension test/test_cli_extension.py
81+
PYTHON_EXECUTABLE "${BUILDTYPE_PYTHON_EXECUTABLE}"
82+
)
83+
endif()
8484
endif()
8585

8686
ament_package(

rosidl_generator_py/rosidl_generator_py/cli.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626

2727
class GeneratePython(GenerateCommandExtension):
2828

29+
def __init__(self, name, *, typesupport_implementations=None):
30+
super().__init__(name)
31+
if typesupport_implementations is None:
32+
typesupport_implementations = ['rosidl_typesupport_c']
33+
typesupport_implementations.extend(
34+
get_resources('rosidl_typesupport_c'))
35+
self.__typesupport_implementations = typesupport_implementations
36+
2937
def generate(
3038
self,
3139
package_name,
@@ -55,10 +63,6 @@ def generate(
5563
))
5664

5765
# Generate code
58-
typesupport_implementations = ['rosidl_typesupport_c']
59-
typesupport_implementations.extend(
60-
get_resources('rosidl_typesupport_c')
61-
)
6266
with legacy_generator_arguments_file(
6367
package_name=package_name,
6468
interface_files=idl_interface_files,
@@ -68,4 +72,4 @@ def generate(
6872
) as path_to_arguments_file:
6973
return generate_py(
7074
path_to_arguments_file,
71-
typesupport_implementations)
75+
self.__typesupport_implementations)

rosidl_generator_py/test/test_cli_extension.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,33 @@
1414

1515
import pathlib
1616

17+
from ament_index_python import get_resources
1718
from rosidl_cli.command.generate.api import generate
1819

1920
PACKAGE_DIR = str(pathlib.Path(__file__).parent.parent)
2021

2122

22-
def test_cli_extension_for_smoke(tmp_path):
23-
generate(
24-
package_name='rosidl_generator_py',
25-
interface_files=[PACKAGE_DIR + ':msg/StringArrays.msg'],
26-
types=['py'],
27-
output_path=tmp_path
28-
)
23+
def test_cli_extension_for_smoke(tmp_path, capsys):
24+
# NOTE(hidmic): pytest and empy do not play along,
25+
# the latter expects some proxy will stay in sys.stdout
26+
# and the former insists in overwriting it
27+
interface_files = [PACKAGE_DIR + ':msg/StringArrays.msg']
28+
29+
with capsys.disabled(): # so do everything in one run
30+
# Passing target typesupport implementations explictly
31+
generate(
32+
package_name='rosidl_typesupport_py',
33+
interface_files=interface_files,
34+
types=['py[typesupport_implementations:{}]'.format(
35+
list(get_resources('rosidl_typesupport_c'))
36+
)],
37+
output_path=tmp_path / 'explicit_args'
38+
)
39+
40+
# Using default typesupport implementations
41+
generate(
42+
package_name='rosidl_typesupport_pu',
43+
interface_files=interface_files,
44+
types=['py'],
45+
output_path=tmp_path / 'defaults'
46+
)

0 commit comments

Comments
 (0)