Skip to content

Commit 52f64f7

Browse files
authored
Merge pull request #131 from guparan/v20.12_changes
v20.12 changes
2 parents 47e698f + 31dc482 commit 52f64f7

File tree

7 files changed

+91
-15
lines changed

7 files changed

+91
-15
lines changed

.github/workflows/macos.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ jobs:
2727
brew install ccache ninja boost eigen pybind11
2828
python3 -m pip install numpy
2929
30-
- name: Download SOFA nightly build
30+
- name: Download SOFA v20.12.02
3131
run: |
3232
curl --output sofa.zip -L \
33-
https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries-v20.12/lastSuccessfulBuild/CI_SCOPE=binaries_minimal/artifact/MacOS/*zip*/MacOS.zip
33+
https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_SCOPE=binaries_minimal/309/artifact/MacOS/*zip*/MacOS.zip
3434
35-
- name: Install SOFA nightly build
35+
- name: Install SOFA v20.12.02
3636
run: |
3737
sudo unzip sofa.zip -d temp
3838
sudo unzip temp/MacOS/`ls temp/MacOS/` -d temp
@@ -105,12 +105,12 @@ jobs:
105105
brew install boost
106106
python3 -m pip install numpy
107107
108-
- name: Download SOFA nightly build
108+
- name: Download SOFA v20.12.02
109109
run: |
110110
curl --output sofa.zip -L \
111-
https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries-v20.12/lastSuccessfulBuild/CI_SCOPE=binaries_minimal/artifact/MacOS/*zip*/MacOS.zip
111+
https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_SCOPE=binaries_minimal/309/artifact/MacOS/*zip*/MacOS.zip
112112
113-
- name: Install SOFA nightly build
113+
- name: Install SOFA v20.12.02
114114
run: |
115115
sudo unzip sofa.zip -d temp
116116
sudo unzip temp/MacOS/`ls temp/MacOS/` -d temp

.github/workflows/ubuntu.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ jobs:
4242
- name: Install pybind11
4343
run: cd /tmp/pybind11 && sudo make install
4444

45-
- name: Download SOFA nightly build
45+
- name: Download SOFA v20.12.02
4646
run: |
4747
curl --output sofa.zip -L \
48-
https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries-v20.12/lastSuccessfulBuild/CI_SCOPE=binaries_minimal/artifact/Linux/*zip*/Linux.zip
48+
https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_SCOPE=binaries_minimal/309/artifact/Linux/*zip*/Linux.zip
4949
50-
- name: Install SOFA nightly build
50+
- name: Install SOFA v20.12.02
5151
run: |
5252
sudo unzip sofa.zip -d temp
5353
sudo unzip temp/Linux/`ls temp/Linux/` -d temp
@@ -120,12 +120,12 @@ jobs:
120120
sudo apt install -qq libboost-all-dev
121121
python3 -m pip install numpy
122122
123-
- name: Download SOFA nightly build
123+
- name: Download SOFA v20.12.02
124124
run: |
125125
curl --output sofa.zip -L \
126-
https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries-v20.12/lastSuccessfulBuild/CI_SCOPE=binaries_minimal/artifact/Linux/*zip*/Linux.zip
126+
https://ci.inria.fr/sofa-ci-dev/job/nightly-generate-binaries/CI_SCOPE=binaries_minimal/309/artifact/Linux/*zip*/Linux.zip
127127
128-
- name: Install SOFA nightly build
128+
- name: Install SOFA v20.12.02
129129
run: |
130130
sudo unzip sofa.zip -d temp
131131
sudo unzip temp/Linux/`ls temp/Linux/` -d temp

Plugin/src/SofaPython3/PythonEnvironment.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ PythonEnvironmentData* PythonEnvironment::getStaticData()
118118
return m_staticdata;
119119
}
120120

121+
std::string PythonEnvironment::pluginLibraryPath = "";
122+
121123
SOFAPYTHON3_API py::module PythonEnvironment::importFromFile(const std::string& module, const std::string& path, py::object* globals)
122124
{
123125
PythonEnvironment::gil lock;
@@ -238,6 +240,17 @@ void PythonEnvironment::Init()
238240

239241
// python modules are automatically reloaded at each scene loading
240242
//setAutomaticModuleReload( true );
243+
244+
// Initialize pluginLibraryPath by reading PluginManager's map
245+
std::map<std::string, Plugin>& map = PluginManager::getInstance().getPluginMap();
246+
for( const auto& elem : map)
247+
{
248+
Plugin p = elem.second;
249+
if ( p.getModuleName() == sofa_tostring(SOFA_TARGET) )
250+
{
251+
pluginLibraryPath = elem.first;
252+
}
253+
}
241254
}
242255

243256
void PythonEnvironment::executePython(std::function<void()> cb)
@@ -332,7 +345,7 @@ void PythonEnvironment::addPythonModulePathsForPlugins(const std::string& plugin
332345

333346
if(!added)
334347
{
335-
msg_warning("PythonEnvironment") << "No python dir found in " << pluginsDirectory;
348+
msg_info("SofaPython3") << "No python3 dir found in " << pluginsDirectory;
336349
}
337350
}
338351

