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

Support available typesupport specification in CLI extension #133

Merged
merged 3 commits into from
Jul 13, 2021
Merged
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
8 changes: 4 additions & 4 deletions rosidl_generator_py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ if(BUILD_TESTING)
APPEND_LIBRARY_DIRS "${_append_library_dirs}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/rosidl_generator_py"
)
endif()

ament_add_pytest_test(test_cli_extension test/test_cli_extension.py
PYTHON_EXECUTABLE "${BUILDTYPE_PYTHON_EXECUTABLE}"
)
ament_add_pytest_test(test_cli_extension test/test_cli_extension.py
PYTHON_EXECUTABLE "${BUILDTYPE_PYTHON_EXECUTABLE}"
)
endif()
endif()

ament_package(
Expand Down
14 changes: 9 additions & 5 deletions rosidl_generator_py/rosidl_generator_py/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@

class GeneratePython(GenerateCommandExtension):

def __init__(self, name, *, typesupport_implementations=None):
super().__init__(name)
if typesupport_implementations is None:
typesupport_implementations = ['rosidl_typesupport_c']
typesupport_implementations.extend(
get_resources('rosidl_typesupport_c'))
self.__typesupport_implementations = typesupport_implementations

def generate(
self,
package_name,
Expand Down Expand Up @@ -55,10 +63,6 @@ def generate(
))

# Generate code
typesupport_implementations = ['rosidl_typesupport_c']
typesupport_implementations.extend(
get_resources('rosidl_typesupport_c')
)
with legacy_generator_arguments_file(
package_name=package_name,
interface_files=idl_interface_files,
Expand All @@ -68,4 +72,4 @@ def generate(
) as path_to_arguments_file:
return generate_py(
path_to_arguments_file,
typesupport_implementations)
self.__typesupport_implementations)
32 changes: 25 additions & 7 deletions rosidl_generator_py/test/test_cli_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,33 @@

import pathlib

from ament_index_python import get_resources
from rosidl_cli.command.generate.api import generate

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


def test_cli_extension_for_smoke(tmp_path):
generate(
package_name='rosidl_generator_py',
interface_files=[PACKAGE_DIR + ':msg/StringArrays.msg'],
types=['py'],
output_path=tmp_path
)
def test_cli_extension_for_smoke(tmp_path, capsys):
# NOTE(hidmic): pytest and empy do not play along,
# the latter expects some proxy will stay in sys.stdout
# and the former insists in overwriting it
interface_files = [PACKAGE_DIR + ':msg/StringArrays.msg']

with capsys.disabled(): # so do everything in one run
# Passing target typesupport implementations explictly
generate(
package_name='rosidl_typesupport_py',
interface_files=interface_files,
types=['py[typesupport_implementations:{}]'.format(
list(get_resources('rosidl_typesupport_c'))
)],
output_path=tmp_path / 'explicit_args'
)

# Using default typesupport implementations
generate(
package_name='rosidl_typesupport_pu',
interface_files=interface_files,
types=['py'],
output_path=tmp_path / 'defaults'
)