Loads all plugins from the plugins directory. Isolates failures per plugin to ensure application startup is not affected.
()
| 12 | logger = logging.getLogger(__name__) |
| 13 | |
| 14 | def load_plugins() -> List[Dict[str, Any]]: |
| 15 | """ |
| 16 | Loads all plugins from the plugins directory. |
| 17 | Isolates failures per plugin to ensure application startup is not affected. |
| 18 | """ |
| 19 | plugins_dir = Path(__file__).parent |
| 20 | loaded_plugins = [] |
| 21 | |
| 22 | # Iterate through all .py files in the plugins folder |
| 23 | for plugin_file in plugins_dir.glob("*.py"): |
| 24 | if plugin_file.name in ("__init__.py", "plugins.py"): |
| 25 | continue |
| 26 | |
| 27 | try: |
| 28 | plugin_instance = _load_single_plugin(plugin_file) |
| 29 | if plugin_instance: |
| 30 | plugin_type = "deobfuscator" if isinstance(plugin_instance, DeobfuscatorPlugin) else "theme" |
| 31 | loaded_plugins.append({ |
| 32 | "type": plugin_type, |
| 33 | "instance": plugin_instance |
| 34 | }) |
| 35 | logger.debug(f"Successfully loaded plugin: {getattr(plugin_instance, 'name', plugin_file.stem)}") |
| 36 | except Exception as e: |
| 37 | logger.error(f"Failed to load plugin {plugin_file.name}: {e}") |
| 38 | |
| 39 | return loaded_plugins |
| 40 | |
| 41 | def _load_single_plugin(file_path: Path): |
| 42 | """Loads a single plugin from a file path using the register contract.""" |
no test coverage detected