forked from mirrors/thatmattlove-hyperglass
25 lines
893 B
Python
25 lines
893 B
Python
"""Built-in hyperglass directives."""
|
|
|
|
# Standard Library
|
|
import pkgutil
|
|
import importlib
|
|
from pathlib import Path
|
|
|
|
# Project
|
|
from hyperglass.log import log
|
|
from hyperglass.state import use_state
|
|
|
|
|
|
def register_builtin_directives() -> None:
|
|
"""Find all directives and register them with global state manager."""
|
|
directives_dir = Path(__file__).parent
|
|
state = use_state()
|
|
for _, name, __ in pkgutil.iter_modules([directives_dir]):
|
|
module = importlib.import_module(f"hyperglass.defaults.directives.{name}")
|
|
|
|
if not all((hasattr(module, "__all__"), len(getattr(module, "__all__", ())) > 0)):
|
|
# Warn if there is no __all__ export or if it is empty.
|
|
log.warning("Module '{!s}' is missing an '__all__' export", module)
|
|
|
|
exports = (getattr(module, p) for p in module.__all__ if hasattr(module, p))
|
|
state.add_directive(*exports)
|