diff --git a/about.txt b/about.txt index 9f2f27f..371fee6 100644 --- a/about.txt +++ b/about.txt @@ -1,4 +1,7 @@ Version history: +1.17.13b - 29 April 2024 +• Fix: Quick & dirty fix of the import imp deprecation. + 1.17.13 - 19 July 2022 • Fix: Qt6 compatibility - Yet another enum issue. diff --git a/action.py b/action.py index 05e0cd2..84035f2 100644 --- a/action.py +++ b/action.py @@ -8,7 +8,7 @@ __copyright__ = '2013, Greg Riker , 2014-2020 additions by David Forrester ' __docformat__ = 'restructuredtext en' -import imp, inspect, os, re, sys, tempfile, threading, types +import importlib, inspect, os, re, sys, tempfile, threading, types # calibre Python 3 compatibility. try: @@ -877,7 +877,15 @@ def library_index_complete(self): self.library_indexed = True self.indexed_library = self.gui.current_db self.library_last_modified = self.gui.current_db.last_modified() - + + def load_module(self, module_name, filename): + loader = importlib.machinery.SourceFileLoader(module_name, filename) + module = types.ModuleType(loader.name) + module.__file__ = filename + sys.modules[module.__name__] = module + loader.exec_module(module) + return module + def load_dynamic_reader_classes(self): ''' Load reader classes dynamically from readers/ folder in plugin zip file @@ -900,7 +908,7 @@ def load_dynamic_reader_classes(self): with open(tmp_file, 'wb') as tf: tf.write(get_resources(rac)) self._log(" loading built-in class '%s'" % name) - imp.load_source(name, tmp_file) + self.load_module(name, tmp_file) os.remove(tmp_file) # Load locally defined classes specified in config file @@ -916,7 +924,7 @@ def load_dynamic_reader_classes(self): name = re.sub('_', '', name) self._log(" loading external class '%s'" % name) try: - imp.load_source(name, ac) + self.load_module(name, ac) except: # If additional_class fails to import, exit import traceback