Skip to content

Commit

Permalink
Fix plugin settings loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Pingdred committed Oct 18, 2023
1 parent 2859a3d commit 4b627d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
10 changes: 5 additions & 5 deletions core/cat/mad_hatter/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from cat.mad_hatter.decorators import CatTool, CatHook, CatPluginOverride
from cat.utils import to_camel_case
from cat.log import log, get_log_level
from cat.log import log


# Empty class to represent basic plugin Settings model
Expand Down Expand Up @@ -83,7 +83,7 @@ def deactivate(self):
# get plugin settings JSON schema
def settings_schema(self):

# is "plugin_settings_schema" hook defined in the plugin?
# is "settings_schema" hook defined in the plugin?
for h in self._plugin_overrides:
if h.name == "settings_schema":
return h.function()
Expand All @@ -94,7 +94,7 @@ def settings_schema(self):
# load plugin settings
def load_settings(self):

# is "plugin_settings_load" hook defined in the plugin?
# is "settings_load" hook defined in the plugin?
for h in self._plugin_overrides:
if h.name == "load_settings":
return h.function()
Expand All @@ -114,13 +114,14 @@ def load_settings(self):
except Exception as e:
log.error(f"Unable to load plugin {self._id} settings")
log.error(e)
raise e

return settings

# save plugin settings
def save_settings(self, settings: Dict):

# is "plugin_settings_save" hook defined in the plugin?
# is "settings_save" hook defined in the plugin?
for h in self._plugin_overrides:
if h.name == "save_settings":
return h.function(settings)
Expand Down Expand Up @@ -182,7 +183,6 @@ def _install_requirements(self):
log.info(f"Installing requirements for: {self.id}")
os.system(f'pip install --no-cache-dir -r "{req_file}"')


# lists of hooks and tools
def _load_decorated_functions(self):
hooks = []
Expand Down
21 changes: 12 additions & 9 deletions core/cat/routes/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,18 @@ async def get_plugins_settings(request: Request) -> Dict:

# plugins are managed by the MadHatter class
for plugin in ccat.mad_hatter.plugins.values():
plugin_settings = plugin.load_settings()
plugin_schema = plugin.settings_schema()
if plugin_schema['properties'] == {}:
plugin_schema = {}
settings.append({
"name": plugin.id,
"value": plugin_settings,
"schema": plugin_schema
})
try:
plugin_settings = plugin.load_settings()
plugin_schema = plugin.settings_schema()
if plugin_schema['properties'] == {}:
plugin_schema = {}
settings.append({
"name": plugin.id,
"value": plugin_settings,
"schema": plugin_schema
})
except:
log.error(f"Error loading {plugin} settings")

return {
"settings": settings,
Expand Down

0 comments on commit 4b627d7

Please sign in to comment.