From b40df3a6b8819266e4644928c07a719fdf279020 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel <guilhem.saurel@laas.fr> Date: Thu, 30 Jul 2020 16:47:48 +0200 Subject: [PATCH] [Python] add more paths to getModelPath, fix #37 and document their purpose --- python/example_robot_data/path.py.in | 1 + python/example_robot_data/robots_loader.py | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/python/example_robot_data/path.py.in b/python/example_robot_data/path.py.in index c1b0976..efb9ccb 100644 --- a/python/example_robot_data/path.py.in +++ b/python/example_robot_data/path.py.in @@ -1 +1,2 @@ EXAMPLE_ROBOT_DATA_MODEL_DIR = "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/robots" +EXAMPLE_ROBOT_DATA_SOURCE_DIR = "${PROJECT_SOURCE_DIR}/robots" diff --git a/python/example_robot_data/robots_loader.py b/python/example_robot_data/robots_loader.py index 1df545a..b0efd60 100644 --- a/python/example_robot_data/robots_loader.py +++ b/python/example_robot_data/robots_loader.py @@ -3,7 +3,6 @@ import warnings from os.path import dirname, exists, join import numpy as np - import pinocchio as pin from pinocchio.robot_wrapper import RobotWrapper @@ -11,13 +10,16 @@ pin.switchToNumpyArray() def getModelPath(subpath, printmsg=False): + source = dirname(dirname(dirname(__file__))) # top level source directory paths = [ - join(dirname(dirname(dirname(dirname(__file__)))), 'robots'), - join(dirname(dirname(dirname(__file__))), 'robots') + join(dirname(dirname(dirname(source))), 'robots'), # function called from "make release" in build/ dir + join(dirname(source), 'robots'), # function called from a build/ dir inside top level source + join(source, 'robots') # function called from top level source dir ] try: - from .path import EXAMPLE_ROBOT_DATA_MODEL_DIR - paths.append(EXAMPLE_ROBOT_DATA_MODEL_DIR) + from .path import EXAMPLE_ROBOT_DATA_MODEL_DIR, EXAMPLE_ROBOT_DATA_SOURCE_DIR + paths.append(EXAMPLE_ROBOT_DATA_MODEL_DIR) # function called from installed project + paths.append(EXAMPLE_ROBOT_DATA_SOURCE_DIR) # function called from off-tree build dir except ImportError: pass paths += [join(p, '../../../share/example-robot-data/robots') for p in sys.path] -- GitLab