[dunfell,1.46,1/2] utils: Update to use exec_module() instead of load_module()

Message ID 50aab1b733bc37c8f8c5517cc45bbfda24e8598c.1642082551.git.steve@sakoman.com
State Accepted, archived
Commit e84c9aa77b61e48f1507edcba7bde65295f4d3ad
Headers show
Series [dunfell,1.46,1/2] utils: Update to use exec_module() instead of load_module() | expand

Commit Message

Steve Sakoman Jan. 13, 2022, 2:10 p.m. UTC
From: Richard Purdie <richard.purdie@linuxfoundation.org>

This is deprecated in python 3.12 and Fedora 35 is throwing warnings so
move to the new functions.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 68a18fbcb5959e334cf307d7fa8dc63832edb942)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
---
 lib/bb/utils.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 5f5767c1..fab16ffc 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -16,7 +16,8 @@  import bb.msg
 import multiprocessing
 import fcntl
 import importlib
-from importlib import machinery
+import importlib.machinery
+import importlib.util
 import itertools
 import subprocess
 import glob
@@ -1584,7 +1585,9 @@  def load_plugins(logger, plugins, pluginpath):
         logger.debug(1, '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
 
     logger.debug(1, 'Loading plugins from %s...' % pluginpath)