Discover out-of-tree platform backends via entry points. Third-party packages register under the ``lightx2v.platform_plugins`` entry point group. Each entry point is a zero-arg callable that registers its Device class into ``PLATFORM_DEVICE_REGISTER`` and its ops into the ``PLATFORM
()
| 6 | |
| 7 | |
| 8 | def _load_platform_plugins(platform): |
| 9 | """Discover out-of-tree platform backends via entry points. |
| 10 | |
| 11 | Third-party packages register under the ``lightx2v.platform_plugins`` entry |
| 12 | point group. Each entry point is a zero-arg callable that registers its |
| 13 | Device class into ``PLATFORM_DEVICE_REGISTER`` and may return a second |
| 14 | callable that loads ops after device initialization. |
| 15 | |
| 16 | This runs before ``init_ai_device`` (so a plugin-provided device is visible |
| 17 | to the lookup) and before ``lightx2v_platform.ops`` is imported, i.e. before |
| 18 | ``lightx2v.utils.registry_factory`` snapshots the selected platform's |
| 19 | registries via ``merge()``. That ordering is what makes plugin |
| 20 | registrations reach the framework-facing registries. |
| 21 | |
| 22 | A plugin for the selected platform is required to load successfully. An |
| 23 | unrelated optional plugin may fail without preventing device setup. |
| 24 | """ |
| 25 | loaders = [] |
| 26 | try: |
| 27 | from importlib.metadata import entry_points |
| 28 | except Exception: # pragma: no cover - importlib.metadata is stdlib on 3.8+ |
| 29 | return loaders |
| 30 | |
| 31 | try: |
| 32 | eps = entry_points(group="lightx2v.platform_plugins") |
| 33 | except TypeError: |
| 34 | # importlib.metadata < 3.10 returns a dict-like mapping. |
| 35 | eps = entry_points().get("lightx2v.platform_plugins", []) |
| 36 | |
| 37 | for ep in eps: |
| 38 | try: |
| 39 | plugin_loader = ep.load()() |
| 40 | if callable(plugin_loader) and ep.name == platform: |
| 41 | loaders.append((ep, plugin_loader)) |
| 42 | logger.info(f"Loaded LightX2V platform plugin: {ep.name}") |
| 43 | except Exception as e: |
| 44 | if ep.name == platform: |
no test coverage detected