Extensions¶
Edgy has extension support build on the Monkay extensions system. Adding extensions
is possible in settings via the attribute/parameter extensions
.
They must implement the monkay extension protocol or return as a callable a class implementing the extension protocol. This sounds hard but it isn't:
from typing import Any
from edgy import EdgySettings
@dataclass
class Extension(ExtensionProtocol[edgy.Instance, edgy.Registry]):
name: str = "hello"
def apply(self, monkay_instance: Monkay[edgy.Instance, edgy.Registry]) -> None:
"""Do something here"""
@dataclass
class ExtensionLessTyped(ExtensionProtocol):
name: str = "hello"
def apply(self, monkay_instance: Monkay) -> None:
"""Do something here"""
class ExtensionSettings(EdgySettings):
extensions: list[Any] = [Extension(), ExtensionLessTyped()]
You can also lazily provide them via add_extension (should happen before the instance is set)
from dataclasses import dataclass
import edgy
@dataclass
class Extension(ExtensionProtocol[edgy.Instance, edgy.Registry]):
name: str = "hard-typed"
def apply(self, monkay_instance: Monkay[edgy.Instance, edgy.Registry]) -> None:
"""Do something here"""
@dataclass
class ExtensionLessTyped(ExtensionProtocol):
name: str = "less-typed"
def apply(self, monkay_instance: Monkay) -> None:
"""Do something here"""
edgy.monkay.add_extension(Extension())
edgy.monkay.add_extension(ExtensionLessTyped())