projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bt2: assign non-const version of field_class_variant_option_borrow_user_attributes...
[babeltrace.git]
/
src
/
bindings
/
python
/
bt2
/
bt2
/
py_plugin.py
diff --git
a/src/bindings/python/bt2/bt2/py_plugin.py
b/src/bindings/python/bt2/bt2/py_plugin.py
index b845030863ce224582406af5698e840a3d70465c..f1142766e3230152ef08acf458ba3069b58ebac7 100644
(file)
--- a/
src/bindings/python/bt2/bt2/py_plugin.py
+++ b/
src/bindings/python/bt2/bt2/py_plugin.py
@@
-21,23
+21,29
@@
# THE SOFTWARE.
from bt2 import utils
# THE SOFTWARE.
from bt2 import utils
-import bt2.component
+from bt2 import component as bt2_component
+import sys
+
+
+# Python plugin path to `_PluginInfo` (cache)
+_plugin_infos = {}
def plugin_component_class(component_class):
def plugin_component_class(component_class):
- if not issubclass(component_class, bt2
.
component._UserComponent):
+ if not issubclass(component_class, bt2
_
component._UserComponent):
raise TypeError('component class is not a subclass of a user component class')
component_class._bt_plugin_component_class = None
return component_class
raise TypeError('component class is not a subclass of a user component class')
component_class._bt_plugin_component_class = None
return component_class
-def register_plugin(module_name, name, description=None, author=None,
- license=None, version=None):
- import sys
-
+def register_plugin(
+ module_name, name, description=None, author=None, license=None, version=None
+):
if module_name not in sys.modules:
if module_name not in sys.modules:
- raise RuntimeError("cannot find module '{}' in loaded modules".format(module_name))
+ raise RuntimeError(
+ "cannot find module '{}' in loaded modules".format(module_name)
+ )
utils._check_str(name)
utils._check_str(name)
@@
-52,11
+58,13
@@
def register_plugin(module_name, name, description=None, author=None,
if version is not None:
if not _validate_version(version):
if version is not None:
if not _validate_version(version):
- raise ValueError('wrong version: expecting a tuple: (major, minor, patch) or (major, minor, patch, extra)')
+ raise ValueError(
+ 'wrong version: expecting a tuple: (major, minor, patch) or (major, minor, patch, extra)'
+ )
- sys.modules[module_name]._bt_plugin_info = _PluginInfo(
name, description,
- author, license,
-
version
)
+ sys.modules[module_name]._bt_plugin_info = _PluginInfo(
+ name, description, author, license, version
+ )
def _validate_version(version):
def _validate_version(version):
@@
-97,6
+105,10
@@
class _PluginInfo:
# called by the BT plugin system
def _try_load_plugin_module(path):
# called by the BT plugin system
def _try_load_plugin_module(path):
+ if path in _plugin_infos:
+ # do not load module and create plugin info twice for this path
+ return _plugin_infos[path]
+
import importlib.machinery
import inspect
import hashlib
import importlib.machinery
import inspect
import hashlib
@@
-110,7
+122,7
@@
def _try_load_plugin_module(path):
h = hashlib.sha256()
h.update(path.encode())
module_name = 'bt_plugin_{}'.format(h.hexdigest())
h = hashlib.sha256()
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 catched by the caller
mod = importlib.machinery.SourceFileLoader(module_name, path).load_module()
@@
-132,4
+144,5
@@
def _try_load_plugin_module(path):
comp_class_entries = inspect.getmembers(mod, is_user_comp_class)
plugin_info.comp_class_addrs = [entry[1].addr for entry in comp_class_entries]
comp_class_entries = inspect.getmembers(mod, is_user_comp_class)
plugin_info.comp_class_addrs = [entry[1].addr for entry in comp_class_entries]
+ _plugin_infos[path] = plugin_info
return plugin_info
return plugin_info
This page took
0.024132 seconds
and
4
git commands to generate.