1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
From 568a00a3296d12cf3b2846c59bc99d13ecba7d47 Mon Sep 17 00:00:00 2001
From: Diego Garcia Gangl <dnicolas@gmail.com>
Date: Tue, 2 Jan 2024 20:59:23 -0300
Subject: [PATCH] Replace imp with importlib
Imp has been deprecated for a while and has recently been removed.
---
GTG/core/plugins/engine.py | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/GTG/core/plugins/engine.py b/GTG/core/plugins/engine.py
index 15794ade06..500462e26d 100644
--- a/GTG/core/plugins/engine.py
+++ b/GTG/core/plugins/engine.py
@@ -15,7 +15,9 @@
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
-import imp
+
+import importlib
+import inspect
import os
import logging
from gi.repository import GLib
@@ -101,15 +103,17 @@ def _load_module(self, module_paths):
"""Load the module containing this plugin."""
try:
# import the module containing the plugin
- f, pathname, desc = imp.find_module(self.module_name, module_paths)
- module = imp.load_module(self.module_name, f, pathname, desc)
- # find the class object for the actual plugin
- for key, item in module.__dict__.items():
- if isinstance(item, type):
- self.plugin_class = item
- self.class_name = item.__dict__['__module__'].split('.')[1]
- break
+ spec = importlib.machinery.PathFinder().find_spec(self.module_name, module_paths)
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+
+ classes = inspect.getmembers(mod, inspect.isclass)
+
+ self.class_name = classes[0][0]
+ self.plugin_class = classes[0][1]
+
except ImportError as e:
+ print(e)
# load_module() failed, probably because of a module dependency
if len(self.module_depends) > 0:
self._check_module_depends()
|