From dc1c8b93b01a174b76d72409a7bb1c351d23322d Mon Sep 17 00:00:00 2001 From: Dany Date: Mon, 23 Oct 2023 13:14:16 +0200 Subject: [PATCH 1/2] Update plugin.py --- core/cat/mad_hatter/plugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/cat/mad_hatter/plugin.py b/core/cat/mad_hatter/plugin.py index fb254780..2a044081 100644 --- a/core/cat/mad_hatter/plugin.py +++ b/core/cat/mad_hatter/plugin.py @@ -2,8 +2,8 @@ import sys import json import glob -import importlib import traceback +import imp from typing import Dict from inspect import getmembers from pydantic import BaseModel @@ -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 = imp.load_source(module_name, py_file) 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}") From bde4de3af155578e180fdbf3ad15832865823ea9 Mon Sep 17 00:00:00 2001 From: Dany Date: Mon, 23 Oct 2023 14:16:52 +0200 Subject: [PATCH 2/2] Update plugin.py --- core/cat/mad_hatter/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/cat/mad_hatter/plugin.py b/core/cat/mad_hatter/plugin.py index 2a044081..c82b808e 100644 --- a/core/cat/mad_hatter/plugin.py +++ b/core/cat/mad_hatter/plugin.py @@ -3,7 +3,7 @@ import json import glob import traceback -import imp +from importlib import machinery from typing import Dict from inspect import getmembers from pydantic import BaseModel @@ -213,7 +213,7 @@ def _load_decorated_functions(self): # save a reference to decorated functions try: - plugin_module = imp.load_source(module_name, py_file) + 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)