From d680d82284d33027d93b36496f9e5c8e78432762 Mon Sep 17 00:00:00 2001 From: Eduard Korchmar Date: Thu, 9 May 2024 18:37:44 +0200 Subject: [PATCH 1/2] Use importlib instead of deprecated imp for Py3.12 Introduces a fork in import logic depending on version, choosing different manual import mechanic --- pacgraph-tk | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pacgraph-tk b/pacgraph-tk index 24831df..cd47329 100755 --- a/pacgraph-tk +++ b/pacgraph-tk @@ -8,9 +8,21 @@ from multiprocessing import Process import sys, threading, queue, time if not dev: - import imp - imp.load_source('pacgraph', '/usr/bin/pacgraph') -import pacgraph + module_name = 'pacgraph' + module_path = '/usr/bin/pacgraph' + if sys.version_info[1] >= 12: + import importlib.util + import importlib.machinery + loader = importlib.machinery.SourceFileLoader(module_name, module_path) + spec = importlib.util.spec_from_loader(module_name, loader) + if spec is None: + raise ImportError(f'Failed to load pacgraph module at {module_path}') + pacgraph = importlib.util.module_from_spec(spec) + loader.exec_module(pacgraph) + else: + import imp + imp.load_source(module_name, module_path) + import pacgraph colors = {'sel' : '#000', 'uns' : '#888', From 7f8280d5a888507902919d0ee9bb4668a9250044 Mon Sep 17 00:00:00 2001 From: Eduard Korchmar Date: Thu, 9 May 2024 18:57:28 +0200 Subject: [PATCH 2/2] Explicitly check major version for import logic Just in case it will be important in the future --- pacgraph-tk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pacgraph-tk b/pacgraph-tk index cd47329..50e2aff 100755 --- a/pacgraph-tk +++ b/pacgraph-tk @@ -10,7 +10,7 @@ import sys, threading, queue, time if not dev: module_name = 'pacgraph' module_path = '/usr/bin/pacgraph' - if sys.version_info[1] >= 12: + if sys.version_info[0] >= 3 and sys.version_info[1] >= 12: import importlib.util import importlib.machinery loader = importlib.machinery.SourceFileLoader(module_name, module_path)