From 09936ad5ef3fb5d7794c9ecc62aa3bfc81ec16a8 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 15:31:56 +0100 Subject: [PATCH 01/11] cmake: Add pinocchio_python_parser target --- CMakeLists.txt | 14 ++------------ sources.cmake | 9 +++------ src/CMakeLists.txt | 16 ++++++++++++++++ unittest/CMakeLists.txt | 15 ++++++++++----- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 093dd617ce..40100fe719 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,9 +134,8 @@ cmake_dependent_option( BUILD_PYTHON_BINDINGS_WITH_BOOST_MPFR_SUPPORT "Build the Python interface with Boost.Multiprecision MPFR support" OFF BUILD_PYTHON_INTERFACE OFF) -cmake_dependent_option( - BUILD_WITH_LIBPYTHON "Link to libpython to embed an interpreter for the python_parser feature" ON - "BUILD_PYTHON_INTERFACE" OFF) +cmake_dependent_option(BUILD_WITH_LIBPYTHON "Build the library with Python format support" ON + "BUILD_PYTHON_INTERFACE" OFF) if(APPLE) option(BUILD_WITH_ACCELERATE_SUPPORT "Build Pinocchio with the Accelerate support" OFF) else(APPLE) @@ -364,15 +363,6 @@ if(BUILD_WITH_EXTRA_SUPPORT) ${${PROJECT_NAME}_BINDINGS_PYTHON_EXTRA_SOURCES}) endif() -# LibPython sources -if(BUILD_WITH_LIBPYTHON) - list(APPEND ${PROJECT_NAME}_CORE_PUBLIC_HEADERS ${${PROJECT_NAME}_LIBPYTHON_PUBLIC_HEADERS}) - list(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES - ${${PROJECT_NAME}_BINDINGS_PYTHON_LIBPYTHON_SOURCES}) - list(APPEND ${PROJECT_NAME}_BINDINGS_PYTHON_PUBLIC_HEADERS - ${${PROJECT_NAME}_BINDINGS_PYTHON_LIBPYTHON_PUBLIC_HEADERS}) -endif(BUILD_WITH_LIBPYTHON) - # HPP-FCL sources if(BUILD_WITH_HPP_FCL_SUPPORT) if(ENABLE_TEMPLATE_INSTANTIATION) diff --git a/sources.cmake b/sources.cmake index d3717bc865..3ee1b87bf3 100644 --- a/sources.cmake +++ b/sources.cmake @@ -369,6 +369,9 @@ set(${PROJECT_NAME}_SDF_PUBLIC_HEADERS set(${PROJECT_NAME}_LIBPYTHON_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/include/pinocchio/parsers/python.hpp) +set(${PROJECT_NAME}_LIBPYTHON_SOURCES + ${PROJECT_SOURCE_DIR}/bindings/python/parsers/python/model.cpp) + set(${PROJECT_NAME}_EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/extra/reachable-workspace.cpp) set(${PROJECT_NAME}_EXTRA_PUBLIC_HEADERS @@ -594,12 +597,6 @@ set(${PROJECT_NAME}_BINDINGS_PYTHON_SOURCES ${PROJECT_SOURCE_DIR}/bindings/python/parsers/mjcf/geometry.cpp ${PROJECT_SOURCE_DIR}/bindings/python/extra/expose-extras.cpp) -set(${PROJECT_NAME}_BINDINGS_PYTHON_LIBPYTHON_SOURCES - ${PROJECT_SOURCE_DIR}/bindings/python/parsers/python/model.cpp) - -set(${PROJECT_NAME}_BINDINGS_PYTHON_LIBPYTHON_PUBLIC_HEADERS - ${PROJECT_SOURCE_DIR}/include/pinocchio/bindings/python/parsers/python.hpp) - set(${PROJECT_NAME}_BINDINGS_PYTHON_HPP_FCL_SOURCES ${PROJECT_SOURCE_DIR}/bindings/python/collision/expose-broadphase.cpp ${PROJECT_SOURCE_DIR}/bindings/python/collision/expose-broadphase-callbacks.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aeb1902cdd..af98e04cf1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -325,6 +325,22 @@ if(BUILD_WITH_CASADI_SUPPORT) target_link_libraries(${PROJECT_NAME}_casadi ${CASADI_SCOPE} casadi) endif() +if(BUILD_WITH_LIBPYTHON) + set(LIBPYTHON_LIB_NAME "${PROJECT_NAME}_python_parser") + + pinocchio_target( + ${LIBPYTHON_LIB_NAME} + SCALAR default + SOURCES ${${PROJECT_NAME}_LIBPYTHON_SOURCES} ${${PROJECT_NAME}_LIBPYTHON_PUBLIC_HEADERS}) + pinocchio_config(python_parser ${LIBPYTHON_LIB_NAME}) + + target_link_libraries(${LIBPYTHON_LIB_NAME} PUBLIC ${PROJECT_NAME}_default Python3::Python) + target_link_boost_python(${LIBPYTHON_LIB_NAME} PUBLIC) + if(WIN32) + target_link_libraries(${PYTHON_LIB_NAME} PUBLIC ${PYTHON_LIBRARY}) + endif() +endif() + # Define main target (default, parsers, extra). add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 7afdc1ebf2..a32eff1019 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -38,6 +38,7 @@ function(ADD_PINOCCHIO_UNIT_TEST name) EXTRA COLLISION PARALLEL + PYTHON_PARSER PARSERS_OPTIONAL EXTRA_OPTIONAL COLLISION_OPTIONAL @@ -93,6 +94,10 @@ function(ADD_PINOCCHIO_UNIT_TEST name) target_link_libraries(${TEST_NAME} PUBLIC ${PROJECT_NAME}_extra) endif() + if(unit_test_PYTHON_PARSER) + target_link_libraries(${TEST_NAME} PUBLIC ${PROJECT_NAME}_python_parser) + endif() + modernize_target_link_libraries( ${TEST_NAME} SCOPE PRIVATE @@ -223,23 +228,23 @@ if(BUILD_WITH_EXTRA_SUPPORT) endif() if(BUILD_WITH_LIBPYTHON) - add_pinocchio_unit_test(python_parser PACKAGES Python3::Python) + add_pinocchio_unit_test(python_parser PYTHON_PARSER) get_cpp_test_name(python_parser ${CMAKE_CURRENT_SOURCE_DIR} python_parser_target) - target_include_directories(${python_parser_target} SYSTEM PUBLIC ${PYTHON_INCLUDE_DIRS}) - target_link_libraries(${python_parser_target} PUBLIC ${PYWRAP}_default) - target_link_libraries(${python_parser_target} PUBLIC ${PYTHON_LIBRARIES}) get_test_property(${python_parser_target} ENVIRONMENT ENV_VARIABLES) compute_pythonpath(PYTHON_ENV_VARIABLES "bindings/python") list(APPEND ENV_VARIABLES ${PYTHON_ENV_VARIABLES}) if(WIN32) - # This line is mandatory because of Github action. The test run well on Windowns + Conda. This + # This line is mandatory because of Github action. The test run well on Windows + Conda. This # hide something wrong. Maybe the test is linking against the wrong Python library or call the # wrong interpreter. get_filename_component(_PYTHONHOME ${PYTHON_EXECUTABLE} PATH) list(APPEND ENV_VARIABLES "PYTHONHOME=${_PYTHONHOME}") endif() set_tests_properties(${python_parser_target} PROPERTIES ENVIRONMENT "${ENV_VARIABLES}") +endif() + +if(BUILD_PYTHON_INTERFACE) add_subdirectory(python) endif() From cd07d8b847e857f78fe599f7a281ef48754cd7f6 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 15:33:26 +0100 Subject: [PATCH 02/11] python_parser: Try to remove some old code --- bindings/python/parsers/python/model.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/bindings/python/parsers/python/model.cpp b/bindings/python/parsers/python/model.cpp index be0ddc82fe..ee896968d7 100644 --- a/bindings/python/parsers/python/model.cpp +++ b/bindings/python/parsers/python/model.cpp @@ -4,8 +4,6 @@ #include "pinocchio/bindings/python/parsers/python.hpp" -#include -#include #include #include @@ -28,11 +26,6 @@ namespace pinocchio // Get a dict for the global namespace to exec further python code with bp::dict globals = bp::extract(main_module.attr("__dict__")); - // We need to link to the pinocchio PyWrap. We delegate the dynamic loading to the python - // interpreter. - bp::object cpp_module( - (bp::handle<>(bp::borrowed(PyImport_AddModule("libpinocchio_pywrap"))))); - // That's it, you can exec your python script, starting with a model you // can update as you want. try @@ -67,10 +60,6 @@ namespace pinocchio // close the interpreter // cf. https://github.com/numpy/numpy/issues/8097 -#if PY_MAJOR_VERSION < 3 - Py_Finalize(); -#else - PyObject * poMainModule = PyImport_AddModule("__main__"); PyObject * poAttrList = PyObject_Dir(poMainModule); PyObject * poAttrIter = PyObject_GetIter(poAttrList); @@ -94,8 +83,6 @@ namespace pinocchio } Py_DecRef(poAttrIter); Py_DecRef(poAttrList); -#endif - return model; } } // namespace python From 609cdd938b718b38b26860c6531e876a611a30eb Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 15:39:14 +0100 Subject: [PATCH 03/11] =?UTF-8?q?cmake:=C2=A0Rename=20BUILD=5FWITH=5FLIBPY?= =?UTF-8?q?THON=20into=20BUILD=5FWITH=5FPYTHON=5FPARSER=5FSUPPORT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 5 ++++- sources.cmake | 4 ++-- src/CMakeLists.txt | 15 ++++++++------- unittest/CMakeLists.txt | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40100fe719..7f3be1c133 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -163,6 +163,9 @@ endif() if(BUILD_WITH_AUTODIFF_SUPPORT) set(BUILD_WITH_CPPAD_SUPPORT TRUE) endif() +if(BUILD_WITH_LIBPYTHON) + set(BUILD_WITH_PYTHON_PARSER_SUPPORT TRUE) +endif() if(BUILD_WITH_EXTRA_SUPPORT) list(APPEND CFLAGS_OPTIONS "-DPINOCCHIO_WITH_EXTRA_SUPPORT") @@ -300,7 +303,7 @@ if(BUILD_PYTHON_INTERFACE) message(STATUS "Python compiler: ${_python_implementation_value}") if(_python_implementation_value MATCHES "PyPy") - set(BUILD_WITH_LIBPYTHON OFF) + set(BUILD_WITH_PYTHON_PARSER_SUPPORT OFF) message( STATUS "PyPy detected, therefore libpython is not available and BUILD_WITH_LIBPYTHON set to OFF.") diff --git a/sources.cmake b/sources.cmake index 3ee1b87bf3..acb07d3b5d 100644 --- a/sources.cmake +++ b/sources.cmake @@ -366,10 +366,10 @@ set(${PROJECT_NAME}_SDF_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/include/pinocchio/parsers/sdf/model.hxx ${PROJECT_SOURCE_DIR}/include/pinocchio/parsers/sdf/geometry.hxx) -set(${PROJECT_NAME}_LIBPYTHON_PUBLIC_HEADERS +set(${PROJECT_NAME}_PYTHON_PARSER_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/include/pinocchio/parsers/python.hpp) -set(${PROJECT_NAME}_LIBPYTHON_SOURCES +set(${PROJECT_NAME}_PYTHON_PARSER_SOURCES ${PROJECT_SOURCE_DIR}/bindings/python/parsers/python/model.cpp) set(${PROJECT_NAME}_EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/extra/reachable-workspace.cpp) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index af98e04cf1..6e8ab226a9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -325,17 +325,18 @@ if(BUILD_WITH_CASADI_SUPPORT) target_link_libraries(${PROJECT_NAME}_casadi ${CASADI_SCOPE} casadi) endif() -if(BUILD_WITH_LIBPYTHON) - set(LIBPYTHON_LIB_NAME "${PROJECT_NAME}_python_parser") +if(BUILD_WITH_PYTHON_PARSER_SUPPORT) + set(PYTHON_PARSER_LIB_NAME "${PROJECT_NAME}_python_parser") pinocchio_target( - ${LIBPYTHON_LIB_NAME} + ${PYTHON_PARSER_LIB_NAME} SCALAR default - SOURCES ${${PROJECT_NAME}_LIBPYTHON_SOURCES} ${${PROJECT_NAME}_LIBPYTHON_PUBLIC_HEADERS}) - pinocchio_config(python_parser ${LIBPYTHON_LIB_NAME}) + SOURCES ${${PROJECT_NAME}_PYTHON_PARSER_SOURCES} + ${${PROJECT_NAME}_PYTHON_PARSER_PUBLIC_HEADERS}) + pinocchio_config(python_parser ${PYTHON_PARSER_LIB_NAME}) - target_link_libraries(${LIBPYTHON_LIB_NAME} PUBLIC ${PROJECT_NAME}_default Python3::Python) - target_link_boost_python(${LIBPYTHON_LIB_NAME} PUBLIC) + target_link_libraries(${PYTHON_PARSER_LIB_NAME} PUBLIC ${PROJECT_NAME}_default Python3::Python) + target_link_boost_python(${PYTHON_PARSER_LIB_NAME} PUBLIC) if(WIN32) target_link_libraries(${PYTHON_LIB_NAME} PUBLIC ${PYTHON_LIBRARY}) endif() diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index a32eff1019..81a46a6328 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -227,7 +227,7 @@ if(BUILD_WITH_EXTRA_SUPPORT) COLLISION_OPTIONAL) endif() -if(BUILD_WITH_LIBPYTHON) +if(BUILD_WITH_PYTHON_PARSER_SUPPORT) add_pinocchio_unit_test(python_parser PYTHON_PARSER) get_cpp_test_name(python_parser ${CMAKE_CURRENT_SOURCE_DIR} python_parser_target) From 88334fdb1d1010c83c348aa6a5dd8808fbf6e0a4 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 15:39:26 +0100 Subject: [PATCH 04/11] changelog: Add entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4abb823e63..f0432f8c7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Added +- Add `pinocchio_python_parser` target ([#2475](https://github.com/stack-of-tasks/pinocchio/pull/2475)) + ## [3.3.0] - 2024-11-06 ### Added From 60a1e6f7e922c09689661317823cec261833f331 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 16:20:39 +0100 Subject: [PATCH 05/11] cmake: Remove useless win specific code --- src/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e8ab226a9..a46a56eb2d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -337,9 +337,6 @@ if(BUILD_WITH_PYTHON_PARSER_SUPPORT) target_link_libraries(${PYTHON_PARSER_LIB_NAME} PUBLIC ${PROJECT_NAME}_default Python3::Python) target_link_boost_python(${PYTHON_PARSER_LIB_NAME} PUBLIC) - if(WIN32) - target_link_libraries(${PYTHON_LIB_NAME} PUBLIC ${PYTHON_LIBRARY}) - endif() endif() # Define main target (default, parsers, extra). From 20c889b4b665d9e915fc3dea1913fdca1b7ddd84 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 16:20:57 +0100 Subject: [PATCH 06/11] cmake: Explicitly search for boost_python --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f3be1c133..8441d6f4cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,6 +264,10 @@ set(BOOST_REQUIRED_COMPONENTS filesystem serialization system) set_boost_default_options() export_boost_default_options() add_project_dependency(Boost REQUIRED COMPONENTS ${BOOST_REQUIRED_COMPONENTS}) +# Search explicitly for boost_python when building python_parser +if(BUILD_WITH_PYTHON_PARSER_SUPPORT) + search_for_boost_python(REQUIRED) +endif() if(Boost_VERSION_STRING VERSION_LESS 1.81) if(BUILD_WITH_URDF_SUPPORT AND "${urdfdom_VERSION}" VERSION_GREATER "0.4.2") From 22fb10de05bddb683a91cb75626e4e3a5920a3c5 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 16:29:06 +0100 Subject: [PATCH 07/11] cmake: Export some flags to other projects --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8441d6f4cb..fdaf43d4d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -496,6 +496,10 @@ if(BUILD_WITH_EXTRA_SUPPORT) export_variable(PINOCCHIO_USE_EXTRA ON) set(PACKAGE_EXTRA_MACROS "${PACKAGE_EXTRA_MACROS}\nset(PINOCCHIO_USE_EXTRA \"\")") endif() +if(BUILD_WITH_PYTHON_PARSER_SUPPORT) + export_variable(PINOCCHIO_USE_PYTHON_PARSER ON) + set(PACKAGE_EXTRA_MACROS "${PACKAGE_EXTRA_MACROS}\nset(PINOCCHIO_USE_PYTHON_PARSER \"\")") +endif() export_variable(pinocchio_VERSION ${pinocchio_VERSION}) # Setup pkg-configs flags and libs From cfe610db5a056236a50f260c944fdc4ac19f493c Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 16:44:29 +0100 Subject: [PATCH 08/11] Revert "cmake: Explicitly search for boost_python" This reverts commit 20c889b4b665d9e915fc3dea1913fdca1b7ddd84. --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdaf43d4d8..1f06e3f8d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,10 +264,6 @@ set(BOOST_REQUIRED_COMPONENTS filesystem serialization system) set_boost_default_options() export_boost_default_options() add_project_dependency(Boost REQUIRED COMPONENTS ${BOOST_REQUIRED_COMPONENTS}) -# Search explicitly for boost_python when building python_parser -if(BUILD_WITH_PYTHON_PARSER_SUPPORT) - search_for_boost_python(REQUIRED) -endif() if(Boost_VERSION_STRING VERSION_LESS 1.81) if(BUILD_WITH_URDF_SUPPORT AND "${urdfdom_VERSION}" VERSION_GREATER "0.4.2") From 750bd0e067e4aa5e33ae80aeb86554413462101e Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 16:59:21 +0100 Subject: [PATCH 09/11] core: Move sources from bindings to core part --- .../bindings/python/parsers/python.hpp | 37 +++---------------- include/pinocchio/parsers/python.hpp | 24 +++++++++++- sources.cmake | 2 +- .../python => src}/parsers/python/model.cpp | 4 +- unittest/python_parser.cpp | 2 +- 5 files changed, 33 insertions(+), 36 deletions(-) rename {bindings/python => src}/parsers/python/model.cpp (97%) diff --git a/include/pinocchio/bindings/python/parsers/python.hpp b/include/pinocchio/bindings/python/parsers/python.hpp index 394b2c5bb4..f0571388ab 100644 --- a/include/pinocchio/bindings/python/parsers/python.hpp +++ b/include/pinocchio/bindings/python/parsers/python.hpp @@ -5,39 +5,12 @@ #ifndef __pinocchio_python_parser_python_hpp__ #define __pinocchio_python_parser_python_hpp__ -#include "pinocchio/multibody/model.hpp" +#include "pinocchio/macros.hpp" -#include +// clang-format off +PINOCCHIO_PRAGMA_DEPRECATED_HEADER(pinocchio/bindings/python/parsers/python.hpp, pinocchio/parsers/python.hpp) +// clang-format on -#if defined _WIN32 - #ifdef pinocchio_pywrap_EXPORTS - #define PINOCCHIO_PYWRAP_DLLAPI __declspec(dllexport) - #else - #define PINOCCHIO_PYWRAP_DLLAPI __declspec(dllimport) - #endif // pinocchio_pywrap_EXPORTS -#else - #define PINOCCHIO_PYWRAP_DLLAPI -#endif // _WIN32 - -namespace pinocchio -{ - namespace python - { - /// \brief Load a model from a Python script. - /// - /// This function raises a Python error in case of incistency in the Python code. - /// - /// \input filename The full path to the model file. - /// \input var_name Name of the Python variable which contains the model in the script. - /// - /// \returns The model constructed by the Python script. - /// - // TODO: look inside the context of Python and find an occurence of object Model - PINOCCHIO_PYWRAP_DLLAPI - Model buildModel(const std::string & filename, const std::string & var_name = "model"); - - } // namespace python - -} // namespace pinocchio +#include "pinocchio/parsers/python.hpp" #endif // ifndef __pinocchio_python_parser_python_hpp__ diff --git a/include/pinocchio/parsers/python.hpp b/include/pinocchio/parsers/python.hpp index 6acc9ddfdb..c3ee294a61 100644 --- a/include/pinocchio/parsers/python.hpp +++ b/include/pinocchio/parsers/python.hpp @@ -5,6 +5,28 @@ #ifndef __pinocchio_parser_python_hpp__ #define __pinocchio_parser_python_hpp__ -#include "pinocchio/bindings/python/parsers/python.hpp" +#include "pinocchio/python_parser/config.hpp" +#include "pinocchio/multibody/model.hpp" + +namespace pinocchio +{ + namespace python + { + /// \brief Load a model from a Python script. + /// + /// This function raises a Python error in case of inconsistency in the Python code. + /// + /// \input filename The full path to the model file. + /// \input var_name Name of the Python variable which contains the model in the script. + /// + /// \returns The model constructed by the Python script. + /// + // TODO: look inside the context of Python and find an occurence of object Model + PINOCCHIO_PYTHON_PARSER_DLLAPI + Model buildModel(const std::string & filename, const std::string & var_name = "model"); + + } // namespace python + +} // namespace pinocchio #endif // ifndef __pinocchio_parser_python_hpp__ diff --git a/sources.cmake b/sources.cmake index acb07d3b5d..ddbdb3290f 100644 --- a/sources.cmake +++ b/sources.cmake @@ -370,7 +370,7 @@ set(${PROJECT_NAME}_PYTHON_PARSER_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/include/pinocchio/parsers/python.hpp) set(${PROJECT_NAME}_PYTHON_PARSER_SOURCES - ${PROJECT_SOURCE_DIR}/bindings/python/parsers/python/model.cpp) + ${PROJECT_SOURCE_DIR}/src/parsers/python/model.cpp) set(${PROJECT_NAME}_EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/extra/reachable-workspace.cpp) diff --git a/bindings/python/parsers/python/model.cpp b/src/parsers/python/model.cpp similarity index 97% rename from bindings/python/parsers/python/model.cpp rename to src/parsers/python/model.cpp index ee896968d7..dc7bd914ad 100644 --- a/bindings/python/parsers/python/model.cpp +++ b/src/parsers/python/model.cpp @@ -2,11 +2,13 @@ // Copyright (c) 2016-2023 CNRS INRIA // -#include "pinocchio/bindings/python/parsers/python.hpp" +#include "pinocchio/parsers/python.hpp" #include #include +#include + // Boost 1.58 #if BOOST_VERSION / 100 % 1000 == 58 #include diff --git a/unittest/python_parser.cpp b/unittest/python_parser.cpp index d1600694d1..d3ae94c2bf 100644 --- a/unittest/python_parser.cpp +++ b/unittest/python_parser.cpp @@ -6,7 +6,7 @@ #include "pinocchio/multibody/model.hpp" #include "pinocchio/multibody/data.hpp" -#include "pinocchio/bindings/python/parsers/python.hpp" +#include "pinocchio/parsers/python.hpp" #include From 6b275d80173523e35a78242568459a80c230d68a Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 17:05:11 +0100 Subject: [PATCH 10/11] pre-commit: lint cmake --- sources.cmake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sources.cmake b/sources.cmake index ddbdb3290f..f8cd400628 100644 --- a/sources.cmake +++ b/sources.cmake @@ -369,8 +369,7 @@ set(${PROJECT_NAME}_SDF_PUBLIC_HEADERS set(${PROJECT_NAME}_PYTHON_PARSER_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/include/pinocchio/parsers/python.hpp) -set(${PROJECT_NAME}_PYTHON_PARSER_SOURCES - ${PROJECT_SOURCE_DIR}/src/parsers/python/model.cpp) +set(${PROJECT_NAME}_PYTHON_PARSER_SOURCES ${PROJECT_SOURCE_DIR}/src/parsers/python/model.cpp) set(${PROJECT_NAME}_EXTRA_SOURCES ${PROJECT_SOURCE_DIR}/src/extra/reachable-workspace.cpp) From 0d81fe22257da838ef2fa5c6f69c97b14e719308 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Fri, 8 Nov 2024 22:37:10 +0100 Subject: [PATCH 11/11] cmake: Factorize python_parser test setup and add windows dll path --- unittest/CMakeLists.txt | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index 81a46a6328..5518dc1b48 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -96,6 +96,18 @@ function(ADD_PINOCCHIO_UNIT_TEST name) if(unit_test_PYTHON_PARSER) target_link_libraries(${TEST_NAME} PUBLIC ${PROJECT_NAME}_python_parser) + add_windows_dll_path_to_test(${TEST_NAME}) + get_test_property(${TEST_NAME} ENVIRONMENT ENV_VARIABLES) + compute_pythonpath(PYTHON_ENV_VARIABLES "bindings/python") + list(APPEND ENV_VARIABLES ${PYTHON_ENV_VARIABLES}) + if(WIN32) + # This line is mandatory because of Github action. The test run well on Windows + Conda. This + # hide something wrong. Maybe the test is linking against the wrong Python library or call the + # wrong interpreter. + get_filename_component(_PYTHONHOME ${PYTHON_EXECUTABLE} PATH) + list(APPEND ENV_VARIABLES "PYTHONHOME=${_PYTHONHOME}") + endif() + set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${ENV_VARIABLES}") endif() modernize_target_link_libraries( @@ -229,19 +241,6 @@ endif() if(BUILD_WITH_PYTHON_PARSER_SUPPORT) add_pinocchio_unit_test(python_parser PYTHON_PARSER) - get_cpp_test_name(python_parser ${CMAKE_CURRENT_SOURCE_DIR} python_parser_target) - - get_test_property(${python_parser_target} ENVIRONMENT ENV_VARIABLES) - compute_pythonpath(PYTHON_ENV_VARIABLES "bindings/python") - list(APPEND ENV_VARIABLES ${PYTHON_ENV_VARIABLES}) - if(WIN32) - # This line is mandatory because of Github action. The test run well on Windows + Conda. This - # hide something wrong. Maybe the test is linking against the wrong Python library or call the - # wrong interpreter. - get_filename_component(_PYTHONHOME ${PYTHON_EXECUTABLE} PATH) - list(APPEND ENV_VARIABLES "PYTHONHOME=${_PYTHONHOME}") - endif() - set_tests_properties(${python_parser_target} PROPERTIES ENVIRONMENT "${ENV_VARIABLES}") endif() if(BUILD_PYTHON_INTERFACE)