Skip to content

Commit

Permalink
Update plugins on changes
Browse files Browse the repository at this point in the history
  • Loading branch information
druzsan committed Sep 11, 2023
1 parent 7f913e0 commit 3620f0f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions renumics/spotlight/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ def update(self, config: AppConfig) -> None:
self._broadcast(RefreshMessage())
self._update_issues()

for plugin in load_plugins():
plugin.update(self, config)

if not self._startup_complete:
self._startup_complete = True
self._connection.send({"kind": "startup_complete"})
Expand Down
4 changes: 4 additions & 0 deletions renumics/spotlight/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def generation_id(self) -> int:
def column_names(self) -> List[str]:
return self._data_source.column_names

@property
def data_source(self) -> DataSource:
return self._data_source

@property
def dtypes(self) -> DTypeMap:
return self._dtypes
Expand Down
18 changes: 8 additions & 10 deletions renumics/spotlight/plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
from dataclasses import dataclass
from types import ModuleType
from pathlib import Path
from typing import Callable, List, Optional
from typing import Any, Callable, List, Optional
from fastapi import FastAPI

from renumics.spotlight.settings import settings
from renumics.spotlight.develop.project import get_project_info
from renumics.spotlight.io.path import is_path_relative_to
from renumics.spotlight.app_config import AppConfig

import renumics.spotlight_plugins as plugins_namespace

Expand All @@ -28,6 +29,7 @@ class Plugin:
module: ModuleType
init: Callable[[], None]
activate: Callable[[FastAPI], None]
update: Callable[[FastAPI, AppConfig], None]
dev: bool
frontend_entrypoint: Optional[Path]

Expand All @@ -46,14 +48,9 @@ def load_plugins() -> List[Plugin]:
if _plugins is not None:
return _plugins

def noinit() -> None:
def noop(*_args: Any, **_kwargs: Any) -> None:
"""
noop impl for __init__
"""

def noactivate(_: FastAPI) -> None:
"""
noop impl for __activate__
noop impl for plugin hooks
"""

plugins = {}
Expand All @@ -73,8 +70,9 @@ def noactivate(_: FastAPI) -> None:
plugins[name] = Plugin(
name=name,
priority=getattr(module, "__priority__", 1000),
init=getattr(module, "__register__", noinit),
activate=getattr(module, "__activate__", noactivate),
init=getattr(module, "__register__", noop),
activate=getattr(module, "__activate__", noop),
update=getattr(module, "__update__", noop),
module=module,
dev=dev,
frontend_entrypoint=main_js if main_js.exists() else None,
Expand Down

0 comments on commit 3620f0f

Please sign in to comment.