[core] plugins: Add templates handling in the Plugin class

Templates that are available for a plugin are detected and gathered
upon the plugin's creation.
This commit is contained in:
Candice Bentéjac 2025-05-09 16:46:52 +02:00
parent 836a351cc9
commit 56eebe4caf

View file

@ -1,6 +1,7 @@
from __future__ import annotations from __future__ import annotations
import logging import logging
import os
from enum import Enum from enum import Enum
from inspect import getfile from inspect import getfile
@ -72,8 +73,10 @@ class Plugin(BaseObject):
Members: Members:
name: the name of the plugin (e.g. name of the Python module containing the node plugins) name: the name of the plugin (e.g. name of the Python module containing the node plugins)
path: the absolute path of the plugin path: the absolute path of the plugin
_nodePlugins: dictionary mapping the name of a node plugin to its corresponding _nodePlugins: dictionary mapping the name of a node plugin contained in the plugin
NodePlugin object to its corresponding NodePlugin object
_templates: dictionary mapping the name of templates (.mg files) associated to the plugin
with their absolute paths
processEnv: the environment required for the nodes' processes to be correctly executed processEnv: the environment required for the nodes' processes to be correctly executed
""" """
@ -84,8 +87,11 @@ class Plugin(BaseObject):
self._path: str = path self._path: str = path
self._nodePlugins: dict[str: NodePlugin] = {} self._nodePlugins: dict[str: NodePlugin] = {}
self._templates: dict[str: str] = {}
self._processEnv: ProcessEnv = ProcessEnv(path) self._processEnv: ProcessEnv = ProcessEnv(path)
self.loadTemplates()
@property @property
def name(self): def name(self):
""" Return the name of the plugin. """ """ Return the name of the plugin. """
@ -96,6 +102,11 @@ class Plugin(BaseObject):
""" Return the absolute path of the plugin. """ """ Return the absolute path of the plugin. """
return self._path return self._path
@property
def templates(self):
""" Return the list of templates associated to the plugin. """
return self._templates
@property @property
def processEnv(self): def processEnv(self):
""" Return the environment required to successfully execute processes. """ """ Return the environment required to successfully execute processes. """
@ -126,6 +137,17 @@ class Plugin(BaseObject):
else: else:
logging.warning(f"Node plugin {name} is not part of the plugin {self.name}.") logging.warning(f"Node plugin {name} is not part of the plugin {self.name}.")
def loadTemplates(self):
"""
Load all the pipeline templates that are available within the plugin folder.
Whenever this method is called, the list of templates for the plugin is cleared,
before being filled again.
"""
self._templates.clear()
for file in os.listdir(self.path):
if file.endswith(".mg"):
self._templates[os.path.splitext(file)[0]] = os.path.join(self.path, file)
class NodePlugin(BaseObject): class NodePlugin(BaseObject):
""" """