Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ PYBIND11_MODULE(SofaRuntime, m) {
return simpleapi::importPlugin(name);
}, "import a sofa plugin into the current environment");

m.def("findPlugin", [](const std::string& name)
{
auto& pluginManager = sofa::helper::system::PluginManager::getInstance();
return pluginManager.findPlugin(name);
}, py::arg("name"),
"Search the plugin repository for the library of the plugin with the given name, without loading it.\n"
"Returns the path to the plugin library if found, an empty string otherwise.");

m.def("isPluginLoaded", [](const std::string& name)
{
auto& pluginManager = sofa::helper::system::PluginManager::getInstance();
return pluginManager.pluginIsLoaded(name);
}, py::arg("name"),
"Returns True if the plugin with the given name (or path) is already loaded, False otherwise.");

m.def("unload_plugin", [](const std::string& name)
{
auto& pluginManager = sofa::helper::system::PluginManager::getInstance();
Expand Down
21 changes: 21 additions & 0 deletions bindings/SofaRuntime/tests/SofaRuntime/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,24 @@ def test_getCategoriesmethod(self):
t = SofaRuntime.getCategories("MeshOBJLoader")
self.assertEqual(len(t),1)
self.assertIsInstance(t, list)

def test_findPlugin(self):
import os
import SofaRuntime
path = SofaRuntime.findPlugin("Sofa.Component")
self.assertIsInstance(path, str)
self.assertNotEqual(path, "")
self.assertTrue(os.path.isfile(path))

def test_findPlugin_nonExisting(self):
import SofaRuntime
name = "ThisPluginDoesNotExist_SofaPython3Test"
self.assertEqual(SofaRuntime.findPlugin(name), "")
# Searching must not have loaded anything
self.assertFalse(SofaRuntime.isPluginLoaded(name))

def test_isPluginLoaded(self):
import SofaRuntime
SofaRuntime.importPlugin("Sofa.Component")
self.assertTrue(SofaRuntime.isPluginLoaded("Sofa.Component"))
self.assertFalse(SofaRuntime.isPluginLoaded("ThisPluginDoesNotExist_SofaPython3Test"))
Loading