Skip to content

Commit

Permalink
feat: API level 3; API level check
Browse files Browse the repository at this point in the history
  • Loading branch information
gamecss committed Sep 9, 2023
1 parent 0440d6a commit 652a3a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/pyfsd/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from .service import PyFSDService


API_LEVEL = 3


class PluginHandledEventResult(TypedDict):
"""A result handled by plugin.
This means a plugin raised `pyfsd.plugin.PreventEvent`.
Expand Down Expand Up @@ -193,7 +196,7 @@ class BasePyFSDPlugin:
"""(A?)Base class of PyFSD Plugin."""

plugin_name = "<plugin name missing>"
api = 2
api = -1

def beforeStart(self, pyfsd: "PyFSDService", config: Optional[dict]) -> None:
...
Expand Down
17 changes: 14 additions & 3 deletions src/pyfsd/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
from .define.utils import iterCallable
from .factory.client import FSDClientFactory
from .metar.service import MetarService
from .plugin import BasePyFSDPlugin, IPyFSDPlugin, IServiceBuilder, PreventEvent
from .plugin import (
API_LEVEL,
BasePyFSDPlugin,
IPyFSDPlugin,
IServiceBuilder,
PreventEvent,
)

if TYPE_CHECKING:
from metar.Metar import Metar
Expand All @@ -49,7 +55,6 @@ def formatService(plugin: IServiceBuilder) -> str:
return f"{plugin.service_name} ({getfile(type(plugin))})"


MAX_API = BasePyFSDPlugin.api
PLUGIN_EVENTS = tuple(func.__name__ for func in iterCallable(BasePyFSDPlugin))
config: Optional[dict] = None

Expand Down Expand Up @@ -212,13 +217,19 @@ def pickPlugins(self) -> None:
plugin=formatPlugin(plugin),
)
else:
if plugin.api > MAX_API:
if not isinstance(plugin.api, int) or plugin.api > API_LEVEL:
self.logger.error(
"{plugin} needs API {api}, try update PyFSD",
api=plugin.api,
plugin=formatPlugin(plugin),
)
else:
if plugin.api != API_LEVEL:
self.logger.error(
"{plugin} using outdated API {api}, may cause some problem",
api=plugin.api,
plugin=formatPlugin(plugin),
)
all_plugins.append(plugin)
for event in PLUGIN_EVENTS:
if hasattr(plugin, event) and getattr(
Expand Down

0 comments on commit 652a3a3

Please sign in to comment.