scripts: Update to use exec_module() instead of load_module()
PATCH 1/1 scripts: Update to use exec_module() instead of load_module()
This is deprecated in python 3.12 and Fedora 35 is throwing warnings so move to the new functions.
Signed-off-by Richard Purdie <[email protected]>
--- scripts/lib/scriptutils.py | 4 +++- scripts/lib/wic/pluginbase.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-)
scripts/lib/scriptutils.py +3 -1
@@ -82,7 +82,9 @@ def load_plugins(logger, plugins, pluginpath): logger.debug('Loading plugin %s' % name) spec = importlib.machinery.PathFinder.find_spec(name, path=[pluginpath] ) if spec: - return spec.loader.load_module() + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod def plugin_name(filename): return os.path.splitext(os.path.basename(filename))[0]
scripts/lib/wic/pluginbase.py +4 -1
@@ -9,6 +9,7 @@ __all__ = ['ImagerPlugin', 'SourcePlugin'] import os import logging +import types from collections import defaultdict from importlib.machinery import SourceFileLoader
@@ -54,7 +55,9 @@ class PluginMgr: mname = fname[:-3] mpath = os.path.join(ppath, fname) logger.debug("loading plugin module %s", mpath) - SourceFileLoader(mname, mpath).load_module() + loader = SourceFileLoader(mname, mpath) + mod = types.ModuleType(loader.name) + loader.exec_module(mod) return PLUGINS.get(ptype)
Signature · 1 line
2.32.0