-
Notifications
You must be signed in to change notification settings - Fork 227
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
avoid custom working directory #147
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,19 +26,16 @@ if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug") | |
set(PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE_DEBUG}") | ||
endif() | ||
|
||
# enables using the Python package from the source space | ||
# This creates a folder in ${CMAKE_CURRENT_BINARY_DIR}/rclpy which has all the | ||
# as well as the compiled modules from the build space | ||
# necessary Python code and C Python extensions for running tests. | ||
configure_file("__init__.py.in" "rclpy/__init__.py" @ONLY) | ||
# enables using the Python extensions from the build space for testing | ||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_rclpy/__init__.py" "") | ||
|
||
ament_python_install_package(${PROJECT_NAME}) | ||
|
||
function(set_properties _targetname _build_type) | ||
set_target_properties(${_targetname} PROPERTIES | ||
PREFIX "" | ||
LIBRARY_OUTPUT_DIRECTORY${_build_type} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" | ||
RUNTIME_OUTPUT_DIRECTORY${_build_type} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" | ||
LIBRARY_OUTPUT_DIRECTORY${_build_type} "${CMAKE_CURRENT_BINARY_DIR}/test_${PROJECT_NAME}" | ||
RUNTIME_OUTPUT_DIRECTORY${_build_type} "${CMAKE_CURRENT_BINARY_DIR}/test_${PROJECT_NAME}" | ||
OUTPUT_NAME "_${_targetname}${PythonExtra_EXTENSION_SUFFIX}" | ||
SUFFIX "${PythonExtra_EXTENSION_EXTENSION}") | ||
endfunction() | ||
|
@@ -109,9 +106,9 @@ if(BUILD_TESTING) | |
endif() | ||
if(NOT _typesupport_impls STREQUAL "") | ||
ament_add_pytest_test(rclpytests test | ||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" | ||
PYTHON_EXECUTABLE "${PYTHON_EXECUTABLE}" | ||
APPEND_ENV AMENT_PREFIX_PATH=${ament_index_build_path} | ||
PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. weird indent ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
TIMEOUT 90 | ||
) | ||
endif() | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,25 +14,29 @@ | |
|
||
import sys | ||
|
||
from rclpy.executors import SingleThreadedExecutor as _SingleThreadedExecutor | ||
from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy | ||
from rclpy.node import Node | ||
from rclpy.utilities import get_rmw_implementation_identifier # noqa | ||
from rclpy.utilities import ok | ||
from rclpy.utilities import shutdown # noqa | ||
from rclpy.utilities import try_shutdown # noqa | ||
|
||
|
||
def init(*, args=None): | ||
return _rclpy.rclpy_init(args if args is not None else sys.argv) | ||
# imported locally to avoid loading extensions on module import | ||
from rclpy.impl.implementation_singleton import rclpy_implementation | ||
return rclpy_implementation.rclpy_init( | ||
args if args is not None else sys.argv) | ||
|
||
|
||
def create_node(node_name, *, namespace=None): | ||
# imported locally to avoid loading extensions on module import | ||
from rclpy.node import Node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is delaying the import a necessary change with the new approach, or an additional feature? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is necessary since the |
||
return Node(node_name, namespace=namespace) | ||
|
||
|
||
def spin_once(node, *, timeout_sec=None): | ||
executor = _SingleThreadedExecutor() | ||
# imported locally to avoid loading extensions on module import | ||
from rclpy.executors import SingleThreadedExecutor | ||
executor = SingleThreadedExecutor() | ||
try: | ||
executor.add_node(node) | ||
executor.spin_once(timeout_sec=timeout_sec) | ||
|
@@ -41,7 +45,9 @@ def spin_once(node, *, timeout_sec=None): | |
|
||
|
||
def spin(node): | ||
executor = _SingleThreadedExecutor() | ||
# imported locally to avoid loading extensions on module import | ||
from rclpy.executors import SingleThreadedExecutor | ||
executor = SingleThreadedExecutor() | ||
try: | ||
executor.add_node(node) | ||
while ok(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2016-2017 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import importlib | ||
import os | ||
|
||
|
||
def _import(name): | ||
try: | ||
return importlib.import_module(name, package='rclpy') | ||
except ImportError as e: | ||
if e.path is not None and os.path.isfile(e.path): | ||
e.msg += \ | ||
"\nThe C extension '%s' failed to be imported while being present on the system." \ | ||
" Please refer to '%s' for possible solutions" % \ | ||
(e.path, 'https://github.com/ros2/ros2/wiki/Rclpy-Import-error-hint') | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks a bit weird to me that if I build without build_testing all my rclpy libraries go to this
test_rclpy
folder. Then they'll be install at the right place at the end of the day so I guess it's fineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory can have any name except
rclpy
. I used thetest_
prefix since it is being used during testing. But any other name (which isn't likely to collide with other packages) would be fine.