mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
Fix plugin registration for builtins
This commit is contained in:
@@ -14,7 +14,12 @@ from gunicorn.glogging import Logger # type: ignore
|
||||
|
||||
# Local
|
||||
from .log import log, setup_lib_logging
|
||||
from .plugins import InputPluginManager, OutputPluginManager, register_plugin
|
||||
from .plugins import (
|
||||
InputPluginManager,
|
||||
OutputPluginManager,
|
||||
register_plugin,
|
||||
init_builtin_plugins,
|
||||
)
|
||||
from .constants import MIN_NODE_VERSION, MIN_PYTHON_VERSION, __version__
|
||||
from .util.frontend import get_node_version
|
||||
|
||||
@@ -123,6 +128,10 @@ def cache_config() -> bool:
|
||||
def register_all_plugins(devices: "Devices") -> None:
|
||||
"""Validate and register configured plugins."""
|
||||
|
||||
# Register built-in plugins.
|
||||
init_builtin_plugins()
|
||||
|
||||
# Register external plugins.
|
||||
for plugin_file, directives in devices.directive_plugins().items():
|
||||
failures = register_plugin(plugin_file, directives=directives)
|
||||
for failure in failures:
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
"""hyperglass Plugins."""
|
||||
|
||||
# Local
|
||||
from .main import init_plugins, register_plugin
|
||||
from .main import register_plugin, init_builtin_plugins
|
||||
from ._input import InputPlugin, InputPluginReturn
|
||||
from ._output import OutputType, OutputPlugin
|
||||
from ._manager import InputPluginManager, OutputPluginManager
|
||||
|
||||
__all__ = (
|
||||
"init_plugins",
|
||||
"init_builtin_plugins",
|
||||
"InputPlugin",
|
||||
"InputPluginManager",
|
||||
"InputPluginReturn",
|
||||
|
||||
@@ -20,7 +20,14 @@ _PLUGIN_GLOBALS = {"InputPlugin": InputPlugin, "OutputPlugin": OutputPlugin, "lo
|
||||
|
||||
|
||||
def _is_class(module: Any, obj: object) -> bool:
|
||||
return isclass(obj) and obj.__module__ == module.__name__
|
||||
if isclass(obj):
|
||||
# Get the object's containing module name.
|
||||
obj_module_name: str = getattr(obj, "__module__", "")
|
||||
# Get the module's name.
|
||||
module_name: str = getattr(module, "__name__", None)
|
||||
# Only validate objects that are members of the module.
|
||||
return module_name in obj_module_name
|
||||
return False
|
||||
|
||||
|
||||
def _register_from_module(module: Any, **kwargs: Any) -> Tuple[str, ...]:
|
||||
@@ -52,7 +59,7 @@ def _module_from_file(file: Path) -> Any:
|
||||
return module
|
||||
|
||||
|
||||
def init_plugins() -> None:
|
||||
def init_builtin_plugins() -> None:
|
||||
"""Initialize all built-in plugins."""
|
||||
_register_from_module(_builtin)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user