project map script | semantic parcer

This commit is contained in:
2026-01-01 16:58:21 +03:00
parent a747a163c8
commit 4c6fc8256d
84 changed files with 10178 additions and 537 deletions

View File

@@ -16,12 +16,18 @@ class PluginLoader:
that inherit from PluginBase.
"""
# [DEF:PluginLoader.__init__:Function]
# @PURPOSE: Initializes the PluginLoader with a directory to scan.
# @PARAM: plugin_dir (str) - The directory containing plugin modules.
def __init__(self, plugin_dir: str):
self.plugin_dir = plugin_dir
self._plugins: Dict[str, PluginBase] = {}
self._plugin_configs: Dict[str, PluginConfig] = {}
self._load_plugins()
# [/DEF:PluginLoader.__init__:Function]
# [DEF:PluginLoader._load_plugins:Function]
# @PURPOSE: Scans the plugin directory and loads all valid plugins.
def _load_plugins(self):
"""
Scans the plugin directory, imports modules, and registers valid plugins.
@@ -41,7 +47,12 @@ class PluginLoader:
module_name = filename[:-3]
file_path = os.path.join(self.plugin_dir, filename)
self._load_module(module_name, file_path)
# [/DEF:PluginLoader._load_plugins:Function]
# [DEF:PluginLoader._load_module:Function]
# @PURPOSE: Loads a single Python module and discovers PluginBase implementations.
# @PARAM: module_name (str) - The name of the module.
# @PARAM: file_path (str) - The path to the module file.
def _load_module(self, module_name: str, file_path: str):
"""
Loads a single Python module and extracts PluginBase subclasses.
@@ -83,7 +94,11 @@ class PluginLoader:
self._register_plugin(plugin_instance)
except Exception as e:
print(f"Error instantiating plugin {attribute_name} in {module_name}: {e}") # Replace with proper logging
# [/DEF:PluginLoader._load_module:Function]
# [DEF:PluginLoader._register_plugin:Function]
# @PURPOSE: Registers a PluginBase instance and its configuration.
# @PARAM: plugin_instance (PluginBase) - The plugin instance to register.
def _register_plugin(self, plugin_instance: PluginBase):
"""
Registers a valid plugin instance.
@@ -116,22 +131,39 @@ class PluginLoader:
except Exception as e:
from ..core.logger import logger
logger.error(f"Error validating plugin '{plugin_instance.name}' (ID: {plugin_id}): {e}")
# [/DEF:PluginLoader._register_plugin:Function]
# [DEF:PluginLoader.get_plugin:Function]
# @PURPOSE: Retrieves a loaded plugin instance by its ID.
# @PARAM: plugin_id (str) - The unique identifier of the plugin.
# @RETURN: Optional[PluginBase] - The plugin instance if found, otherwise None.
def get_plugin(self, plugin_id: str) -> Optional[PluginBase]:
"""
Returns a loaded plugin instance by its ID.
"""
return self._plugins.get(plugin_id)
# [/DEF:PluginLoader.get_plugin:Function]
# [DEF:PluginLoader.get_all_plugin_configs:Function]
# @PURPOSE: Returns a list of all registered plugin configurations.
# @RETURN: List[PluginConfig] - A list of plugin configurations.
def get_all_plugin_configs(self) -> List[PluginConfig]:
"""
Returns a list of all loaded plugin configurations.
"""
return list(self._plugin_configs.values())
# [/DEF:PluginLoader.get_all_plugin_configs:Function]
# [DEF:PluginLoader.has_plugin:Function]
# @PURPOSE: Checks if a plugin with the given ID is registered.
# @PARAM: plugin_id (str) - The unique identifier of the plugin.
# @RETURN: bool - True if the plugin is registered, False otherwise.
def has_plugin(self, plugin_id: str) -> bool:
"""
Checks if a plugin with the given ID is loaded.
"""
return plugin_id in self._plugins
return plugin_id in self._plugins
# [/DEF:PluginLoader.has_plugin:Function]
# [/DEF:PluginLoader:Class]