Esempio n. 1
0
def _import(name):
    try:
        # Since Python 3.8, on Windows we should ensure DLL directories are explicitly added
        # to the search path.
        # See https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
        with add_dll_directories_from_env('PATH'):
            return importlib.import_module(name, package='rclpy')
    except ImportError as e:
        if e.path is None:
            import sysconfig
            expected_path = Path(__file__).parents[1] / (
                name[1:] + sysconfig.get_config_var('EXT_SUFFIX'))
            assert not expected_path.is_file()
            e.msg += \
                f"\nThe C extension '{expected_path}' isn't present on the " \
                "system. Please refer to 'https://index.ros.org/doc/ros2/" \
                'Troubleshooting/Installation-Troubleshooting/#import-' \
                "failing-without-library-present-on-the-system' for " \
                'possible solutions'
        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://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/'
                         '#import-failing-even-with-library-present-on-the-system')
        raise
Esempio n. 2
0
def test_add_dll_direcotires_from_env(monkeypatch, tmp_path):
    # Test with empty value
    monkeypatch.delenv('TEST_ENV', raising=False)
    with add_dll_directories_from_env('TEST_ENV'):
        pass

    # Test with one path
    monkeypatch.setenv('TEST_ENV', tmp_path.name)
    with add_dll_directories_from_env('TEST_ENV'):
        pass

    # Test with multiple paths
    dir1 = tmp_path / 'subdir1'
    dir2 = tmp_path / 'subdir2'
    dir1.mkdir()
    dir2.mkdir()
    monkeypatch.setenv('TEST_ENV', f'{dir1.name};{dir2.name}')
    with add_dll_directories_from_env('TEST_ENV'):
        pass
Esempio n. 3
0
def _import(name):
    try:
        # Since Python 3.8, on Windows we should ensure DLL directories are explicitly added
        # to the search path.
        # See https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
        with add_dll_directories_from_env('PATH'):
            return importlib.import_module(name, package='rosbag2_transport')
    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://index.ros.org/doc/ros2/Troubleshooting/'
                         '#import-failing-even-with-library-present-on-the-system')
        raise
Esempio n. 4
0
def import_type_support(pkg_name):
    """
    Import the rosidl_typesupport_c module of a package.

    The module will provide the C typesupport for the rosidl files in the
    specified package, such that the ROS message structures in the package can
    be converted to and from message structures used by the rmw implementation.

    :param pkg_name str: name of the package
    :returns: the typesupport Python module for the specified package
    """
    module_name = '.{}_s__rosidl_typesupport_c'.format(pkg_name)
    try:
        # Since Python 3.8, on Windows we should ensure DLL directories are explicitly added
        # to the search path.
        # See https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
        with add_dll_directories_from_env('PATH'):
            return importlib.import_module(module_name, package=pkg_name)
    except ImportError:
        raise UnsupportedTypeSupport(pkg_name)
Esempio n. 5
0
def import_c_library(name: str, package: Optional[str] = None):
    """
    Import and return a C extension library using importlib, with consistent error messaging.

    See importlib.import_module documentation for details on the parameters and return type.

    :param name
    :param package
    :return The loaded module
    :raises ImportError
    """
    try:
        # Since Python 3.8, on Windows we should ensure DLL directories are
        # explicitly added to the search path.
        # See https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
        with add_dll_directories_from_env('PATH'):
            return importlib.import_module(name, package=package)
    except ImportError as e:
        if e.path is None:
            import sysconfig
            expected_path = Path(__file__).parents[1] / (
                name[1:] + sysconfig.get_config_var('EXT_SUFFIX'))
            assert not expected_path.is_file()
            e.msg += \
                f"\nThe C extension '{expected_path}' isn't present on the " \
                "system. Please refer to 'https://index.ros.org/doc/ros2/" \
                'Troubleshooting/Installation-Troubleshooting/#import-' \
                "failing-without-library-present-on-the-system' for " \
                'possible solutions'
        if e.path is not None and os.path.isfile(e.path):
            e.msg += \
                f"\nThe C extension '{e.path}' failed to be imported while " \
                "being present on the system. Please refer to 'https://" \
                'index.ros.org/doc/ros2/Troubleshooting/Installation-' \
                'Troubleshooting/#import-failing-even-with-library-present-' \
                "on-the-system' for possible solutions"
        raise
Esempio n. 6
0
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import unittest

from geometry_msgs.msg import TransformStamped
import rclpy
from rpyutils import add_dll_directories_from_env

# Since Python 3.8, on Windows we should ensure DLL directories are explicitly added
# to the search path.
# See https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
with add_dll_directories_from_env('PATH'):
    from test_tf2_py._tf2_py import BufferCore
    from test_tf2_py._tf2_py import LookupException


def build_transform(target_frame, source_frame, stamp):
    transform = TransformStamped()
    transform.header.frame_id = target_frame
    transform.child_frame_id = source_frame
    transform.header.stamp = stamp
    transform.transform.translation.x = 2.0
    transform.transform.translation.y = 0.0
    transform.transform.translation.z = 0.0
    transform.transform.rotation.w = 1.0
    transform.transform.rotation.x = 0.0
    transform.transform.rotation.y = 0.0
Esempio n. 7
0
def _custom_import(name):
    # Since Python 3.8, on Windows we should ensure DLL directories are explicitly added
    # to the search path.
    # See https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew
    with add_dll_directories_from_env('PATH'):
        return importlib.import_module(name, package='test_rclpy')