mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
Refactor and restructure directive model
This commit is contained in:
@@ -16,10 +16,10 @@ from hyperglass.settings import Settings
|
||||
from hyperglass.constants import PARSED_RESPONSE_FIELDS, __version__
|
||||
from hyperglass.models.ui import UIParameters
|
||||
from hyperglass.util.files import check_path
|
||||
from hyperglass.models.directive import Directive
|
||||
from hyperglass.exceptions.private import ConfigError, ConfigMissing
|
||||
from hyperglass.models.config.params import Params
|
||||
from hyperglass.models.config.devices import Devices
|
||||
from hyperglass.models.commands.generic import Directive
|
||||
|
||||
# Local
|
||||
from .markdown import get_markdown
|
||||
|
@@ -20,8 +20,8 @@ from hyperglass.exceptions.private import ConfigError
|
||||
if t.TYPE_CHECKING:
|
||||
# Project
|
||||
from hyperglass.models.api.query import Query
|
||||
from hyperglass.models.directive import Directive
|
||||
from hyperglass.models.config.devices import Device
|
||||
from hyperglass.models.commands.generic import Directive
|
||||
|
||||
|
||||
class Construct:
|
||||
|
@@ -29,8 +29,8 @@ from .proxy import Proxy
|
||||
from .params import Params
|
||||
from ..fields import SupportedDriver
|
||||
from .network import Network
|
||||
from ..directive import Directive
|
||||
from .credential import Credential
|
||||
from ..commands.generic import Directive
|
||||
|
||||
|
||||
class Device(HyperglassModelWithId, extra="allow"):
|
||||
|
@@ -22,12 +22,12 @@ from hyperglass.settings import Settings
|
||||
from hyperglass.exceptions.private import InputValidationError
|
||||
|
||||
# Local
|
||||
from ..main import HyperglassModel, HyperglassModelWithId
|
||||
from ..fields import Action
|
||||
from .main import HyperglassModel, HyperglassModelWithId
|
||||
from .fields import Action
|
||||
|
||||
if t.TYPE_CHECKING:
|
||||
# Local
|
||||
from ..config.params import Params
|
||||
from .config.params import Params
|
||||
|
||||
IPv4PrefixLength = conint(ge=0, le=32)
|
||||
IPv6PrefixLength = conint(ge=0, le=128)
|
@@ -18,8 +18,8 @@ if t.TYPE_CHECKING:
|
||||
# Project
|
||||
from hyperglass.state import HyperglassState
|
||||
from hyperglass.models.api.query import Query
|
||||
from hyperglass.models.directive import Directive
|
||||
from hyperglass.models.config.devices import Device
|
||||
from hyperglass.models.commands.generic import Directive
|
||||
|
||||
PluginT = t.TypeVar("PluginT", bound=HyperglassPlugin)
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
# Standard Library
|
||||
import sys
|
||||
from typing import Any, Tuple
|
||||
import typing as t
|
||||
from inspect import isclass, getmembers
|
||||
from pathlib import Path
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
@@ -19,7 +19,7 @@ from ._manager import InputPluginManager, OutputPluginManager
|
||||
_PLUGIN_GLOBALS = {"InputPlugin": InputPlugin, "OutputPlugin": OutputPlugin, "log": log}
|
||||
|
||||
|
||||
def _is_class(module: Any, obj: object) -> bool:
|
||||
def _is_class(module: t.Any, obj: object) -> bool:
|
||||
if isclass(obj):
|
||||
# Get the object's containing module name.
|
||||
obj_module_name: str = getattr(obj, "__module__", "")
|
||||
@@ -30,7 +30,7 @@ def _is_class(module: Any, obj: object) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _register_from_module(module: Any, **kwargs: Any) -> Tuple[str, ...]:
|
||||
def _register_from_module(module: t.Any, **kwargs: t.Any) -> t.Tuple[str, ...]:
|
||||
"""Register defined classes from the module."""
|
||||
failures = ()
|
||||
defs = getmembers(module, lambda o: _is_class(module, o))
|
||||
@@ -48,7 +48,7 @@ def _register_from_module(module: Any, **kwargs: Any) -> Tuple[str, ...]:
|
||||
return failures
|
||||
|
||||
|
||||
def _module_from_file(file: Path) -> Any:
|
||||
def _module_from_file(file: Path) -> t.Any:
|
||||
"""Import a plugin module from its file Path object."""
|
||||
name = file.name.split(".")[0]
|
||||
spec = spec_from_file_location(f"hyperglass.plugins.external.{name}", file)
|
||||
@@ -64,7 +64,7 @@ def init_builtin_plugins() -> None:
|
||||
_register_from_module(_builtin)
|
||||
|
||||
|
||||
def register_plugin(plugin_file: Path, **kwargs) -> Tuple[str, ...]:
|
||||
def register_plugin(plugin_file: Path, **kwargs) -> t.Tuple[str, ...]:
|
||||
"""Register an external plugin by file path."""
|
||||
if plugin_file.exists():
|
||||
module = _module_from_file(plugin_file)
|
||||
|
Reference in New Issue
Block a user