Skip to content

Commit 798f09a

Browse files
committed
simplify plugin loader
1 parent e093e4d commit 798f09a

File tree

2 files changed

+3
-24
lines changed

2 files changed

+3
-24
lines changed

docs/advanced/plugins.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Discovery
1111
=========
1212

1313
Plugin packages advertise themselves through the ``hls4ml.backends`` Python entry point group. Each
14-
entry either exposes a subclass of :class:`hls4ml.backends.backend.Backend` or a callable that
15-
receives ``register_backend`` and ``register_writer`` helpers and performs any setup that is
14+
entry exposes a callable that receives ``register_backend`` and ``register_writer`` helpers and performs any setup that is
1615
required. ``hls4ml`` automatically scans for these entry points during ``hls4ml.backends`` import so
1716
third-party backends become available without additional user configuration.
1817

hls4ml/backends/plugin_loader.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
"""Utilities for discovering and loading external hls4ml backend plugins."""
22

3-
from __future__ import annotations
4-
5-
import inspect
63
import os
7-
from collections.abc import Callable, Iterable
4+
from collections.abc import Callable
85
from importlib import import_module
96
from importlib.metadata import entry_points
107
from typing import Any
118

12-
from hls4ml.backends.backend import Backend, register_backend
9+
from hls4ml.backends.backend import register_backend
1310
from hls4ml.writer.writers import register_writer
1411

1512
ENTRY_POINT_GROUP = 'hls4ml.backends'
@@ -66,16 +63,6 @@ def _load_env_plugins() -> None:
6663

6764
def _register_plugin_object(name: str, obj: Any) -> None:
6865
"""Interpret the plugin object and register provided backends."""
69-
70-
if inspect.isclass(obj) and issubclass(obj, Backend):
71-
_safe_register_backend(name, obj)
72-
return
73-
74-
if isinstance(obj, Iterable) and not isinstance(obj, (str, bytes)):
75-
for item in obj:
76-
_register_plugin_object(name, item)
77-
return
78-
7966
if callable(obj):
8067
_invoke_registration_callable(name, obj)
8168
return
@@ -97,10 +84,3 @@ def _invoke_registration_callable(name: str, func: Callable[..., Any]) -> None:
9784
except Exception as exc:
9885
print(f'WARNING: backend plugin callable "{name}" failed: {exc}')
9986
return
100-
101-
102-
def _safe_register_backend(name: str, backend_cls: type[Backend]) -> None:
103-
try:
104-
register_backend(name, backend_cls)
105-
except Exception as exc:
106-
print(f'WARNING: failed to register backend "{name}" from plugin: {exc}')

0 commit comments

Comments
 (0)