Skip to content

Commit

Permalink
register rmw python extensions separately
Browse files Browse the repository at this point in the history
* register rmw python extensions separately

* setup the ament_index in the build space for testing

* updates to use new ament_index syntax

* escape ; as \; when passing a PATH list as an env var on Windows

* just append the build folder's ament index as a work around
  • Loading branch information
wjwwood committed Apr 12, 2016
1 parent 24e23fc commit 0bf9640
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
16 changes: 16 additions & 0 deletions rclpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ macro(target)
${PythonExtra_INCLUDE_DIRS}
)

# make an entry in the ament index for each rmw implementation for which
# a rclpy Python extension is built
# this is used in the Python code to avoid trying to import a Python
# extension for rmw implementations which do not have one
ament_index_register_resource("rmw_python_extension"
PACKAGE_NAME ${rmw_implementation}
)

install(TARGETS ${PROJECT_NAME}${target_suffix}
DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}")
endmacro()
Expand All @@ -88,9 +96,17 @@ if(AMENT_ENABLE_TESTING)
ament_lint_auto_find_test_dependencies()

rosidl_generator_py_get_typesupports(_typesupport_impls)
ament_index_get_prefix_path(ament_index_build_path SKIP_AMENT_PREFIX_PATH)
# Get the first item (it will be the build space version of the build path).
list(GET ament_index_build_path 0 ament_index_build_path)
if(WIN32)
# On Windows prevent CMake errors and prevent it being evaluated as a list.
string(REPLACE "\\" "/" ament_index_build_path "${ament_index_build_path}")
endif()
if(NOT "${_typesupport_impls} " STREQUAL " ")
ament_add_nose_test(rclpytests test
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
APPEND_ENV AMENT_PREFIX_PATH=${ament_index_build_path}
)
endif()
endif()
Expand Down
10 changes: 3 additions & 7 deletions rclpy/rclpy/impl/rmw_implementation_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@
__selected_rmw_implementation = None
__rmw_implementation_module = None

AMENT_INDEX_NAME = 'rmw_python_extension'


def reload_rmw_implementations():
"""(Re)Load the available rmw implementations by inspecting the ament index."""
global __rmw_implementations
__rmw_implementations = sorted(ament_index_python.get_resources('rmw_implementation').keys())

# Remove implementations that are being filtered for in the rclpy CMakeLists so
# that they cannot be selected
__rmw_implementations = [
rmw_impl for rmw_impl in __rmw_implementations
if rmw_impl not in ['rmw_connext_dynamic_cpp', 'rmw_fastrtps_cpp']]
__rmw_implementations = sorted(ament_index_python.get_resources(AMENT_INDEX_NAME).keys())
return __rmw_implementations


Expand Down
26 changes: 2 additions & 24 deletions rclpy/test/test_select_rmw_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,7 @@ def func_import_each_available_rmw_implementation(rmw_implementation):
assert(rmw_implementation in rmw_implementations)

select_rmw_implementation(rmw_implementation)
try:
rclpy.init([])
except ImportError as exc:
if "No module named 'rclpy._rclpy__" in '{0}'.format(exc):
# Not all rmw implementations generate a Python implementation.
# TODO(wjwwood): prune get_rmw_implementations by
# implementations that have generated a Python implementation
# (probably use a separate ament index entry).
print("Failed to import rmw implementation '{0}', ignoring."
.format(rmw_implementation), file=sys.stderr)
return ctypes.c_bool(True)
raise
rclpy.init([])

set_rmw = rclpy.get_rmw_implementation_identifier()

Expand Down Expand Up @@ -93,18 +82,7 @@ def func_select_rmw_implementation_by_environment(rmw_implementation):
rmw_implementations = get_rmw_implementations()
assert(os.environ['RCLPY_IMPLEMENTATION'] in rmw_implementations)

try:
rclpy.init([])
except ImportError as exc:
if "No module named 'rclpy._rclpy__" in '{0}'.format(exc):
# Not all rmw implementations generate a Python implementation.
# TODO(wjwwood): prune get_rmw_implementations by
# implementations that have generated a Python implementation
# (probably use a separate ament index entry).
return ctypes.c_bool(True)
print("Failed to import rmw implementation '{0}', ignoring."
.format(rmw_implementation), file=sys.stderr)
raise
rclpy.init([])

set_rmw = rclpy.get_rmw_implementation_identifier()

Expand Down

0 comments on commit 0bf9640

Please sign in to comment.