Fix typos
[babeltrace.git] / src / bindings / python / bt2 / bt2 / py_plugin.py
index 6f067e8b4d59c4e794362372a05ccf8f008393ec..2a7414bb5c415f6212a851263f08a2c2de2637f7 100644 (file)
@@ -2,10 +2,10 @@
 #
 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
 
-from bt2 import utils
-from bt2 import component as bt2_component
 import sys
 
+from bt2 import utils as bt2_utils
+from bt2 import component as bt2_component
 
 # Python plugin path to `_PluginInfo` (cache)
 _plugin_infos = {}
@@ -27,16 +27,16 @@ def register_plugin(
             "cannot find module '{}' in loaded modules".format(module_name)
         )
 
-    utils._check_str(name)
+    bt2_utils._check_str(name)
 
     if description is not None:
-        utils._check_str(description)
+        bt2_utils._check_str(description)
 
     if author is not None:
-        utils._check_str(author)
+        bt2_utils._check_str(author)
 
     if license is not None:
-        utils._check_str(license)
+        bt2_utils._check_str(license)
 
     if version is not None:
         if not _validate_version(version):
@@ -91,9 +91,9 @@ def _try_load_plugin_module(path):
         # do not load module and create plugin info twice for this path
         return _plugin_infos[path]
 
-    import importlib.machinery
-    import inspect
     import hashlib
+    import inspect
+    import importlib.machinery
 
     if path is None:
         raise TypeError("missing path")
@@ -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()
+
+    # try loading the module: any raised exception is caught by the caller
+    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.037793 seconds and 4 git commands to generate.