Skip to content

Commit

Permalink
Merge pull request #518 from zAlweNy26/plugin_import
Browse files Browse the repository at this point in the history
Fix dynamic plugin import
  • Loading branch information
pieroit authored Oct 23, 2023
2 parents 14ecd36 + bde4de3 commit 1ca78eb
Showing 1 changed file with 5 additions and 5 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 @@ -2,8 +2,8 @@
import sys
import json
import glob
import importlib
import traceback
from importlib import machinery
from typing import Dict
from inspect import getmembers
from pydantic import BaseModel
Expand Down Expand Up @@ -207,18 +207,18 @@ def _load_decorated_functions(self):
plugin_overrides = []

for py_file in self.py_files:
py_filename = py_file.replace("/", ".").replace(".py", "") # this is UGLY I know. I'm sorry
module_name = os.path.splitext(os.path.basename(py_file))[0]

log.info(f"Import module {py_filename}")
log.info(f"Import module {py_file}")

# save a reference to decorated functions
try:
plugin_module = importlib.import_module(py_filename)
plugin_module = machinery.SourceFileLoader(module_name, py_file).load_module()
hooks += getmembers(plugin_module, self._is_cat_hook)
tools += getmembers(plugin_module, self._is_cat_tool)
plugin_overrides += getmembers(plugin_module, self._is_cat_plugin_override)
except Exception as e:
log.error(f"Error in {py_filename}: {str(e)}")
log.error(f"Error in {module_name}: {str(e)}")
traceback.print_exc()
raise Exception(f"Unable to load the plugin {self._id}")

Expand Down

0 comments on commit 1ca78eb

Please sign in to comment.