From: Philippe Proulx Date: Wed, 24 Jul 2019 18:31:59 +0000 (-0400) Subject: bt2: import public names into `__init__.py` X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=5290f876138c2b71026bd2bbed78077b68cf961a bt2: import public names into `__init__.py` This patch updates `__init__.py.in` so that it imports exactly the names which we want to make public (available directly in the `bt2` package). Most public names which start with `_` exist to be able to test if a given object is an instance of that type, for example: if isinstance(val, bt2._IntegerValue): # do something with `val` knowing it's an integer value `bt2._Error` exists to catch it: try: # ... except bt2._Error as exc: # ... `bt2._User*` names exist to inherit them. Signed-off-by: Philippe Proulx Change-Id: I67c7bed00bdffcd0b1fe63603820ecbe2867ec7a Reviewed-on: https://review.lttng.org/c/babeltrace/+/1768 Tested-by: jenkins --- diff --git a/src/bindings/python/bt2/bt2/__init__.py.in b/src/bindings/python/bt2/bt2/__init__.py.in index 76e8e9b9..e4f01589 100644 --- a/src/bindings/python/bt2/bt2/__init__.py.in +++ b/src/bindings/python/bt2/bt2/__init__.py.in @@ -23,51 +23,95 @@ __version__ = '@PACKAGE_VERSION@' -from bt2.interrupter import * -from bt2.clock_class import * -from bt2.clock_snapshot import * -from bt2.component import * -from bt2.component import _FilterComponent +from bt2.clock_class import ClockClassOffset +from bt2.clock_snapshot import _ClockSnapshot +from bt2.clock_snapshot import _UnknownClockSnapshot +from bt2.component import _SourceComponentClass from bt2.component import _FilterComponentClass from bt2.component import _SinkComponentClass -from bt2.component import _SourceComponentClass -from bt2.component import _SinkComponent from bt2.component import _SourceComponent +from bt2.component import _FilterComponent +from bt2.component import _SinkComponent +from bt2.component import _UserSourceComponent from bt2.component import _UserFilterComponent from bt2.component import _UserSinkComponent -from bt2.component import _UserSourceComponent -from bt2.connection import * -from bt2.connection import _Connection -from bt2.error import * +from bt2.error import ComponentClassType +from bt2.error import _ErrorCause +from bt2.error import _ComponentErrorCause +from bt2.error import _ComponentClassErrorCause +from bt2.error import _MessageIteratorErrorCause from bt2.error import _Error -from bt2.event import _Event -from bt2.event_class import * -from bt2.field_class import * -from bt2.field_path import * -from bt2.field import * -from bt2.graph import * -from bt2.integer_range_set import * -from bt2.logging import * -from bt2.message import * +from bt2.event_class import EventClassLogLevel +from bt2.field import _IntegerField +from bt2.field import _UnsignedIntegerField +from bt2.field import _SignedIntegerField +from bt2.field import _RealField +from bt2.field import _EnumerationField +from bt2.field import _UnsignedEnumerationField +from bt2.field import _SignedEnumerationField +from bt2.field import _StringField +from bt2.field import _StructureField +from bt2.field import _VariantField +from bt2.field import _ArrayField +from bt2.field import _StaticArrayField +from bt2.field import _DynamicArrayField +from bt2.field_class import IntegerDisplayBase +from bt2.field_class import _IntegerFieldClass +from bt2.field_class import _UnsignedIntegerFieldClass +from bt2.field_class import _SignedIntegerFieldClass +from bt2.field_class import _RealFieldClass +from bt2.field_class import _EnumerationFieldClass +from bt2.field_class import _UnsignedEnumerationFieldClass +from bt2.field_class import _SignedEnumerationFieldClass +from bt2.field_class import _StringFieldClass +from bt2.field_class import _StructureFieldClass +from bt2.field_class import _VariantFieldClass +from bt2.field_class import _VariantFieldClassWithoutSelector +from bt2.field_class import _VariantFieldClassWithSelector +from bt2.field_class import _VariantFieldClassWithUnsignedSelector +from bt2.field_class import _VariantFieldClassWithSignedSelector +from bt2.field_class import _ArrayFieldClass +from bt2.field_class import _StaticArrayFieldClass +from bt2.field_class import _DynamicArrayFieldClass +from bt2.field_path import Scope +from bt2.field_path import _IndexFieldPathItem +from bt2.field_path import _CurrentArrayElementFieldPathItem +from bt2.graph import Graph +from bt2.integer_range_set import SignedIntegerRange +from bt2.integer_range_set import UnsignedIntegerRange +from bt2.integer_range_set import SignedIntegerRangeSet +from bt2.integer_range_set import UnsignedIntegerRangeSet +from bt2.interrupter import Interrupter +from bt2.logging import LoggingLevel +from bt2.logging import get_minimal_logging_level +from bt2.logging import get_global_logging_level +from bt2.logging import set_global_logging_level +from bt2.message import _EventMessage +from bt2.message import _PacketBeginningMessage +from bt2.message import _PacketEndMessage +from bt2.message import _StreamBeginningMessage +from bt2.message import _StreamEndMessage +from bt2.message import _MessageIteratorInactivityMessage from bt2.message import _DiscardedEventsMessage from bt2.message import _DiscardedPacketsMessage -from bt2.message import _EventMessage -from bt2.message_iterator import * from bt2.message_iterator import _UserMessageIterator -from bt2.packet import _Packet -from bt2.plugin import * -from bt2.port import * -from bt2.py_plugin import * -from bt2.query_executor import * -from bt2.stream import _Stream -from bt2.stream_class import * -from bt2.trace import * -from bt2.trace_class import * -from bt2.trace_collection_message_iterator import * -from bt2.value import * -from bt2.value import _Value +from bt2.plugin import find_plugins_in_path +from bt2.plugin import find_plugins +from bt2.plugin import find_plugin +from bt2.py_plugin import plugin_component_class +from bt2.py_plugin import register_plugin +from bt2.query_executor import QueryExecutor +from bt2.trace_collection_message_iterator import ComponentSpec +from bt2.trace_collection_message_iterator import TraceCollectionMessageIterator +from bt2.value import create_value +from bt2.value import BoolValue from bt2.value import _IntegerValue -from bt2.clock_snapshot import _UnknownClockSnapshot +from bt2.value import UnsignedIntegerValue +from bt2.value import SignedIntegerValue +from bt2.value import RealValue +from bt2.value import StringValue +from bt2.value import ArrayValue +from bt2.value import MapValue class _MemoryError(_Error): diff --git a/src/bindings/python/bt2/bt2/component.py b/src/bindings/python/bt2/bt2/component.py index 35574456..7a79666a 100644 --- a/src/bindings/python/bt2/bt2/component.py +++ b/src/bindings/python/bt2/bt2/component.py @@ -24,6 +24,7 @@ from bt2 import native_bt, object, utils import bt2.message_iterator import collections.abc import bt2.value +import bt2.trace_class import traceback import bt2.port import sys @@ -679,7 +680,7 @@ class _UserComponent(metaclass=_UserComponentType): if tc_ptr is None: raise bt2._MemoryError('could not create trace class') - tc = bt2._TraceClass._create_from_ptr(tc_ptr) + tc = bt2.trace_class._TraceClass._create_from_ptr(tc_ptr) tc._assigns_automatic_stream_class_id = assigns_automatic_stream_class_id return tc diff --git a/src/bindings/python/bt2/bt2/event.py b/src/bindings/python/bt2/bt2/event.py index c8a7d320..78179c5a 100644 --- a/src/bindings/python/bt2/bt2/event.py +++ b/src/bindings/python/bt2/bt2/event.py @@ -58,7 +58,7 @@ class _Event(object._UniqueObject): def stream(self): stream_ptr = native_bt.event_borrow_stream(self._ptr) assert stream_ptr is not None - return bt2._Stream._create_from_ptr_and_get_ref(stream_ptr) + return bt2.stream._Stream._create_from_ptr_and_get_ref(stream_ptr) @property def common_context_field(self): diff --git a/src/bindings/python/bt2/bt2/stream_class.py b/src/bindings/python/bt2/bt2/stream_class.py index 08186333..cda21864 100644 --- a/src/bindings/python/bt2/bt2/stream_class.py +++ b/src/bindings/python/bt2/bt2/stream_class.py @@ -23,6 +23,7 @@ from bt2 import native_bt, object, utils import bt2.field_class import bt2.event_class +import bt2.trace_class import collections.abc import bt2.stream import bt2 @@ -107,7 +108,7 @@ class _StreamClass(object._SharedObject, collections.abc.Mapping): tc_ptr = native_bt.stream_class_borrow_trace_class_const(self._ptr) if tc_ptr is not None: - return bt2._TraceClass._create_from_ptr_and_get_ref(tc_ptr) + return bt2.trace_class._TraceClass._create_from_ptr_and_get_ref(tc_ptr) @property def name(self): diff --git a/src/bindings/python/bt2/bt2/trace_class.py b/src/bindings/python/bt2/bt2/trace_class.py index 0acd7694..5c4da5c7 100644 --- a/src/bindings/python/bt2/bt2/trace_class.py +++ b/src/bindings/python/bt2/bt2/trace_class.py @@ -28,6 +28,7 @@ import bt2 from bt2 import native_bt, utils, object import bt2.stream_class import bt2.field_class +import bt2.trace import collections.abc import functools diff --git a/tests/bindings/python/bt2/test_connection.py b/tests/bindings/python/bt2/test_connection.py index 686a75f7..fc5c546e 100644 --- a/tests/bindings/python/bt2/test_connection.py +++ b/tests/bindings/python/bt2/test_connection.py @@ -44,7 +44,6 @@ class ConnectionTestCase(unittest.TestCase): src = graph.add_component(MySource, 'src') sink = graph.add_component(MySink, 'sink') conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) - self.assertIsInstance(conn, bt2._Connection) def test_downstream_port(self): class MyIter(bt2._UserMessageIterator):