Loads a single plugin from a file path using the register contract.
(file_path: Path)
| 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.""" |
| 43 | try: |
| 44 | spec = importlib.util.spec_from_file_location(file_path.stem, str(file_path)) |
| 45 | if spec is None or spec.loader is None: |
| 46 | return None |
| 47 | |
| 48 | module = importlib.util.module_from_spec(spec) |
| 49 | spec.loader.exec_module(module) |
| 50 | |
| 51 | # Check for the register() function (the new contract) |
| 52 | if hasattr(module, REGISTER_FUNCTION): |
| 53 | register_fn = getattr(module, REGISTER_FUNCTION) |
| 54 | return register_fn() |
| 55 | |
| 56 | # Fallback to old class-based detection for backward compatibility |
| 57 | for attr_name in dir(module): |
| 58 | attr = getattr(module, attr_name) |
| 59 | if isinstance(attr, type) and issubclass(attr, (DeobfuscatorPlugin, ThemePlugin)) and attr not in (DeobfuscatorPlugin, ThemePlugin): |
| 60 | return attr() |
| 61 | |
| 62 | return None |
| 63 | except Exception as e: |
| 64 | logger.error(f"Error executing plugin {file_path.name}: {e}") |
| 65 | return None |