@@ -352,7 +365,30 @@ void PythonEnvironment::addPythonModulePathsForPluginsByName(const std::string&
352365
return;
353366
}
354367
}
355-
msg_warning("PythonEnvironment") << pluginName << " not found in PluginManager's map.";
368+
msg_info("SofaPython3") << pluginName << " not found in PluginManager's map.";
369+
}
370+
371+
void PythonEnvironment::addPluginManagerCallback()
372+
{
373+
PluginManager::getInstance().addOnPluginLoadedCallback(pluginLibraryPath,
374+
[](const std::string& pluginLibraryPath, const Plugin& plugin) {
375+
// WARNING: loaded plugin must be organized like plugin_name/lib/plugin_name.so
376+
for ( auto path : sofa::helper::system::PluginRepository.getPaths() )
377+
{
378+
std::string pluginRoot = FileSystem::cleanPath( path + "/" + plugin.getModuleName() );
379+
if ( FileSystem::exists(pluginRoot) && FileSystem::isDirectory(pluginRoot) )
380+
{
381+
addPythonModulePathsForPlugins(pluginRoot);
382+
return;
383+
}
384+
}
385+
}
386+
);
387+
}
388+
389+
void PythonEnvironment::removePluginManagerCallback()
390+
{
391+
PluginManager::getInstance().removeOnPluginLoadedCallback(pluginLibraryPath);
356392
}
357393

358394

Plugin/src/SofaPython3/PythonEnvironment.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ class SOFAPYTHON3_API PythonEnvironment
5757
const std::string& path,
5858
pybind11::object* globals = nullptr);
5959

60+
/// Add a new callback in PluginManager to auto-add future
61+
/// loaded plugins to sys.path
62+
static void addPluginManagerCallback();
63+
static void removePluginManagerCallback();
64+
6065
/// Add a path to sys.path, the list of search path for Python modules.
6166
static void addPythonModulePath(const std::string& path);
6267

@@ -134,6 +139,7 @@ class SOFAPYTHON3_API PythonEnvironment
134139

135140
private:
136141
static PythonEnvironmentData* getStaticData() ;
142+
static std::string pluginLibraryPath;
137143
};
138144

139145
} // namespace sofapython3

Plugin/src/SofaPython3/initModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void initExternalModule()
5252
PythonEnvironment::Init();
5353
first = false;
5454
}
55+
PythonEnvironment::addPluginManagerCallback();
5556
}
5657

5758
const char* getModuleName()

bindings/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ endif()
88
# This will set rpaths relative to SP3 plugin library
99
if(UNIX)
1010
set(CMAKE_INSTALL_RPATH
11+
"$ORIGIN"
12+
"$$ORIGIN"
1113
"$ORIGIN/../lib"
1214
"$$ORIGIN/../lib"
1315
)
1416
if(APPLE)
1517
set(CMAKE_MACOSX_RPATH ON)
1618
list(APPEND CMAKE_INSTALL_RPATH
19+
"@loader_path"
20+
"@executable_path"
1721
"@loader_path/../lib"
1822
"@executable_path/../lib"
1923
)

bindings/SofaGui/src/SofaPython3/SofaGui/Module_SofaGui.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222

2323
#include <sofa/gui/Main.h>
2424
#include <sofa/core/init.h>
25+
#include <sofa/helper/logging/Messaging.h>
26+
#include <sofa/helper/Utils.h>
27+
#include <sofa/helper/system/FileSystem.h>
28+
using sofa::helper::system::FileSystem;
29+
30+
#if SOFAGUI_HAVE_SOFAGUIQT
31+
#include <sofa/gui/qt/qt.conf.h>
32+
#endif // SOFAGUI_HAVE_SOFAGUIQT
2533

2634
#include "Binding_BaseGui.h"
2735
#include "Binding_GUIManager.h"
@@ -55,6 +63,26 @@ PYBIND11_MODULE(Gui, m) {
5563
:members:
5664
)doc";
5765

66+
#if SOFAGUI_HAVE_SOFAGUIQT
67+
std::string sofaPrefixAbsolute = sofa::helper::Utils::getSofaPathPrefix();
68+
std::string inputFilepath = FileSystem::cleanPath(sofaPrefixAbsolute + "/bin/qt.conf");
69+
bool success = sofa::gui::qt::loadQtConfWithCustomPrefix(inputFilepath, sofaPrefixAbsolute);
70+
if(success)
71+
{
72+
msg_info("Sofa.Gui") << "Loaded qt.conf from " << inputFilepath << " customized with Prefix = " << sofaPrefixAbsolute;
73+
}
74+
else
75+
{
76+
msg_warning("Sofa.Gui") << "Failed loading and/or customizing qt.conf from " << inputFilepath;
77+
78+
std::cout << "qt_resource_data:" << std::endl;
79+
for (int i = 0 ; i < qt_resource_data.size() ; ++i) {
80+
std::cout << qt_resource_data[i];
81+
}
82+
std::cout << std::endl;
83+
}
84+
#endif // SOFAGUI_HAVE_SOFAGUIQT
85+
5886
// This is needed to make sure the GuiMain library (libSofaGuiMain.so) is correctly
5987
// linked since the GUIs are statically created during the load of the library.
6088
sofa::gui::initMain();
@@ -63,4 +91,5 @@ PYBIND11_MODULE(Gui, m) {
6391
moduleAddBaseGui(m);
6492
moduleAddGuiManager(m);
6593
}
66-
}
94+
95+
} // namespace sofapython3

0 commit comments

Comments
 (0)