From f82dd763bd50affda993b9afe3b141069a1a7466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Tue, 23 Jul 2024 07:39:22 -0700 Subject: [PATCH 1/2] make tests compatible with Python 3.12 --- tests/test_scripts.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 6db3aac..b620cd9 100755 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -3,7 +3,21 @@ import sys import os from io import TextIOWrapper, BytesIO -from imp import load_source +import importlib.machinery +import importlib.util + + +# from https://docs.python.org/3.12/whatsnew/3.12.html#imp +def load_source(modname, filename): + loader = importlib.machinery.SourceFileLoader(modname, filename) + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) + module = importlib.util.module_from_spec(spec) + # The module is always executed and not cached in sys.modules. + # Uncomment the following line to cache the module. + # sys.modules[module.__name__] = module + loader.exec_module(module) + return module + pifc = load_source('pifc', 'scripts/pifconfig') peth = load_source('peth', 'scripts/pethtool') From b10c2a2face18c2761223120f82452bd02257d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Wed, 28 Aug 2024 14:00:01 -0700 Subject: [PATCH 2/2] retain test compatibility with Python 2 --- tests/test_scripts.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/test_scripts.py b/tests/test_scripts.py index b620cd9..dc6bc8c 100755 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -3,21 +3,23 @@ import sys import os from io import TextIOWrapper, BytesIO -import importlib.machinery -import importlib.util - - -# from https://docs.python.org/3.12/whatsnew/3.12.html#imp -def load_source(modname, filename): - loader = importlib.machinery.SourceFileLoader(modname, filename) - spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) - module = importlib.util.module_from_spec(spec) - # The module is always executed and not cached in sys.modules. - # Uncomment the following line to cache the module. - # sys.modules[module.__name__] = module - loader.exec_module(module) - return module +try: + from imp import load_source +except ImportError: + import importlib.machinery + import importlib.util + + # from https://docs.python.org/3.12/whatsnew/3.12.html#imp + def load_source(modname, filename): + loader = importlib.machinery.SourceFileLoader(modname, filename) + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) + module = importlib.util.module_from_spec(spec) + # The module is always executed and not cached in sys.modules. + # Uncomment the following line to cache the module. + # sys.modules[module.__name__] = module + loader.exec_module(module) + return module pifc = load_source('pifc', 'scripts/pifconfig') peth = load_source('peth', 'scripts/pethtool')