MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / _load_platform_plugins

Function _load_platform_plugins

lightx2v_platform/set_ai_device.py:8–41  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

6
7
8def _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:

Callers 1

set_ai_deviceFunction · 0.85

Calls 4

infoMethod · 0.80
warningMethod · 0.80
getMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected