(
self,
key: str,
path: str,
*,
folder_name: str,
force_reload: bool,
previous_package: Optional[str],
)
| 288 | yield key, action_id |
| 289 | |
| 290 | def _load_plugin( |
| 291 | self, |
| 292 | key: str, |
| 293 | path: str, |
| 294 | *, |
| 295 | folder_name: str, |
| 296 | force_reload: bool, |
| 297 | previous_package: Optional[str], |
| 298 | ) -> tuple[Optional[LoadedPlugin], Optional[str]]: |
| 299 | # Plugin can be a package and/or contain plugin.py. Prefer plugin.py when present. |
| 300 | has_pkg = os.path.exists(os.path.join(path, "__init__.py")) |
| 301 | has_pluginpy = os.path.exists(os.path.join(path, "plugin.py")) |
| 302 | if not (has_pkg or has_pluginpy): |
| 303 | logger.debug(f"Skipping {path}: no plugin.py or package") |
| 304 | return None, None |
| 305 | |
| 306 | package_name = self._resolve_package_name(key) |
| 307 | alias_name = self._resolve_alias_name(folder_name, path) |
| 308 | |
| 309 | if force_reload and previous_package: |
| 310 | self._unload_package(previous_package) |
| 311 | |
| 312 | module = None |
| 313 | plugin_cls = None |
| 314 | last_error = None |
| 315 | |
| 316 | # Ensure a package context exists for plugin.py (even without __init__.py) |
| 317 | if has_pluginpy: |
| 318 | self._ensure_namespace_package(package_name, path, alias=alias_name) |
| 319 | |
| 320 | module_name = f"{package_name}.plugin" |
| 321 | plugin_path = os.path.join(path, "plugin.py") |
| 322 | try: |
| 323 | logger.debug(f"Importing plugin module {module_name} from {plugin_path}") |
| 324 | module = self._load_module_from_path(module_name, plugin_path, is_package=False) |
| 325 | if alias_name: |
| 326 | self._register_alias_module(f"{alias_name}.plugin", module, path) |
| 327 | plugin_cls = getattr(module, "Plugin", None) |
| 328 | if plugin_cls is None: |
| 329 | logger.warning(f"Module {module_name} has no Plugin class") |
| 330 | except Exception as e: |
| 331 | last_error = e |
| 332 | logger.exception(f"Error importing module {module_name}") |
| 333 | |
| 334 | if plugin_cls is None and has_pkg: |
| 335 | module_name = package_name |
| 336 | init_path = os.path.join(path, "__init__.py") |
| 337 | try: |
| 338 | logger.debug(f"Importing plugin package {module_name} from {init_path}") |
| 339 | module = self._load_module_from_path(module_name, init_path, is_package=True) |
| 340 | self._register_alias_module(alias_name, module, path) |
| 341 | plugin_cls = getattr(module, "Plugin", None) |
| 342 | if plugin_cls is None: |
| 343 | logger.warning(f"Module {module_name} has no Plugin class") |
| 344 | except Exception as e: |
| 345 | last_error = e |
| 346 | logger.exception(f"Error importing module {module_name}") |
| 347 |
no test coverage detected