Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
40 changes: 38 additions & 2 deletions Plugin/src/SofaPython3/PythonEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<std::string, Plugin>& 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<void()> cb)
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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);
}


Expand Down
6 changes: 6 additions & 0 deletions Plugin/src/SofaPython3/PythonEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -134,6 +139,7 @@ class SOFAPYTHON3_API PythonEnvironment

private:
static PythonEnvironmentData* getStaticData() ;
static std::string pluginLibraryPath;
};

} // namespace sofapython3
Expand Down
1 change: 1 addition & 0 deletions Plugin/src/SofaPython3/initModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void initExternalModule()
PythonEnvironment::Init();
first = false;
}
PythonEnvironment::addPluginManagerCallback();
}

const char* getModuleName()
Expand Down
4 changes: 4 additions & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
31 changes: 30 additions & 1 deletion bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

#include <sofa/gui/Main.h>
#include <sofa/core/init.h>
#include <sofa/helper/logging/Messaging.h>
#include <sofa/helper/Utils.h>
#include <sofa/helper/system/FileSystem.h>
using sofa::helper::system::FileSystem;

#if SOFAGUI_HAVE_SOFAGUIQT
#include <sofa/gui/qt/qt.conf.h>
#endif // SOFAGUI_HAVE_SOFAGUIQT

#include "Binding_BaseGui.h"
#include "Binding_GUIManager.h"
Expand Down Expand Up @@ -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();
Expand All @@ -63,4 +91,5 @@ PYBIND11_MODULE(Gui, m) {
moduleAddBaseGui(m);
moduleAddGuiManager(m);
}
}

} // namespace sofapython3