fix: 'load_module()' deprecated in Python 3.12
[babeltrace.git] / src / bindings / python / bt2 / bt2 / py_plugin.py
index 5702a2fe38f20f7a94c23d5e295002f15deaa83d..223615a55190d86323c15edf71d60b461b996c80 100644 (file)
@@ -105,8 +105,18 @@ def _try_load_plugin_module(path):
     h.update(path.encode())
     module_name = "bt_plugin_{}".format(h.hexdigest())
     assert module_name not in sys.modules
+
     # try loading the module: any raised exception is catched by the caller
-    mod = importlib.machinery.SourceFileLoader(module_name, path).load_module()
+    if sys.version_info < (3, 5):
+        mod = importlib.machinery.SourceFileLoader(module_name, path).load_module()
+    else:
+        import importlib.util
+
+        loader = importlib.machinery.SourceFileLoader(module_name, path)
+        spec = importlib.util.spec_from_file_location(module_name, path, loader=loader)
+        mod = importlib.util.module_from_spec(spec)
+        sys.modules[mod.__name__] = mod
+        loader.exec_module(mod)
 
     # we have the module: look for its plugin info first
     if not hasattr(mod, "_bt_plugin_info"):
This page took 0.025381 seconds and 4 git commands to generate.