Skip to content

Commit

Permalink
Fix bug in handler.py causing the same plugin to be loaded multiple…
Browse files Browse the repository at this point in the history
… times
  • Loading branch information
Wrench56 committed Jul 8, 2024
1 parent 92e93bf commit c4e46d6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/backend/plugins/handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import Dict, Tuple, Optional

import importlib
import logging
Expand All @@ -7,11 +7,14 @@
from plugins import priority


_PLUGINS: List[Plugin] = []
_PLUGINS: Dict[str, Plugin] = {}


def load_all() -> None:
for plugin_name, prio in priority.fetch_plugins():
# Skip if plugin has already been loaded
if _PLUGINS.get(plugin_name) is not None:
continue
logging.info(f'Loading plugin "{plugin_name}" with priority {prio}')
plugin = load(plugin_name)
if plugin is not None:
Expand All @@ -22,8 +25,8 @@ def load(name: str) -> Optional[Plugin]:
try:
source = f'plugins.plugins.{name}.backend.main'
plugin: Plugin = importlib.import_module(source).init()
if plugin and plugin not in _PLUGINS:
_PLUGINS.append(plugin)
if plugin:
_PLUGINS[name] = plugin
return plugin
except TypeError:
# Abstract class (Plugin) does not implement methods like load & unload
Expand All @@ -38,5 +41,5 @@ def load(name: str) -> Optional[Plugin]:
return None


def get_plugin_names() -> List[str]:
return [plugin.name for plugin in _PLUGINS]
def get_plugin_names() -> Tuple[str, ...]:
return tuple(_PLUGINS.keys())

0 comments on commit c4e46d6

Please sign in to comment.