Apply black code formatter on all Python code
[babeltrace.git] / src / bindings / python / bt2 / bt2 / graph.py
index 9e30c18f2645ccd45a9d4cf8e975402ffb4acf9a..1f280ba119ff4de691398980b9c4cd6e54f9eb2c 100644 (file)
@@ -29,28 +29,40 @@ import bt2.logging
 import bt2
 
 
-def _graph_port_added_listener_from_native(user_listener,
-                                           component_ptr, component_type,
-                                           port_ptr, port_type):
-    component = bt2.component._create_component_from_ptr_and_get_ref(component_ptr, component_type)
+def _graph_port_added_listener_from_native(
+    user_listener, component_ptr, component_type, port_ptr, port_type
+):
+    component = bt2.component._create_component_from_ptr_and_get_ref(
+        component_ptr, component_type
+    )
     port = bt2.port._create_from_ptr_and_get_ref(port_ptr, port_type)
     user_listener(component, port)
 
 
-def _graph_ports_connected_listener_from_native(user_listener,
-                                                upstream_component_ptr, upstream_component_type,
-                                                upstream_port_ptr,
-                                                downstream_component_ptr, downstream_component_type,
-                                                downstream_port_ptr):
+def _graph_ports_connected_listener_from_native(
+    user_listener,
+    upstream_component_ptr,
+    upstream_component_type,
+    upstream_port_ptr,
+    downstream_component_ptr,
+    downstream_component_type,
+    downstream_port_ptr,
+):
     upstream_component = bt2.component._create_component_from_ptr_and_get_ref(
-        upstream_component_ptr, upstream_component_type)
+        upstream_component_ptr, upstream_component_type
+    )
     upstream_port = bt2.port._create_from_ptr_and_get_ref(
-        upstream_port_ptr, native_bt.PORT_TYPE_OUTPUT)
+        upstream_port_ptr, native_bt.PORT_TYPE_OUTPUT
+    )
     downstream_component = bt2.component._create_component_from_ptr_and_get_ref(
-        downstream_component_ptr, downstream_component_type)
+        downstream_component_ptr, downstream_component_type
+    )
     downstream_port = bt2.port._create_from_ptr_and_get_ref(
-        downstream_port_ptr, native_bt.PORT_TYPE_INPUT)
-    user_listener(upstream_component, upstream_port, downstream_component, downstream_port)
+        downstream_port_ptr, native_bt.PORT_TYPE_INPUT
+    )
+    user_listener(
+        upstream_component, upstream_port, downstream_component, downstream_port
+    )
 
 
 class Graph(object._SharedObject):
@@ -65,9 +77,13 @@ class Graph(object._SharedObject):
 
         super().__init__(ptr)
 
-
-    def add_component(self, component_class, name, params=None,
-                      logging_level=bt2.logging.LoggingLevel.NONE):
+    def add_component(
+        self,
+        component_class,
+        name,
+        params=None,
+        logging_level=bt2.logging.LoggingLevel.NONE,
+    ):
         if isinstance(component_class, bt2.component._GenericSourceComponentClass):
             cc_ptr = component_class._ptr
             add_fn = native_bt.graph_add_source_component
@@ -93,8 +109,11 @@ class Graph(object._SharedObject):
             add_fn = native_bt.graph_add_filter_component
             cc_type = native_bt.COMPONENT_CLASS_TYPE_FILTER
         else:
-            raise TypeError("'{}' is not a component class".format(
-                component_class.__class__.__name__))
+            raise TypeError(
+                "'{}' is not a component class".format(
+                    component_class.__class__.__name__
+                )
+            )
 
         utils._check_str(name)
         utils._check_log_level(logging_level)
@@ -102,8 +121,7 @@ class Graph(object._SharedObject):
 
         params_ptr = params._ptr if params is not None else None
 
-        status, comp_ptr = add_fn(self._ptr, cc_ptr, name,
-                                  params_ptr, logging_level)
+        status, comp_ptr = add_fn(self._ptr, cc_ptr, name, params_ptr, logging_level)
         utils._handle_func_status(status, 'cannot add component to graph')
         assert comp_ptr
         return bt2.component._create_component_from_ptr(comp_ptr, cc_type)
@@ -111,12 +129,11 @@ class Graph(object._SharedObject):
     def connect_ports(self, upstream_port, downstream_port):
         utils._check_type(upstream_port, bt2.port._OutputPort)
         utils._check_type(downstream_port, bt2.port._InputPort)
-        status, conn_ptr = native_bt.graph_connect_ports(self._ptr,
-                                                         upstream_port._ptr,
-                                                         downstream_port._ptr)
-        utils._handle_func_status(status,
-                                  'cannot connect component ports within graph')
-        assert(conn_ptr)
+        status, conn_ptr = native_bt.graph_connect_ports(
+            self._ptr, upstream_port._ptr, downstream_port._ptr
+        )
+        utils._handle_func_status(status, 'cannot connect component ports within graph')
+        assert conn_ptr
         return bt2.connection._Connection._create_from_ptr(conn_ptr)
 
     def add_port_added_listener(self, listener):
@@ -124,8 +141,9 @@ class Graph(object._SharedObject):
             raise TypeError("'listener' parameter is not callable")
 
         fn = native_bt.bt2_graph_add_port_added_listener
-        listener_from_native = functools.partial(_graph_port_added_listener_from_native,
-                                                 listener)
+        listener_from_native = functools.partial(
+            _graph_port_added_listener_from_native, listener
+        )
 
         listener_ids = fn(self._ptr, listener_from_native)
         if listener_ids is None:
@@ -137,8 +155,9 @@ class Graph(object._SharedObject):
             raise TypeError("'listener' parameter is not callable")
 
         fn = native_bt.bt2_graph_add_ports_connected_listener
-        listener_from_native = functools.partial(_graph_ports_connected_listener_from_native,
-                                                 listener)
+        listener_from_native = functools.partial(
+            _graph_ports_connected_listener_from_native, listener
+        )
 
         listener_ids = fn(self._ptr, listener_from_native)
         if listener_ids is None:
@@ -149,8 +168,9 @@ class Graph(object._SharedObject):
         status = native_bt.graph_run(self._ptr)
 
         try:
-            utils._handle_func_status(status,
-                                      'graph object stopped running because of an unexpected error')
+            utils._handle_func_status(
+                status, 'graph object stopped running because of an unexpected error'
+            )
         except bt2.Stop:
             # done
             return
@@ -164,12 +184,14 @@ class Graph(object._SharedObject):
     @property
     def is_canceled(self):
         is_canceled = native_bt.graph_is_canceled(self._ptr)
-        assert(is_canceled >= 0)
+        assert is_canceled >= 0
         return is_canceled > 0
 
     def create_output_port_message_iterator(self, output_port):
         utils._check_type(output_port, bt2.port._OutputPort)
-        msg_iter_ptr = native_bt.port_output_message_iterator_create(self._ptr, output_port._ptr)
+        msg_iter_ptr = native_bt.port_output_message_iterator_create(
+            self._ptr, output_port._ptr
+        )
 
         if msg_iter_ptr is None:
             raise bt2.CreationError('cannot create output port message iterator')
This page took 0.026597 seconds and 4 git commands to generate.