refactor: remove per-type module.py and simplify plugin wiring
This commit is contained in:
@@ -1,3 +1 @@
|
||||
"""Item type package exposing plugin module surface."""
|
||||
|
||||
from .module import * # noqa: F401,F403
|
||||
"""Clock item type plugin package."""
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
"""Clock item plugin module surface."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .actions import use_item
|
||||
from .definition import (
|
||||
CAPABILITIES,
|
||||
DEFAULT_PARAMS,
|
||||
DEFAULT_TIME_ZONE,
|
||||
DEFAULT_TITLE,
|
||||
DIRECTIONAL,
|
||||
EDITABLE_PROPERTIES,
|
||||
EMIT_RANGE,
|
||||
EMIT_SOUND,
|
||||
LABEL,
|
||||
PROPERTY_METADATA,
|
||||
TIME_ZONE_OPTIONS,
|
||||
TOOLTIP,
|
||||
USE_COOLDOWN_MS,
|
||||
USE_SOUND,
|
||||
)
|
||||
from .validator import validate_update
|
||||
|
||||
__all__ = [
|
||||
"LABEL",
|
||||
"TOOLTIP",
|
||||
"EDITABLE_PROPERTIES",
|
||||
"CAPABILITIES",
|
||||
"USE_SOUND",
|
||||
"EMIT_SOUND",
|
||||
"USE_COOLDOWN_MS",
|
||||
"EMIT_RANGE",
|
||||
"DIRECTIONAL",
|
||||
"DEFAULT_TITLE",
|
||||
"DEFAULT_TIME_ZONE",
|
||||
"TIME_ZONE_OPTIONS",
|
||||
"DEFAULT_PARAMS",
|
||||
"PROPERTY_METADATA",
|
||||
"validate_update",
|
||||
"use_item",
|
||||
]
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from . import module
|
||||
from ..plugin_helpers import build_item_module
|
||||
from . import actions, definition, validator
|
||||
|
||||
ITEM_TYPE_PLUGIN = {
|
||||
"type": "clock",
|
||||
"order": 10,
|
||||
"module": module,
|
||||
"module": build_item_module(definition, validate_update=validator.validate_update, use_item=actions.use_item),
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
"""Item type package exposing plugin module surface."""
|
||||
|
||||
from .module import * # noqa: F401,F403
|
||||
"""Dice item type plugin package."""
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
"""Dice item plugin module surface."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .actions import use_item
|
||||
from .definition import (
|
||||
CAPABILITIES,
|
||||
DEFAULT_PARAMS,
|
||||
DEFAULT_TITLE,
|
||||
DIRECTIONAL,
|
||||
EDITABLE_PROPERTIES,
|
||||
EMIT_RANGE,
|
||||
EMIT_SOUND,
|
||||
LABEL,
|
||||
PROPERTY_METADATA,
|
||||
TOOLTIP,
|
||||
USE_COOLDOWN_MS,
|
||||
USE_SOUND,
|
||||
)
|
||||
from .validator import validate_update
|
||||
|
||||
__all__ = [
|
||||
"LABEL",
|
||||
"TOOLTIP",
|
||||
"EDITABLE_PROPERTIES",
|
||||
"CAPABILITIES",
|
||||
"USE_SOUND",
|
||||
"EMIT_SOUND",
|
||||
"USE_COOLDOWN_MS",
|
||||
"EMIT_RANGE",
|
||||
"DIRECTIONAL",
|
||||
"DEFAULT_TITLE",
|
||||
"DEFAULT_PARAMS",
|
||||
"PROPERTY_METADATA",
|
||||
"validate_update",
|
||||
"use_item",
|
||||
]
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from . import module
|
||||
from ..plugin_helpers import build_item_module
|
||||
from . import actions, definition, validator
|
||||
|
||||
ITEM_TYPE_PLUGIN = {
|
||||
"type": "dice",
|
||||
"order": 20,
|
||||
"module": module,
|
||||
"module": build_item_module(definition, validate_update=validator.validate_update, use_item=actions.use_item),
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
"""Item type package exposing plugin module surface."""
|
||||
|
||||
from .module import * # noqa: F401,F403
|
||||
"""Piano item type plugin package."""
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
"""Piano item plugin module surface."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .actions import use_item
|
||||
from .definition import (
|
||||
CAPABILITIES,
|
||||
DEFAULT_PARAMS,
|
||||
DEFAULT_TITLE,
|
||||
DIRECTIONAL,
|
||||
EDITABLE_PROPERTIES,
|
||||
EMIT_RANGE,
|
||||
EMIT_SOUND,
|
||||
INSTRUMENT_OPTIONS,
|
||||
LABEL,
|
||||
PROPERTY_METADATA,
|
||||
TOOLTIP,
|
||||
USE_COOLDOWN_MS,
|
||||
USE_SOUND,
|
||||
VOICE_MODE_OPTIONS,
|
||||
)
|
||||
from .validator import validate_update
|
||||
|
||||
__all__ = [
|
||||
"LABEL",
|
||||
"TOOLTIP",
|
||||
"EDITABLE_PROPERTIES",
|
||||
"CAPABILITIES",
|
||||
"USE_SOUND",
|
||||
"EMIT_SOUND",
|
||||
"USE_COOLDOWN_MS",
|
||||
"EMIT_RANGE",
|
||||
"DIRECTIONAL",
|
||||
"DEFAULT_TITLE",
|
||||
"DEFAULT_PARAMS",
|
||||
"PROPERTY_METADATA",
|
||||
"INSTRUMENT_OPTIONS",
|
||||
"VOICE_MODE_OPTIONS",
|
||||
"validate_update",
|
||||
"use_item",
|
||||
]
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from . import module
|
||||
from ..plugin_helpers import build_item_module
|
||||
from . import actions, definition, validator
|
||||
|
||||
ITEM_TYPE_PLUGIN = {
|
||||
"type": "piano",
|
||||
"order": 30,
|
||||
"module": module,
|
||||
"module": build_item_module(definition, validate_update=validator.validate_update, use_item=actions.use_item),
|
||||
}
|
||||
|
||||
19
server/app/items/types/plugin_helpers.py
Normal file
19
server/app/items/types/plugin_helpers.py
Normal file
@@ -0,0 +1,19 @@
|
||||
"""Helpers for composing item plugin module surfaces."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
|
||||
def build_item_module(definition: Any, *, validate_update: Any, use_item: Any) -> Any:
|
||||
"""Compose a plugin module-like object from split definition/validator/actions files."""
|
||||
|
||||
exports: dict[str, Any] = {
|
||||
name: getattr(definition, name)
|
||||
for name in dir(definition)
|
||||
if name.isupper()
|
||||
}
|
||||
exports["validate_update"] = validate_update
|
||||
exports["use_item"] = use_item
|
||||
return SimpleNamespace(**exports)
|
||||
@@ -1,3 +1 @@
|
||||
"""Item type package exposing plugin module surface."""
|
||||
|
||||
from .module import * # noqa: F401,F403
|
||||
"""Radio station item type plugin package."""
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
"""Radio item plugin module surface."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .actions import use_item
|
||||
from .definition import (
|
||||
CAPABILITIES,
|
||||
CHANNEL_OPTIONS,
|
||||
DEFAULT_PARAMS,
|
||||
DEFAULT_TITLE,
|
||||
DIRECTIONAL,
|
||||
EDITABLE_PROPERTIES,
|
||||
EFFECT_OPTIONS,
|
||||
EMIT_RANGE,
|
||||
EMIT_SOUND,
|
||||
LABEL,
|
||||
PROPERTY_METADATA,
|
||||
TOOLTIP,
|
||||
USE_COOLDOWN_MS,
|
||||
USE_SOUND,
|
||||
)
|
||||
from .validator import validate_update
|
||||
|
||||
__all__ = [
|
||||
"LABEL",
|
||||
"TOOLTIP",
|
||||
"EDITABLE_PROPERTIES",
|
||||
"CAPABILITIES",
|
||||
"USE_SOUND",
|
||||
"EMIT_SOUND",
|
||||
"USE_COOLDOWN_MS",
|
||||
"EMIT_RANGE",
|
||||
"DIRECTIONAL",
|
||||
"DEFAULT_TITLE",
|
||||
"DEFAULT_PARAMS",
|
||||
"PROPERTY_METADATA",
|
||||
"CHANNEL_OPTIONS",
|
||||
"EFFECT_OPTIONS",
|
||||
"validate_update",
|
||||
"use_item",
|
||||
]
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from . import module
|
||||
from ..plugin_helpers import build_item_module
|
||||
from . import actions, definition, validator
|
||||
|
||||
ITEM_TYPE_PLUGIN = {
|
||||
"type": "radio_station",
|
||||
"order": 40,
|
||||
"module": module,
|
||||
"module": build_item_module(definition, validate_update=validator.validate_update, use_item=actions.use_item),
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
"""Item type package exposing plugin module surface."""
|
||||
|
||||
from .module import * # noqa: F401,F403
|
||||
"""Wheel item type plugin package."""
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
"""Wheel item plugin module surface."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .actions import use_item
|
||||
from .definition import (
|
||||
CAPABILITIES,
|
||||
DEFAULT_PARAMS,
|
||||
DEFAULT_TITLE,
|
||||
DIRECTIONAL,
|
||||
EDITABLE_PROPERTIES,
|
||||
EMIT_RANGE,
|
||||
EMIT_SOUND,
|
||||
LABEL,
|
||||
PROPERTY_METADATA,
|
||||
TOOLTIP,
|
||||
USE_COOLDOWN_MS,
|
||||
USE_SOUND,
|
||||
)
|
||||
from .validator import validate_update
|
||||
|
||||
__all__ = [
|
||||
"LABEL",
|
||||
"TOOLTIP",
|
||||
"EDITABLE_PROPERTIES",
|
||||
"CAPABILITIES",
|
||||
"USE_SOUND",
|
||||
"EMIT_SOUND",
|
||||
"USE_COOLDOWN_MS",
|
||||
"EMIT_RANGE",
|
||||
"DIRECTIONAL",
|
||||
"DEFAULT_TITLE",
|
||||
"DEFAULT_PARAMS",
|
||||
"PROPERTY_METADATA",
|
||||
"validate_update",
|
||||
"use_item",
|
||||
]
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from . import module
|
||||
from ..plugin_helpers import build_item_module
|
||||
from . import actions, definition, validator
|
||||
|
||||
ITEM_TYPE_PLUGIN = {
|
||||
"type": "wheel",
|
||||
"order": 50,
|
||||
"module": module,
|
||||
"module": build_item_module(definition, validate_update=validator.validate_update, use_item=actions.use_item),
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
"""Item type package exposing plugin module surface."""
|
||||
|
||||
from .module import * # noqa: F401,F403
|
||||
"""Widget item type plugin package."""
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
"""Widget item plugin module surface."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from .actions import use_item
|
||||
from .definition import (
|
||||
CAPABILITIES,
|
||||
DEFAULT_PARAMS,
|
||||
DEFAULT_TITLE,
|
||||
DIRECTIONAL,
|
||||
EDITABLE_PROPERTIES,
|
||||
EFFECT_OPTIONS,
|
||||
EMIT_RANGE,
|
||||
EMIT_SOUND,
|
||||
LABEL,
|
||||
PROPERTY_METADATA,
|
||||
TOOLTIP,
|
||||
USE_COOLDOWN_MS,
|
||||
USE_SOUND,
|
||||
)
|
||||
from .validator import validate_update
|
||||
|
||||
__all__ = [
|
||||
"LABEL",
|
||||
"TOOLTIP",
|
||||
"EDITABLE_PROPERTIES",
|
||||
"CAPABILITIES",
|
||||
"USE_SOUND",
|
||||
"EMIT_SOUND",
|
||||
"USE_COOLDOWN_MS",
|
||||
"EMIT_RANGE",
|
||||
"DIRECTIONAL",
|
||||
"DEFAULT_TITLE",
|
||||
"DEFAULT_PARAMS",
|
||||
"PROPERTY_METADATA",
|
||||
"EFFECT_OPTIONS",
|
||||
"validate_update",
|
||||
"use_item",
|
||||
]
|
||||
@@ -2,10 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from . import module
|
||||
from ..plugin_helpers import build_item_module
|
||||
from . import actions, definition, validator
|
||||
|
||||
ITEM_TYPE_PLUGIN = {
|
||||
"type": "widget",
|
||||
"order": 60,
|
||||
"module": module,
|
||||
"module": build_item_module(definition, validate_update=validator.validate_update, use_item=actions.use_item),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user