diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index b608b482..730cfa3e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -27,12 +27,12 @@ jobs: brew install ccache ninja boost eigen pybind11 python3 -m pip install numpy - - name: Download SOFA nightly build + - name: Download SOFA v20.12.02 run: | curl --output sofa.zip -L \ - https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries-v20.12/lastSuccessfulBuild/CI_SCOPE=binaries_minimal/artifact/MacOS/*zip*/MacOS.zip + https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_SCOPE=binaries_minimal/309/artifact/MacOS/*zip*/MacOS.zip - - name: Install SOFA nightly build + - name: Install SOFA v20.12.02 run: | sudo unzip sofa.zip -d temp sudo unzip temp/MacOS/`ls temp/MacOS/` -d temp @@ -105,12 +105,12 @@ jobs: brew install boost python3 -m pip install numpy - - name: Download SOFA nightly build + - name: Download SOFA v20.12.02 run: | curl --output sofa.zip -L \ - https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries-v20.12/lastSuccessfulBuild/CI_SCOPE=binaries_minimal/artifact/MacOS/*zip*/MacOS.zip + https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_SCOPE=binaries_minimal/309/artifact/MacOS/*zip*/MacOS.zip - - name: Install SOFA nightly build + - name: Install SOFA v20.12.02 run: | sudo unzip sofa.zip -d temp sudo unzip temp/MacOS/`ls temp/MacOS/` -d temp diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index e158aaf9..da57197f 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -42,12 +42,12 @@ jobs: - name: Install pybind11 run: cd /tmp/pybind11 && sudo make install - - name: Download SOFA nightly build + - name: Download SOFA v20.12.02 run: | curl --output sofa.zip -L \ - https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries-v20.12/lastSuccessfulBuild/CI_SCOPE=binaries_minimal/artifact/Linux/*zip*/Linux.zip + https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_SCOPE=binaries_minimal/309/artifact/Linux/*zip*/Linux.zip - - name: Install SOFA nightly build + - name: Install SOFA v20.12.02 run: | sudo unzip sofa.zip -d temp sudo unzip temp/Linux/`ls temp/Linux/` -d temp @@ -120,12 +120,12 @@ jobs: sudo apt install -qq libboost-all-dev python3 -m pip install numpy - - name: Download SOFA nightly build + - name: Download SOFA v20.12.02 run: | curl --output sofa.zip -L \ - https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries-v20.12/lastSuccessfulBuild/CI_SCOPE=binaries_minimal/artifact/Linux/*zip*/Linux.zip + https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_SCOPE=binaries_minimal/309/artifact/Linux/*zip*/Linux.zip - - name: Install SOFA nightly build + - name: Install SOFA v20.12.02 run: | sudo unzip sofa.zip -d temp sudo unzip temp/Linux/`ls temp/Linux/` -d temp diff --git a/Plugin/src/SofaPython3/PythonEnvironment.cpp b/Plugin/src/SofaPython3/PythonEnvironment.cpp index 4959b7f5..2a0743e3 100644 --- a/Plugin/src/SofaPython3/PythonEnvironment.cpp +++ b/Plugin/src/SofaPython3/PythonEnvironment.cpp @@ -118,6 +118,8 @@ PythonEnvironmentData* PythonEnvironment::getStaticData() return m_staticdata; } +std::string PythonEnvironment::pluginLibraryPath = ""; + SOFAPYTHON3_API py::module PythonEnvironment::importFromFile(const std::string& module, const std::string& path, py::object* globals) { PythonEnvironment::gil lock; @@ -238,6 +240,17 @@ void PythonEnvironment::Init() // python modules are automatically reloaded at each scene loading //setAutomaticModuleReload( true ); + + // Initialize pluginLibraryPath by reading PluginManager's map + std::map& map = PluginManager::getInstance().getPluginMap(); + for( const auto& elem : map) + { + Plugin p = elem.second; + if ( p.getModuleName() == sofa_tostring(SOFA_TARGET) ) + { + pluginLibraryPath = elem.first; + } + } } void PythonEnvironment::executePython(std::function cb) @@ -332,7 +345,7 @@ void PythonEnvironment::addPythonModulePathsForPlugins(const std::string& plugin if(!added) { - msg_warning("PythonEnvironment") << "No python dir found in " << pluginsDirectory; + msg_info("SofaPython3") << "No python3 dir found in " << pluginsDirectory; } } @@ -352,7 +365,30 @@ void PythonEnvironment::addPythonModulePathsForPluginsByName(const std::string& return; } } - msg_warning("PythonEnvironment") << pluginName << " not found in PluginManager's map."; + msg_info("SofaPython3") << pluginName << " not found in PluginManager's map."; +} + +void PythonEnvironment::addPluginManagerCallback() +{ + PluginManager::getInstance().addOnPluginLoadedCallback(pluginLibraryPath, + [](const std::string& pluginLibraryPath, const Plugin& plugin) { + // WARNING: loaded plugin must be organized like plugin_name/lib/plugin_name.so + for ( auto path : sofa::helper::system::PluginRepository.getPaths() ) + { + std::string pluginRoot = FileSystem::cleanPath( path + "/" + plugin.getModuleName() ); + if ( FileSystem::exists(pluginRoot) && FileSystem::isDirectory(pluginRoot) ) + { + addPythonModulePathsForPlugins(pluginRoot); + return; + } + } + } + ); +} + +void PythonEnvironment::removePluginManagerCallback() +{ + PluginManager::getInstance().removeOnPluginLoadedCallback(pluginLibraryPath); } diff --git a/Plugin/src/SofaPython3/PythonEnvironment.h b/Plugin/src/SofaPython3/PythonEnvironment.h index f74e968f..aa12fba8 100644 --- a/Plugin/src/SofaPython3/PythonEnvironment.h +++ b/Plugin/src/SofaPython3/PythonEnvironment.h @@ -57,6 +57,11 @@ class SOFAPYTHON3_API PythonEnvironment const std::string& path, pybind11::object* globals = nullptr); + /// Add a new callback in PluginManager to auto-add future + /// loaded plugins to sys.path + static void addPluginManagerCallback(); + static void removePluginManagerCallback(); + /// Add a path to sys.path, the list of search path for Python modules. static void addPythonModulePath(const std::string& path); @@ -134,6 +139,7 @@ class SOFAPYTHON3_API PythonEnvironment private: static PythonEnvironmentData* getStaticData() ; + static std::string pluginLibraryPath; }; } // namespace sofapython3 diff --git a/Plugin/src/SofaPython3/initModule.cpp b/Plugin/src/SofaPython3/initModule.cpp index 63b9857b..4c2cd7af 100644 --- a/Plugin/src/SofaPython3/initModule.cpp +++ b/Plugin/src/SofaPython3/initModule.cpp @@ -52,6 +52,7 @@ void initExternalModule() PythonEnvironment::Init(); first = false; } + PythonEnvironment::addPluginManagerCallback(); } const char* getModuleName() diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index 4257e2a0..ab23b7a3 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -8,12 +8,16 @@ endif() # This will set rpaths relative to SP3 plugin library if(UNIX) set(CMAKE_INSTALL_RPATH + "$ORIGIN" + "$$ORIGIN" "$ORIGIN/../lib" "$$ORIGIN/../lib" ) if(APPLE) set(CMAKE_MACOSX_RPATH ON) list(APPEND CMAKE_INSTALL_RPATH + "@loader_path" + "@executable_path" "@loader_path/../lib" "@executable_path/../lib" ) diff --git a/bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp b/bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp index 16872c1d..78bc1a5a 100644 --- a/bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp +++ b/bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp @@ -22,6 +22,14 @@ #include #include +#include +#include +#include +using sofa::helper::system::FileSystem; + +#if SOFAGUI_HAVE_SOFAGUIQT +#include +#endif // SOFAGUI_HAVE_SOFAGUIQT #include "Binding_BaseGui.h" #include "Binding_GUIManager.h" @@ -55,6 +63,26 @@ PYBIND11_MODULE(Gui, m) { :members: )doc"; +#if SOFAGUI_HAVE_SOFAGUIQT + std::string sofaPrefixAbsolute = sofa::helper::Utils::getSofaPathPrefix(); + std::string inputFilepath = FileSystem::cleanPath(sofaPrefixAbsolute + "/bin/qt.conf"); + bool success = sofa::gui::qt::loadQtConfWithCustomPrefix(inputFilepath, sofaPrefixAbsolute); + if(success) + { + msg_info("Sofa.Gui") << "Loaded qt.conf from " << inputFilepath << " customized with Prefix = " << sofaPrefixAbsolute; + } + else + { + msg_warning("Sofa.Gui") << "Failed loading and/or customizing qt.conf from " << inputFilepath; + + std::cout << "qt_resource_data:" << std::endl; + for (int i = 0 ; i < qt_resource_data.size() ; ++i) { + std::cout << qt_resource_data[i]; + } + std::cout << std::endl; + } +#endif // SOFAGUI_HAVE_SOFAGUIQT + // This is needed to make sure the GuiMain library (libSofaGuiMain.so) is correctly // linked since the GUIs are statically created during the load of the library. sofa::gui::initMain(); @@ -63,4 +91,5 @@ PYBIND11_MODULE(Gui, m) { moduleAddBaseGui(m); moduleAddGuiManager(m); } -} \ No newline at end of file + +} // namespace sofapython3