python: run isort on everything
[babeltrace.git] / src / bindings / python / bt2 / bt2 / plugin.py
index 597f38f24e8f3405990b91fa7eebb17821e70df1..0c9906679125773f3d449e9ff4396d60c041be84 100644 (file)
@@ -1,36 +1,20 @@
-# The MIT License (MIT)
+# SPDX-License-Identifier: MIT
 #
 # Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-from bt2 import native_bt, object, utils
-import collections.abc
-import bt2.component
+
 import os.path
-import bt2
+import collections.abc
+
+from bt2 import utils as bt2_utils
+from bt2 import object as bt2_object
+from bt2 import component as bt2_component
+from bt2 import native_bt
 
 
 def find_plugins_in_path(path, recurse=True, fail_on_load_error=False):
-    utils._check_str(path)
-    utils._check_bool(recurse)
-    utils._check_bool(fail_on_load_error)
+    bt2_utils._check_str(path)
+    bt2_utils._check_bool(recurse)
+    bt2_utils._check_bool(fail_on_load_error)
     plugin_set_ptr = None
 
     if os.path.isfile(path):
@@ -47,7 +31,7 @@ def find_plugins_in_path(path, recurse=True, fail_on_load_error=False):
     if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND:
         return
 
-    utils._handle_func_status(status, 'failed to find plugins')
+    bt2_utils._handle_func_status(status, "failed to find plugins")
     assert plugin_set_ptr is not None
     return _PluginSet._create_from_ptr(plugin_set_ptr)
 
@@ -59,11 +43,11 @@ def find_plugins(
     find_in_static=True,
     fail_on_load_error=False,
 ):
-    utils._check_bool(find_in_std_env_var)
-    utils._check_bool(find_in_user_dir)
-    utils._check_bool(find_in_sys_dir)
-    utils._check_bool(find_in_static)
-    utils._check_bool(fail_on_load_error)
+    bt2_utils._check_bool(find_in_std_env_var)
+    bt2_utils._check_bool(find_in_user_dir)
+    bt2_utils._check_bool(find_in_sys_dir)
+    bt2_utils._check_bool(find_in_static)
+    bt2_utils._check_bool(fail_on_load_error)
     plugin_set_ptr = None
 
     status, plugin_set_ptr = native_bt.bt2_plugin_find_all(
@@ -77,7 +61,7 @@ def find_plugins(
     if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND:
         return
 
-    utils._handle_func_status(status, 'failed to find plugins')
+    bt2_utils._handle_func_status(status, "failed to find plugins")
     assert plugin_set_ptr is not None
     return _PluginSet._create_from_ptr(plugin_set_ptr)
 
@@ -90,8 +74,8 @@ def find_plugin(
     find_in_static=True,
     fail_on_load_error=False,
 ):
-    utils._check_str(name)
-    utils._check_bool(fail_on_load_error)
+    bt2_utils._check_str(name)
+    bt2_utils._check_bool(fail_on_load_error)
     status, ptr = native_bt.bt2_plugin_find(
         name,
         int(find_in_std_env_var),
@@ -104,14 +88,19 @@ def find_plugin(
     if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND:
         return
 
-    utils._handle_func_status(status, 'failed to find plugin')
+    bt2_utils._handle_func_status(status, "failed to find plugin")
     assert ptr is not None
     return _Plugin._create_from_ptr(ptr)
 
 
-class _PluginSet(object._SharedObject, collections.abc.Sequence):
-    _put_ref = staticmethod(native_bt.plugin_set_put_ref)
-    _get_ref = staticmethod(native_bt.plugin_set_get_ref)
+class _PluginSet(bt2_object._SharedObject, collections.abc.Sequence):
+    @staticmethod
+    def _put_ref(ptr):
+        native_bt.plugin_set_put_ref(ptr)
+
+    @staticmethod
+    def _get_ref(ptr):
+        native_bt.plugin_set_get_ref(ptr)
 
     def __len__(self):
         count = native_bt.plugin_set_get_plugin_count(self._ptr)
@@ -119,7 +108,7 @@ class _PluginSet(object._SharedObject, collections.abc.Sequence):
         return count
 
     def __getitem__(self, index):
-        utils._check_uint64(index)
+        bt2_utils._check_uint64(index)
 
         if index >= len(self):
             raise IndexError
@@ -153,12 +142,12 @@ class _PluginVersion:
         return self._extra
 
     def __str__(self):
-        extra = ''
+        extra = ""
 
         if self._extra is not None:
             extra = self._extra
 
-        return '{}.{}.{}{}'.format(self._major, self._minor, self._patch, extra)
+        return "{}.{}.{}{}".format(self._major, self._minor, self._patch, extra)
 
 
 class _PluginComponentClassesIterator(collections.abc.Iterator):
@@ -180,7 +169,7 @@ class _PluginComponentClassesIterator(collections.abc.Iterator):
         self._at += 1
 
         comp_cls_type = self._plugin_comp_cls._comp_cls_type
-        comp_cls_pycls = bt2.component._COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS[
+        comp_cls_pycls = bt2_component._COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS[
             comp_cls_type
         ]
         comp_cls_ptr = comp_cls_pycls._bt_as_component_class_ptr(comp_cls_ptr)
@@ -194,13 +183,13 @@ class _PluginComponentClasses(collections.abc.Mapping):
         self._plugin = plugin
 
     def __getitem__(self, key):
-        utils._check_str(key)
+        bt2_utils._check_str(key)
         cc_ptr = self._borrow_component_class_by_name(self._plugin._ptr, key)
 
         if cc_ptr is None:
             raise KeyError(key)
 
-        return bt2.component._create_component_class_from_ptr_and_get_ref(
+        return bt2_component._create_component_class_from_const_ptr_and_get_ref(
             cc_ptr, self._comp_cls_type
         )
 
@@ -250,9 +239,14 @@ class _PluginSinkComponentClasses(_PluginComponentClasses):
     _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SINK
 
 
-class _Plugin(object._SharedObject):
-    _put_ref = staticmethod(native_bt.plugin_put_ref)
-    _get_ref = staticmethod(native_bt.plugin_get_ref)
+class _Plugin(bt2_object._SharedObject):
+    @staticmethod
+    def _put_ref(ptr):
+        native_bt.plugin_put_ref(ptr)
+
+    @staticmethod
+    def _get_ref(ptr):
+        native_bt.plugin_get_ref(ptr)
 
     @property
     def name(self):
This page took 0.02525 seconds and 4 git commands to generate.