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
|
# Local
|
||||||
from .log import log, setup_lib_logging
|
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 .constants import MIN_NODE_VERSION, MIN_PYTHON_VERSION, __version__
|
||||||
from .util.frontend import get_node_version
|
from .util.frontend import get_node_version
|
||||||
|
|
||||||
@@ -123,6 +128,10 @@ def cache_config() -> bool:
|
|||||||
def register_all_plugins(devices: "Devices") -> None:
|
def register_all_plugins(devices: "Devices") -> None:
|
||||||
"""Validate and register configured plugins."""
|
"""Validate and register configured plugins."""
|
||||||
|
|
||||||
|
# Register built-in plugins.
|
||||||
|
init_builtin_plugins()
|
||||||
|
|
||||||
|
# Register external plugins.
|
||||||
for plugin_file, directives in devices.directive_plugins().items():
|
for plugin_file, directives in devices.directive_plugins().items():
|
||||||
failures = register_plugin(plugin_file, directives=directives)
|
failures = register_plugin(plugin_file, directives=directives)
|
||||||
for failure in failures:
|
for failure in failures:
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
"""hyperglass Plugins."""
|
"""hyperglass Plugins."""
|
||||||
|
|
||||||
# Local
|
# Local
|
||||||
from .main import init_plugins, register_plugin
|
from .main import register_plugin, init_builtin_plugins
|
||||||
from ._input import InputPlugin, InputPluginReturn
|
from ._input import InputPlugin, InputPluginReturn
|
||||||
from ._output import OutputType, OutputPlugin
|
from ._output import OutputType, OutputPlugin
|
||||||
from ._manager import InputPluginManager, OutputPluginManager
|
from ._manager import InputPluginManager, OutputPluginManager
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
"init_plugins",
|
"init_builtin_plugins",
|
||||||
"InputPlugin",
|
"InputPlugin",
|
||||||
"InputPluginManager",
|
"InputPluginManager",
|
||||||
"InputPluginReturn",
|
"InputPluginReturn",
|
||||||
|
|||||||
@@ -20,7 +20,14 @@ _PLUGIN_GLOBALS = {"InputPlugin": InputPlugin, "OutputPlugin": OutputPlugin, "lo
|
|||||||
|
|
||||||
|
|
||||||
def _is_class(module: Any, obj: object) -> bool:
|
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, ...]:
|
def _register_from_module(module: Any, **kwargs: Any) -> Tuple[str, ...]:
|
||||||
@@ -52,7 +59,7 @@ def _module_from_file(file: Path) -> Any:
|
|||||||
return module
|
return module
|
||||||
|
|
||||||
|
|
||||||
def init_plugins() -> None:
|
def init_builtin_plugins() -> None:
|
||||||
"""Initialize all built-in plugins."""
|
"""Initialize all built-in plugins."""
|
||||||
_register_from_module(_builtin)
|
_register_from_module(_builtin)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user