[core] plugins: Support finding unregistered nodes in plugins

A `NodePlugin` may be part of a `Plugin` even if it has not been
registered. `containsNode` allows to check whether a `NodePlugin` is
contained within a `Plugin`, and `belongsToPlugin`
This commit is contained in:
Candice Bentéjac 2025-05-22 16:22:32 +02:00
parent 98d90dae81
commit a8a54f67fb

View file

@ -148,6 +148,16 @@ class Plugin(BaseObject):
if file.endswith(".mg"):
self._templates[os.path.splitext(file)[0]] = os.path.join(self.path, file)
def containsNodePlugin(self, name: str) -> bool:
"""
Return whether the node plugin "name" is part of the plugin, independently from its
status.
Args:
name: the name of the node plugin to be checked.
"""
return name in self._nodePlugins
class NodePlugin(BaseObject):
"""
@ -231,6 +241,22 @@ class NodePluginManager(BaseObject):
"""
return name in self._nodePlugins
def belongsToPlugin(self, name: str) -> Plugin:
"""
Check whether the node plugin belongs to a loaded plugin, independently from
whether it has been registered or not.
Args:
name: the name of the node plugin that needs to be searched for across plugins.
Returns:
Plugin | None: the Plugin the node belongs to if it exists, None otherwise.
"""
for plugin in self._plugins.values():
if plugin.containsNodePlugin(name):
return plugin
return None
def getPlugins(self) -> dict[str: Plugin]:
"""
Return a dictionary containing all the loaded Plugins, with {key, value} =