diff --git a/bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp b/bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp index 299b8081b..f398049d7 100644 --- a/bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp +++ b/bindings/SofaRuntime/src/SofaPython3/SofaRuntime/Module_SofaRuntime.cpp @@ -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(); diff --git a/bindings/SofaRuntime/tests/SofaRuntime/Base.py b/bindings/SofaRuntime/tests/SofaRuntime/Base.py index cbdd3985c..5940b9c77 100644 --- a/bindings/SofaRuntime/tests/SofaRuntime/Base.py +++ b/bindings/SofaRuntime/tests/SofaRuntime/Base.py @@ -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"))