From 162e98623f1bc7df72d5f9f8e486024e52edd1e0 Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Thu, 9 Feb 2023 01:51:40 -0600 Subject: [PATCH 1/3] Add protocol serialization --- runtimepy/codec/protocol/base.py | 3 +++ runtimepy/codec/protocol/json.py | 24 +++++++++++++++++++++++- tests/codec/test_protocol.py | 7 +++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/runtimepy/codec/protocol/base.py b/runtimepy/codec/protocol/base.py index af2a9d19..5ec83a91 100644 --- a/runtimepy/codec/protocol/base.py +++ b/runtimepy/codec/protocol/base.py @@ -62,9 +62,12 @@ def __init__( names: _NameRegistry = None, fields: BitFieldsManager = None, build: _List[_Union[int, FieldSpec]] = None, + identifier: int = 1, ) -> None: """Initialize this protocol.""" + self.id = identifier + # Each instance gets its own array. self.array = PrimitiveArray() diff --git a/runtimepy/codec/protocol/json.py b/runtimepy/codec/protocol/json.py index 9acd5329..3b1ba4d7 100644 --- a/runtimepy/codec/protocol/json.py +++ b/runtimepy/codec/protocol/json.py @@ -3,6 +3,8 @@ """ # built-in +from json import dumps as _dumps +from typing import BinaryIO as _BinaryIO from typing import Dict as _Dict from typing import List as _List from typing import Set as _Set @@ -25,18 +27,32 @@ ) BUILD_KEY = "build" +META_KEY = "meta" T = _TypeVar("T", bound="JsonProtocol") class JsonProtocol(ProtocolBase): """A class for defining runtime communication protocols.""" + def meta_str(self, resolve_enum: bool = True) -> str: + """Get protocol metadata as a string..""" + return _dumps(self.export_json(resolve_enum=resolve_enum)) + + def meta_bytes(self, resolve_enum: bool = True) -> bytes: + """Get protocol metadata as a bytes object.""" + return self.meta_str(resolve_enum=resolve_enum).encode() + + def write_meta(self, stream: _BinaryIO, resolve_enum: bool = True) -> int: + """Write protocol metadata to a stream.""" + return stream.write(self.meta_bytes(resolve_enum=resolve_enum)) + def export_json( self, resolve_enum: bool = True ) -> _Dict[str, _JsonObject]: """Export this protocol's data to JSON.""" data = self._fields.export_json(resolve_enum=resolve_enum) + data[META_KEY] = {"id": self.id} # Export regular-field names. json_obj = data[NAMES_KEY] @@ -101,7 +117,13 @@ def import_json(cls: _Type[T], data: _Dict[str, _JsonObject]) -> T: ) ) - result = cls(fields.enums, fields.registry, fields=fields, build=build) + result = cls( + fields.enums, + fields.registry, + fields=fields, + build=build, + identifier=_cast(int, data[META_KEY]["id"]), + ) # Set values. for name, value in values.items(): diff --git a/tests/codec/test_protocol.py b/tests/codec/test_protocol.py index b9523f3a..ee5a059b 100644 --- a/tests/codec/test_protocol.py +++ b/tests/codec/test_protocol.py @@ -4,6 +4,8 @@ # built-in from copy import copy +from io import BytesIO +from json import load # module under test from runtimepy.codec.protocol import Protocol @@ -53,3 +55,8 @@ def test_protocol_basic(): new_proto = Protocol.import_json(proto.export_json()) assert new_proto["test1"] == 40 assert proto["flag1"] == "valve_open" + + with BytesIO() as stream: + assert proto.write_meta(stream) + stream.seek(0) + assert Protocol.import_json(load(stream)) From d3dc37297d11ba6d211fa87a960a7035eb86a47e Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Thu, 9 Feb 2023 02:29:57 -0600 Subject: [PATCH 2/3] Add initial message-type enum --- README.md | 6 +- im/pydeps.svg | 2608 ++++++++++++++++------------- local/variables/package.yaml | 4 +- pyproject.toml | 2 +- runtimepy/__init__.py | 4 +- runtimepy/enum/__init__.py | 19 + runtimepy/enum/registry.py | 17 + runtimepy/telemetry/__init__.py | 13 + tests/enum/test_enum.py | 26 + tests/telemetry/__init__.py | 0 tests/telemetry/test_telemetry.py | 20 + 11 files changed, 1585 insertions(+), 1134 deletions(-) create mode 100644 runtimepy/telemetry/__init__.py create mode 100644 tests/enum/test_enum.py create mode 100644 tests/telemetry/__init__.py create mode 100644 tests/telemetry/test_telemetry.py diff --git a/README.md b/README.md index 1d13c362..04f77c49 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ===================================== generator=datazen version=3.1.0 - hash=edfe0b431e5e5c87a6a1e84b9e3a12f6 + hash=a8255694100a058fa4413abe0341a123 ===================================== --> -# runtimepy ([0.12.3](https://pypi.org/project/runtimepy/)) +# runtimepy ([0.13.0](https://pypi.org/project/runtimepy/)) [![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/) ![Build Status](https://github.com/vkottler/runtimepy/workflows/Python%20Package/badge.svg) @@ -41,7 +41,7 @@ This package is tested on the following platforms: # Command-line Options ``` -$ ./venv3.7/bin/runtimepy -h +$ ./venv3.8/bin/runtimepy -h usage: runtimepy [-h] [--version] [-v] [-C DIR] {tui,noop} ... diff --git a/im/pydeps.svg b/im/pydeps.svg index ae2d7670..6b9513f0 100644 --- a/im/pydeps.svg +++ b/im/pydeps.svg @@ -1,1770 +1,2126 @@ - - - + + G - + -runtimepy___main__ - -runtimepy. -__main__ + +runtimepy___main__ + +runtimepy. +__main__ -runtimepy_app - -runtimepy.app + +runtimepy_app + +runtimepy.app -runtimepy_entry - -runtimepy. -entry + +runtimepy_entry + +runtimepy. +entry -runtimepy_app->runtimepy_entry - - + +runtimepy_app->runtimepy_entry + + -runtimepy_channel - -runtimepy. -channel + +runtimepy_channel + +runtimepy. +channel -runtimepy_commands_tui - -runtimepy. -commands. -tui + +runtimepy_commands_tui + +runtimepy. +commands. +tui -runtimepy_channel->runtimepy_commands_tui - - + +runtimepy_channel->runtimepy_commands_tui + -runtimepy_task - -runtimepy.task + +runtimepy_task + +runtimepy.task -runtimepy_channel->runtimepy_task - - - + +runtimepy_channel->runtimepy_task + + + -runtimepy_tui_channels - -runtimepy. -tui. -channels + +runtimepy_tui_channels + +runtimepy. +tui. +channels -runtimepy_channel->runtimepy_tui_channels - - + +runtimepy_channel->runtimepy_tui_channels + + -runtimepy_tui_task - -runtimepy. -tui. -task + +runtimepy_tui_task + +runtimepy. +tui. +task -runtimepy_channel->runtimepy_tui_task - - - + +runtimepy_channel->runtimepy_tui_task + + -runtimepy_channel_environment - -runtimepy. -channel. -environment + +runtimepy_channel_environment + +runtimepy. +channel. +environment -runtimepy_channel_environment->runtimepy_commands_tui - - - - - + +runtimepy_channel_environment->runtimepy_commands_tui + + -runtimepy_channel_environment->runtimepy_task - - + +runtimepy_channel_environment->runtimepy_task + + -runtimepy_channel_environment->runtimepy_tui_channels - - - + +runtimepy_channel_environment->runtimepy_tui_channels + + -runtimepy_channel_environment->runtimepy_tui_task - - + +runtimepy_channel_environment->runtimepy_tui_task + + -runtimepy_channel_environment_array - -runtimepy. -channel. -environment. -array + +runtimepy_channel_environment_array + +runtimepy. +channel. +environment. +array -runtimepy_channel_environment_array->runtimepy_channel_environment - - + +runtimepy_channel_environment_array->runtimepy_channel_environment + + -runtimepy_channel_environment_base - -runtimepy. -channel. -environment. -base + +runtimepy_channel_environment_base + +runtimepy. +channel. +environment. +base -runtimepy_channel_environment_base->runtimepy_channel_environment_array - - + +runtimepy_channel_environment_base->runtimepy_channel_environment_array + + -runtimepy_channel_environment_create - -runtimepy. -channel. -environment. -create + +runtimepy_channel_environment_create + +runtimepy. +channel. +environment. +create -runtimepy_channel_environment_base->runtimepy_channel_environment_create - - + +runtimepy_channel_environment_base->runtimepy_channel_environment_create + + -runtimepy_channel_environment_file - -runtimepy. -channel. -environment. -file + +runtimepy_channel_environment_file + +runtimepy. +channel. +environment. +file -runtimepy_channel_environment_base->runtimepy_channel_environment_file - - + +runtimepy_channel_environment_base->runtimepy_channel_environment_file + + -runtimepy_channel_environment_names - -runtimepy. -channel. -environment. -names + +runtimepy_channel_environment_names + +runtimepy. +channel. +environment. +names -runtimepy_channel_environment_base->runtimepy_channel_environment_names - - + +runtimepy_channel_environment_base->runtimepy_channel_environment_names + + -runtimepy_channel_environment_create->runtimepy_channel_environment - - + +runtimepy_channel_environment_create->runtimepy_channel_environment + + -runtimepy_channel_environment_file->runtimepy_channel_environment - - + +runtimepy_channel_environment_file->runtimepy_channel_environment + + -runtimepy_channel_environment_names->runtimepy_channel_environment - - + +runtimepy_channel_environment_names->runtimepy_channel_environment + + -runtimepy_channel_registry - -runtimepy. -channel. -registry + +runtimepy_channel_registry + +runtimepy. +channel. +registry -runtimepy_channel_registry->runtimepy_channel_environment_base - - + +runtimepy_channel_registry->runtimepy_channel_environment_base + + + -runtimepy_channel_registry->runtimepy_channel_environment_file - - - - + +runtimepy_channel_registry->runtimepy_channel_environment_file + + -runtimepy_codec_protocol - -runtimepy. -codec. -protocol + +runtimepy_codec_protocol + +runtimepy. +codec. +protocol -runtimepy_codec_protocol_base - -runtimepy. -codec. -protocol. -base + +runtimepy_codec_protocol_base + +runtimepy. +codec. +protocol. +base -runtimepy_codec_protocol_json - -runtimepy. -codec. -protocol. -json + +runtimepy_codec_protocol_json + +runtimepy. +codec. +protocol. +json -runtimepy_codec_protocol_base->runtimepy_codec_protocol_json - - + +runtimepy_codec_protocol_base->runtimepy_codec_protocol_json + + -runtimepy_codec_protocol_json->runtimepy_codec_protocol - - + +runtimepy_codec_protocol_json->runtimepy_codec_protocol + + -runtimepy_commands - -runtimepy. -commands + +runtimepy_commands + +runtimepy. +commands -runtimepy_commands->runtimepy_app - - + +runtimepy_commands->runtimepy_app + + -runtimepy_commands_all - -runtimepy. -commands. -all + +runtimepy_commands_all + +runtimepy. +commands. +all -runtimepy_commands_all->runtimepy_app - - - + +runtimepy_commands_all->runtimepy_app + -runtimepy_commands_tui->runtimepy_commands_all - - + +runtimepy_commands_tui->runtimepy_commands_all + + -runtimepy_entry->runtimepy___main__ - - + +runtimepy_entry->runtimepy___main__ + + -runtimepy_enum - -runtimepy.enum + +runtimepy_enum + +runtimepy.enum -runtimepy_enum->runtimepy_channel_environment_base - + +runtimepy_enum->runtimepy_channel_environment_base + -runtimepy_enum->runtimepy_channel_environment_create - - - + +runtimepy_enum->runtimepy_channel_environment_create + + -runtimepy_enum->runtimepy_channel_environment_file - + +runtimepy_enum->runtimepy_channel_environment_file + + -runtimepy_enum->runtimepy_codec_protocol_base - - - + +runtimepy_enum->runtimepy_codec_protocol_base + -runtimepy_primitives_field_manager - -runtimepy. -primitives. -field. -manager + +runtimepy_primitives_field_manager + +runtimepy. +primitives. +field. +manager -runtimepy_enum->runtimepy_primitives_field_manager - - + +runtimepy_enum->runtimepy_primitives_field_manager + + -runtimepy_primitives_field_manager_base - -runtimepy. -primitives. -field. -manager. -base + +runtimepy_primitives_field_manager_base + +runtimepy. +primitives. +field. +manager. +base -runtimepy_enum->runtimepy_primitives_field_manager_base - - + +runtimepy_enum->runtimepy_primitives_field_manager_base + + + + + + +runtimepy_telemetry + +runtimepy. +telemetry + + + +runtimepy_enum->runtimepy_telemetry + -runtimepy_enum_registry - -runtimepy. -enum. -registry + +runtimepy_enum_registry + +runtimepy. +enum. +registry -runtimepy_enum_registry->runtimepy_channel_environment_base - - + +runtimepy_enum_registry->runtimepy_channel_environment_base + + + -runtimepy_enum_registry->runtimepy_channel_environment_file - - + +runtimepy_enum_registry->runtimepy_channel_environment_file + + + -runtimepy_enum_registry->runtimepy_codec_protocol_base - + +runtimepy_enum_registry->runtimepy_codec_protocol_base + + + + -runtimepy_enum_registry->runtimepy_primitives_field_manager - - - + +runtimepy_enum_registry->runtimepy_primitives_field_manager + -runtimepy_enum_registry->runtimepy_primitives_field_manager_base - - - - + +runtimepy_enum_registry->runtimepy_primitives_field_manager_base + + + + +runtimepy_enum_registry->runtimepy_telemetry + + + -runtimepy_enum_type - -runtimepy. -enum. -type + +runtimepy_enum_type + +runtimepy. +enum. +type -runtimepy_enum_type->runtimepy_channel_environment_create - - + +runtimepy_enum_type->runtimepy_channel_environment_create + + + -runtimepy_enum_type->runtimepy_enum - - + +runtimepy_enum_type->runtimepy_enum + + -runtimepy_enum_type->runtimepy_enum_registry - - + +runtimepy_enum_type->runtimepy_enum_registry + + -runtimepy_mapping - -runtimepy. -mapping + +runtimepy_mapping + +runtimepy. +mapping -runtimepy_mapping->runtimepy_channel_environment_create - - - - + +runtimepy_mapping->runtimepy_channel_environment_create + + -runtimepy_mapping->runtimepy_channel_environment_file - - + +runtimepy_mapping->runtimepy_channel_environment_file + + + + -runtimepy_mapping->runtimepy_enum - - + +runtimepy_mapping->runtimepy_enum + + + -runtimepy_mapping->runtimepy_enum_registry - - - + +runtimepy_mapping->runtimepy_enum_registry + + + -runtimepy_registry_bool - -runtimepy. -registry. -bool + +runtimepy_registry_bool + +runtimepy. +registry. +bool -runtimepy_mapping->runtimepy_registry_bool - - + +runtimepy_mapping->runtimepy_registry_bool + + -runtimepy_registry_name - -runtimepy. -registry. -name + +runtimepy_registry_name + +runtimepy. +registry. +name -runtimepy_mapping->runtimepy_registry_name - - + +runtimepy_mapping->runtimepy_registry_name + + -runtimepy_mixins - -runtimepy. -mixins + +runtimepy_mixins + +runtimepy. +mixins -runtimepy_mixins->runtimepy_channel - + +runtimepy_mixins->runtimepy_channel + -runtimepy_mixins->runtimepy_channel_registry - - - + +runtimepy_mixins->runtimepy_channel_registry + -runtimepy_mixins->runtimepy_mapping - - + +runtimepy_mixins->runtimepy_mapping + + -runtimepy_primitives_field - -runtimepy. -primitives. -field + +runtimepy_primitives_field + +runtimepy. +primitives. +field -runtimepy_mixins->runtimepy_primitives_field - - - + +runtimepy_mixins->runtimepy_primitives_field + + -runtimepy_mixins_enum - -runtimepy. -mixins. -enum + +runtimepy_mixins_enum + +runtimepy. +mixins. +enum -runtimepy_mixins_enum->runtimepy_channel - - - + +runtimepy_mixins_enum->runtimepy_channel + + + -runtimepy_mixins_enum->runtimepy_primitives_field - - + +runtimepy_mixins_enum->runtimepy_primitives_field + + -runtimepy_mixins_regex - -runtimepy. -mixins. -regex + +runtimepy_mixins_regex + +runtimepy. +mixins. +regex -runtimepy_mixins_regex->runtimepy_channel_registry - - - + +runtimepy_mixins_regex->runtimepy_channel_registry + + -runtimepy_mixins_regex->runtimepy_mapping - - + +runtimepy_mixins_regex->runtimepy_mapping + + + -runtimepy_mixins_regex->runtimepy_primitives_field - + +runtimepy_mixins_regex->runtimepy_primitives_field + + + + -runtimepy_net_connection - -runtimepy. -net. -connection + +runtimepy_net_connection + +runtimepy. +net. +connection -runtimepy_net_manager - -runtimepy. -net. -manager + +runtimepy_net_manager + +runtimepy. +net. +manager -runtimepy_net_connection->runtimepy_net_manager - - + +runtimepy_net_connection->runtimepy_net_manager + + -runtimepy_net_mixin - -runtimepy. -net. -mixin + +runtimepy_net_mixin + +runtimepy. +net. +mixin -runtimepy_net_connection->runtimepy_net_mixin - - + +runtimepy_net_connection->runtimepy_net_mixin + + -runtimepy_net_tcp_connection - -runtimepy. -net. -tcp. -connection + +runtimepy_net_tcp_connection + +runtimepy. +net. +tcp. +connection -runtimepy_net_connection->runtimepy_net_tcp_connection - - - + +runtimepy_net_connection->runtimepy_net_tcp_connection + -runtimepy_net_udp_connection - -runtimepy. -net. -udp. -connection + +runtimepy_net_udp_connection + +runtimepy. +net. +udp. +connection -runtimepy_net_connection->runtimepy_net_udp_connection - + +runtimepy_net_connection->runtimepy_net_udp_connection + -runtimepy_net_websocket_connection - -runtimepy. -net. -websocket. -connection + +runtimepy_net_websocket_connection + +runtimepy. +net. +websocket. +connection -runtimepy_net_connection->runtimepy_net_websocket_connection - - + +runtimepy_net_connection->runtimepy_net_websocket_connection + + + -runtimepy_net_manager->runtimepy_net_tcp_connection - + +runtimepy_net_manager->runtimepy_net_tcp_connection + + + -runtimepy_net_mixin->runtimepy_net_tcp_connection - + +runtimepy_net_mixin->runtimepy_net_tcp_connection + + -runtimepy_net_mixin->runtimepy_net_udp_connection - + +runtimepy_net_mixin->runtimepy_net_udp_connection + + + -runtimepy_primitives - -runtimepy. -primitives + +runtimepy_primitives + +runtimepy. +primitives -runtimepy_primitives->runtimepy_channel - - + +runtimepy_primitives->runtimepy_channel + + -runtimepy_primitives->runtimepy_channel_environment_array - - - + +runtimepy_primitives->runtimepy_channel_environment_array + -runtimepy_primitives->runtimepy_channel_environment_base - - - - + +runtimepy_primitives->runtimepy_channel_environment_base + -runtimepy_primitives->runtimepy_channel_environment_create - - + +runtimepy_primitives->runtimepy_channel_environment_create + + -runtimepy_primitives->runtimepy_channel_environment_file - + +runtimepy_primitives->runtimepy_channel_environment_file + + -runtimepy_primitives->runtimepy_channel_registry - - + +runtimepy_primitives->runtimepy_channel_registry + + + -runtimepy_primitives->runtimepy_codec_protocol_base - + +runtimepy_primitives->runtimepy_codec_protocol_base + + -runtimepy_primitives->runtimepy_codec_protocol_json - - + +runtimepy_primitives->runtimepy_codec_protocol_json + + -runtimepy_primitives_array - -runtimepy. -primitives. -array + +runtimepy_primitives_array + +runtimepy. +primitives. +array -runtimepy_primitives_array->runtimepy_channel_environment_array - - + +runtimepy_primitives_array->runtimepy_channel_environment_array + + + -runtimepy_primitives_array->runtimepy_codec_protocol_base - + +runtimepy_primitives_array->runtimepy_codec_protocol_base + + -runtimepy_primitives_base - -runtimepy. -primitives. -base + +runtimepy_primitives_base + +runtimepy. +primitives. +base -runtimepy_primitives_base->runtimepy_primitives_array - - + +runtimepy_primitives_base->runtimepy_primitives_array + + -runtimepy_primitives_bool - -runtimepy. -primitives. -bool + +runtimepy_primitives_bool + +runtimepy. +primitives. +bool -runtimepy_primitives_base->runtimepy_primitives_bool - - + +runtimepy_primitives_base->runtimepy_primitives_bool + + -runtimepy_primitives_float - -runtimepy. -primitives. -float + +runtimepy_primitives_float + +runtimepy. +primitives. +float -runtimepy_primitives_base->runtimepy_primitives_float - - + +runtimepy_primitives_base->runtimepy_primitives_float + + -runtimepy_primitives_int - -runtimepy. -primitives. -int + +runtimepy_primitives_int + +runtimepy. +primitives. +int -runtimepy_primitives_base->runtimepy_primitives_int - - + +runtimepy_primitives_base->runtimepy_primitives_int + + -runtimepy_primitives_bool->runtimepy_channel - + +runtimepy_primitives_bool->runtimepy_channel + + + -runtimepy_primitives_bool->runtimepy_primitives - - + +runtimepy_primitives_bool->runtimepy_primitives + + -runtimepy_primitives_field->runtimepy_channel_environment_array - - + +runtimepy_primitives_field->runtimepy_channel_environment_array + + + -runtimepy_primitives_field->runtimepy_channel_environment_base - - + +runtimepy_primitives_field->runtimepy_channel_environment_base + -runtimepy_primitives_field->runtimepy_channel_environment_file - - + +runtimepy_primitives_field->runtimepy_channel_environment_file + + -runtimepy_primitives_field->runtimepy_codec_protocol_base - - - + +runtimepy_primitives_field->runtimepy_codec_protocol_base + + -runtimepy_primitives_field->runtimepy_codec_protocol_json - - + +runtimepy_primitives_field->runtimepy_codec_protocol_json + + + -runtimepy_primitives_field_fields - -runtimepy. -primitives. -field. -fields + +runtimepy_primitives_field_fields + +runtimepy. +primitives. +field. +fields -runtimepy_primitives_field_fields->runtimepy_channel_environment_array - - + +runtimepy_primitives_field_fields->runtimepy_channel_environment_array + + + -runtimepy_primitives_field_fields->runtimepy_channel_environment_base - + +runtimepy_primitives_field_fields->runtimepy_channel_environment_base + + -runtimepy_primitives_field_fields->runtimepy_codec_protocol_base - + +runtimepy_primitives_field_fields->runtimepy_codec_protocol_base + -runtimepy_primitives_field_fields->runtimepy_primitives_field_manager - - + +runtimepy_primitives_field_fields->runtimepy_primitives_field_manager + + -runtimepy_primitives_field_fields->runtimepy_primitives_field_manager_base - - + +runtimepy_primitives_field_fields->runtimepy_primitives_field_manager_base + + -runtimepy_primitives_field_manager->runtimepy_channel_environment_base - - - + +runtimepy_primitives_field_manager->runtimepy_channel_environment_base + + -runtimepy_primitives_field_manager->runtimepy_channel_environment_file - - - - + +runtimepy_primitives_field_manager->runtimepy_channel_environment_file + + -runtimepy_primitives_field_manager->runtimepy_codec_protocol_base - - - + +runtimepy_primitives_field_manager->runtimepy_codec_protocol_base + + + -runtimepy_primitives_field_manager->runtimepy_codec_protocol_json - - + +runtimepy_primitives_field_manager->runtimepy_codec_protocol_json + + -runtimepy_primitives_field_manager_base->runtimepy_primitives_field_manager - - + +runtimepy_primitives_field_manager_base->runtimepy_primitives_field_manager + + -runtimepy_primitives_float->runtimepy_channel - + +runtimepy_primitives_float->runtimepy_channel + + -runtimepy_primitives_float->runtimepy_primitives - - + +runtimepy_primitives_float->runtimepy_primitives + + -runtimepy_primitives_int->runtimepy_channel - + +runtimepy_primitives_int->runtimepy_channel + -runtimepy_primitives_int->runtimepy_primitives - - + +runtimepy_primitives_int->runtimepy_primitives + + -runtimepy_primitives_int->runtimepy_primitives_field - - + +runtimepy_primitives_int->runtimepy_primitives_field + + -runtimepy_primitives_int->runtimepy_primitives_field_fields - - + +runtimepy_primitives_int->runtimepy_primitives_field_fields + + -runtimepy_primitives_type - -runtimepy. -primitives. -type + +runtimepy_primitives_type + +runtimepy. +primitives. +type -runtimepy_primitives_type->runtimepy_primitives_base - - + +runtimepy_primitives_type->runtimepy_primitives_base + + -runtimepy_primitives_type->runtimepy_primitives_bool - - - + +runtimepy_primitives_type->runtimepy_primitives_bool + -runtimepy_primitives_type->runtimepy_primitives_float - - + +runtimepy_primitives_type->runtimepy_primitives_float + + + -runtimepy_primitives_type->runtimepy_primitives_int - + +runtimepy_primitives_type->runtimepy_primitives_int + -runtimepy_primitives_type_base - -runtimepy. -primitives. -type. -base + +runtimepy_primitives_type_base + +runtimepy. +primitives. +type. +base -runtimepy_primitives_type_bool - -runtimepy. -primitives. -type. -bool + +runtimepy_primitives_type_bool + +runtimepy. +primitives. +type. +bool -runtimepy_primitives_type_base->runtimepy_primitives_type_bool - - + +runtimepy_primitives_type_base->runtimepy_primitives_type_bool + + -runtimepy_primitives_type_float - -runtimepy. -primitives. -type. -float + +runtimepy_primitives_type_float + +runtimepy. +primitives. +type. +float -runtimepy_primitives_type_base->runtimepy_primitives_type_float - - + +runtimepy_primitives_type_base->runtimepy_primitives_type_float + + -runtimepy_primitives_type_int - -runtimepy. -primitives. -type. -int + +runtimepy_primitives_type_int + +runtimepy. +primitives. +type. +int -runtimepy_primitives_type_base->runtimepy_primitives_type_int - - + +runtimepy_primitives_type_base->runtimepy_primitives_type_int + + -runtimepy_primitives_type_bool->runtimepy_primitives_bool - - + +runtimepy_primitives_type_bool->runtimepy_primitives_bool + + + -runtimepy_primitives_type_bool->runtimepy_primitives_type - - + +runtimepy_primitives_type_bool->runtimepy_primitives_type + + -runtimepy_primitives_type_float->runtimepy_primitives_float - - + +runtimepy_primitives_type_float->runtimepy_primitives_float + -runtimepy_primitives_type_float->runtimepy_primitives_type - - + +runtimepy_primitives_type_float->runtimepy_primitives_type + + -runtimepy_primitives_type_int->runtimepy_primitives_int - - - + +runtimepy_primitives_type_int->runtimepy_primitives_int + + + -runtimepy_primitives_type_int->runtimepy_primitives_type - - + +runtimepy_primitives_type_int->runtimepy_primitives_type + + -runtimepy_registry - -runtimepy. -registry + +runtimepy_registry + +runtimepy. +registry -runtimepy_registry->runtimepy_channel - - + +runtimepy_registry->runtimepy_channel + + + -runtimepy_registry->runtimepy_channel_environment_array - - - + +runtimepy_registry->runtimepy_channel_environment_array + + + -runtimepy_registry->runtimepy_channel_environment_base - - - + +runtimepy_registry->runtimepy_channel_environment_base + + -runtimepy_registry->runtimepy_channel_environment_create - + +runtimepy_registry->runtimepy_channel_environment_create + -runtimepy_registry->runtimepy_channel_registry - - - + +runtimepy_registry->runtimepy_channel_registry + + + -runtimepy_registry->runtimepy_codec_protocol_base - - - + +runtimepy_registry->runtimepy_codec_protocol_base + + + -runtimepy_registry->runtimepy_enum - - - + +runtimepy_registry->runtimepy_enum + + + -runtimepy_registry->runtimepy_enum_registry - - + +runtimepy_registry->runtimepy_enum_registry + -runtimepy_registry->runtimepy_mixins_enum - - + +runtimepy_registry->runtimepy_mixins_enum + + -runtimepy_registry->runtimepy_primitives_field - - + +runtimepy_registry->runtimepy_primitives_field + + -runtimepy_registry->runtimepy_primitives_field_fields - + +runtimepy_registry->runtimepy_primitives_field_fields + + + -runtimepy_registry->runtimepy_primitives_field_manager - - + +runtimepy_registry->runtimepy_primitives_field_manager + -runtimepy_registry->runtimepy_primitives_field_manager_base - - - + +runtimepy_registry->runtimepy_primitives_field_manager_base + + -runtimepy_registry_bool->runtimepy_enum - + +runtimepy_registry_bool->runtimepy_enum + -runtimepy_registry_item - -runtimepy. -registry. -item + +runtimepy_registry_item + +runtimepy. +registry. +item -runtimepy_registry_item->runtimepy_channel - + +runtimepy_registry_item->runtimepy_channel + -runtimepy_registry_item->runtimepy_enum - + +runtimepy_registry_item->runtimepy_enum + + -runtimepy_registry_item->runtimepy_registry - - + +runtimepy_registry_item->runtimepy_registry + + -runtimepy_registry_name->runtimepy_channel_environment_array - - + +runtimepy_registry_name->runtimepy_channel_environment_array + -runtimepy_registry_name->runtimepy_channel_environment_base - - - + +runtimepy_registry_name->runtimepy_channel_environment_base + + + -runtimepy_registry_name->runtimepy_channel_environment_create - - + +runtimepy_registry_name->runtimepy_channel_environment_create + -runtimepy_registry_name->runtimepy_channel_registry - - + +runtimepy_registry_name->runtimepy_channel_registry + + -runtimepy_registry_name->runtimepy_codec_protocol_base - - - - + +runtimepy_registry_name->runtimepy_codec_protocol_base + + -runtimepy_registry_name->runtimepy_enum - - - + +runtimepy_registry_name->runtimepy_enum + + -runtimepy_registry_name->runtimepy_mixins_enum - - + +runtimepy_registry_name->runtimepy_mixins_enum + + -runtimepy_registry_name->runtimepy_primitives_field - + +runtimepy_registry_name->runtimepy_primitives_field + + -runtimepy_registry_name->runtimepy_primitives_field_fields - - - + +runtimepy_registry_name->runtimepy_primitives_field_fields + + -runtimepy_registry_name->runtimepy_primitives_field_manager - - + +runtimepy_registry_name->runtimepy_primitives_field_manager + + + + + -runtimepy_registry_name->runtimepy_primitives_field_manager_base - - + +runtimepy_registry_name->runtimepy_primitives_field_manager_base + + + -runtimepy_registry_name->runtimepy_registry - - + +runtimepy_registry_name->runtimepy_registry + + -runtimepy_schemas - -runtimepy. -schemas + +runtimepy_schemas + +runtimepy. +schemas -runtimepy_schemas->runtimepy_primitives_field_fields - + +runtimepy_schemas->runtimepy_primitives_field_fields + + -runtimepy_schemas->runtimepy_registry - - + +runtimepy_schemas->runtimepy_registry + + -runtimepy_task->runtimepy_tui_task - - + +runtimepy_task->runtimepy_tui_task + + + -runtimepy_tui - -runtimepy.tui + +runtimepy_tui + +runtimepy.tui -runtimepy_tui->runtimepy_commands_tui - + +runtimepy_tui->runtimepy_commands_tui + -runtimepy_tui_channels->runtimepy_commands_tui - + +runtimepy_tui_channels->runtimepy_commands_tui + -runtimepy_tui_channels->runtimepy_tui_task - - + +runtimepy_tui_channels->runtimepy_tui_task + + -runtimepy_tui_task->runtimepy_commands_tui - + +runtimepy_tui_task->runtimepy_commands_tui + -vcorelib - -vcorelib + +vcorelib + +vcorelib -vcorelib->runtimepy_app - + +vcorelib->runtimepy_app + + + + + -vcorelib->runtimepy_channel - - - + +vcorelib->runtimepy_channel + + -vcorelib->runtimepy_channel_environment_base - - - - + +vcorelib->runtimepy_channel_environment_base + + -vcorelib->runtimepy_channel_environment_create - - - + +vcorelib->runtimepy_channel_environment_create + + + -vcorelib->runtimepy_channel_environment_file - + +vcorelib->runtimepy_channel_environment_file + + + -vcorelib->runtimepy_channel_registry - - + +vcorelib->runtimepy_channel_registry + + -vcorelib->runtimepy_codec_protocol_base - - + +vcorelib->runtimepy_codec_protocol_base + + -vcorelib->runtimepy_codec_protocol_json - - - - + +vcorelib->runtimepy_codec_protocol_json + + + + -vcorelib->runtimepy_commands_all - - + +vcorelib->runtimepy_commands_all + + + -vcorelib->runtimepy_commands_tui - + +vcorelib->runtimepy_commands_tui + + + -vcorelib->runtimepy_enum - + +vcorelib->runtimepy_enum + + + -vcorelib->runtimepy_enum_registry - - - - + +vcorelib->runtimepy_enum_registry + + + + -vcorelib->runtimepy_net_connection - - - + +vcorelib->runtimepy_net_connection + + -vcorelib->runtimepy_net_tcp_connection - - - + +vcorelib->runtimepy_net_tcp_connection + + + -vcorelib->runtimepy_net_udp_connection - - - - - + +vcorelib->runtimepy_net_udp_connection + + -vcorelib->runtimepy_primitives_field - - + +vcorelib->runtimepy_primitives_field + + -vcorelib->runtimepy_primitives_field_fields - - - + +vcorelib->runtimepy_primitives_field_fields + + -vcorelib->runtimepy_primitives_field_manager - - - + +vcorelib->runtimepy_primitives_field_manager + + -vcorelib->runtimepy_primitives_field_manager_base - - + +vcorelib->runtimepy_primitives_field_manager_base + -vcorelib->runtimepy_registry - - + +vcorelib->runtimepy_registry + + + -vcorelib->runtimepy_registry_item - - - + +vcorelib->runtimepy_registry_item + + -vcorelib->runtimepy_schemas - - + +vcorelib->runtimepy_schemas + + + + -vcorelib->runtimepy_task - - + +vcorelib->runtimepy_task + + -vcorelib_args - -vcorelib.args + +vcorelib_args + +vcorelib.args -vcorelib_args->runtimepy_app - - + +vcorelib_args->runtimepy_app + -vcorelib_args->runtimepy_commands_all - - - + +vcorelib_args->runtimepy_commands_all + + + -vcorelib_args->runtimepy_commands_tui - + +vcorelib_args->runtimepy_commands_tui + + -vcorelib_asyncio - -vcorelib. -asyncio + +vcorelib_asyncio + +vcorelib. +asyncio -vcorelib_asyncio->runtimepy_commands_tui - + +vcorelib_asyncio->runtimepy_commands_tui + -vcorelib_dict - -vcorelib.dict + +vcorelib_dict + +vcorelib.dict -vcorelib_dict->runtimepy_registry_item - - - + +vcorelib_dict->runtimepy_registry_item + + -vcorelib_dict->runtimepy_schemas - - - - + +vcorelib_dict->runtimepy_schemas + + + -vcorelib_io - -vcorelib.io + +vcorelib_io + +vcorelib.io -vcorelib_dict->vcorelib_io - - + +vcorelib_dict->vcorelib_io + + + -vcorelib_io_types - -vcorelib. -io. -types + +vcorelib_io_types + +vcorelib. +io. +types -vcorelib_dict->vcorelib_io_types - - + +vcorelib_dict->vcorelib_io_types + + -vcorelib_dict_codec - -vcorelib. -dict. -codec + +vcorelib_dict_codec + +vcorelib. +dict. +codec -vcorelib_dict_codec->runtimepy_registry_item - + +vcorelib_dict_codec->runtimepy_registry_item + + -vcorelib_dict_codec->runtimepy_schemas - - + +vcorelib_dict_codec->runtimepy_schemas + + + -vcorelib_io->runtimepy_channel - - + +vcorelib_io->runtimepy_channel + + + -vcorelib_io->runtimepy_channel_environment_file - + +vcorelib_io->runtimepy_channel_environment_file + -vcorelib_io->runtimepy_channel_registry - + +vcorelib_io->runtimepy_channel_registry + + + -vcorelib_io->runtimepy_codec_protocol_base - - + +vcorelib_io->runtimepy_codec_protocol_base + + + + + -vcorelib_io->runtimepy_codec_protocol_json - - + +vcorelib_io->runtimepy_codec_protocol_json + -vcorelib_io->runtimepy_enum - + +vcorelib_io->runtimepy_enum + -vcorelib_io->runtimepy_enum_registry - + +vcorelib_io->runtimepy_enum_registry + + + + -vcorelib_io->runtimepy_primitives_field - - - + +vcorelib_io->runtimepy_primitives_field + + + + -vcorelib_io->runtimepy_primitives_field_fields - - + +vcorelib_io->runtimepy_primitives_field_fields + + + -vcorelib_io->runtimepy_primitives_field_manager - + +vcorelib_io->runtimepy_primitives_field_manager + + + -vcorelib_io->runtimepy_primitives_field_manager_base - - - - + +vcorelib_io->runtimepy_primitives_field_manager_base + + + -vcorelib_io->runtimepy_registry - - + +vcorelib_io->runtimepy_registry + + + -vcorelib_io->runtimepy_registry_item - - + +vcorelib_io->runtimepy_registry_item + + + -vcorelib_io->vcorelib_dict_codec - - + +vcorelib_io->vcorelib_dict_codec + + -vcorelib_schemas - -vcorelib. -schemas + +vcorelib_schemas + +vcorelib. +schemas -vcorelib_io->vcorelib_schemas - - - + +vcorelib_io->vcorelib_schemas + + -vcorelib_schemas_base - -vcorelib. -schemas. -base + +vcorelib_schemas_base + +vcorelib. +schemas. +base -vcorelib_io->vcorelib_schemas_base - - - + +vcorelib_io->vcorelib_schemas_base + + -vcorelib_io_types->runtimepy_channel - - - + +vcorelib_io_types->runtimepy_channel + + -vcorelib_io_types->runtimepy_channel_environment_file - - + +vcorelib_io_types->runtimepy_channel_environment_file + -vcorelib_io_types->runtimepy_channel_registry - - - + +vcorelib_io_types->runtimepy_channel_registry + + -vcorelib_io_types->runtimepy_codec_protocol_base - - + +vcorelib_io_types->runtimepy_codec_protocol_base + + + -vcorelib_io_types->runtimepy_codec_protocol_json - - + +vcorelib_io_types->runtimepy_codec_protocol_json + + + + + -vcorelib_io_types->runtimepy_enum - - - - - - + +vcorelib_io_types->runtimepy_enum + + -vcorelib_io_types->runtimepy_enum_registry - - - + +vcorelib_io_types->runtimepy_enum_registry + + -vcorelib_io_types->runtimepy_primitives_field - - - + +vcorelib_io_types->runtimepy_primitives_field + -vcorelib_io_types->runtimepy_primitives_field_fields - - - - + +vcorelib_io_types->runtimepy_primitives_field_fields + + + -vcorelib_io_types->runtimepy_primitives_field_manager - - - - + +vcorelib_io_types->runtimepy_primitives_field_manager + -vcorelib_io_types->runtimepy_primitives_field_manager_base - - + +vcorelib_io_types->runtimepy_primitives_field_manager_base + + + -vcorelib_io_types->runtimepy_registry - - + +vcorelib_io_types->runtimepy_registry + + + + -vcorelib_io_types->runtimepy_registry_item - - - + +vcorelib_io_types->runtimepy_registry_item + -vcorelib_io_types->vcorelib_dict_codec - - - + +vcorelib_io_types->vcorelib_dict_codec + + + -vcorelib_io_types->vcorelib_io - - + +vcorelib_io_types->vcorelib_io + + -vcorelib_io_types->vcorelib_schemas - - + +vcorelib_io_types->vcorelib_schemas + + -vcorelib_io_types->vcorelib_schemas_base - - + +vcorelib_io_types->vcorelib_schemas_base + + + -vcorelib_logging - -vcorelib. -logging + +vcorelib_logging + +vcorelib. +logging -vcorelib_logging->runtimepy_net_connection - + +vcorelib_logging->runtimepy_net_connection + + -vcorelib_logging->runtimepy_net_tcp_connection - - - + +vcorelib_logging->runtimepy_net_tcp_connection + + -vcorelib_logging->runtimepy_net_udp_connection - - - + +vcorelib_logging->runtimepy_net_udp_connection + + + + -vcorelib_logging->runtimepy_task - - + +vcorelib_logging->runtimepy_task + + -vcorelib_math - -vcorelib.math + +vcorelib_math + +vcorelib.math -vcorelib_math->runtimepy_task - + +vcorelib_math->runtimepy_task + + + + + -vcorelib_math->vcorelib_logging - - + +vcorelib_math->vcorelib_logging + + -vcorelib_math_analysis - -vcorelib. -math. -analysis + +vcorelib_math_analysis + +vcorelib. +math. +analysis -vcorelib_math_analysis->runtimepy_task - + +vcorelib_math_analysis->runtimepy_task + -vcorelib_math_analysis_average - -vcorelib. -math. -analysis. -average + +vcorelib_math_analysis_average + +vcorelib. +math. +analysis. +average -vcorelib_math_analysis_average->runtimepy_task - - + +vcorelib_math_analysis_average->runtimepy_task + -vcorelib_math_analysis_rate - -vcorelib. -math. -analysis. -rate + +vcorelib_math_analysis_rate + +vcorelib. +math. +analysis. +rate -vcorelib_math_analysis_average->vcorelib_math_analysis_rate - - + +vcorelib_math_analysis_average->vcorelib_math_analysis_rate + + -vcorelib_math_analysis_rate->runtimepy_task - + +vcorelib_math_analysis_rate->runtimepy_task + -vcorelib_namespace - -vcorelib. -namespace + +vcorelib_namespace + +vcorelib. +namespace -vcorelib_namespace->runtimepy_channel_environment_base - - + +vcorelib_namespace->runtimepy_channel_environment_base + + + -vcorelib_namespace->runtimepy_channel_environment_create - + +vcorelib_namespace->runtimepy_channel_environment_create + + + -vcorelib_paths - -vcorelib.paths + +vcorelib_paths + +vcorelib.paths -vcorelib_paths->runtimepy_channel_environment_file - - + +vcorelib_paths->runtimepy_channel_environment_file + + + + + -vcorelib_paths->runtimepy_primitives_field_manager - - + +vcorelib_paths->runtimepy_primitives_field_manager + + + + -vcorelib_paths->runtimepy_primitives_field_manager_base - - - + +vcorelib_paths->runtimepy_primitives_field_manager_base + + -vcorelib_paths->vcorelib_dict_codec - + +vcorelib_paths->vcorelib_dict_codec + + + -vcorelib_paths->vcorelib_io - - - + +vcorelib_paths->vcorelib_io + + -vcorelib_paths->vcorelib_io_types - - - + +vcorelib_paths->vcorelib_io_types + + -vcorelib_paths->vcorelib_schemas_base - - + +vcorelib_paths->vcorelib_schemas_base + + -vcorelib_schemas->runtimepy_schemas - + +vcorelib_schemas->runtimepy_schemas + + + -vcorelib_schemas->vcorelib_dict_codec - + +vcorelib_schemas->vcorelib_dict_codec + + -vcorelib_schemas_base->runtimepy_schemas - - - + +vcorelib_schemas_base->runtimepy_schemas + -vcorelib_schemas_base->vcorelib_dict_codec - + +vcorelib_schemas_base->vcorelib_dict_codec + + + -vcorelib_schemas_base->vcorelib_schemas - - + +vcorelib_schemas_base->vcorelib_schemas + + -websockets - -websockets + +websockets + +websockets -websockets->runtimepy_net_websocket_connection - - - + +websockets->runtimepy_net_websocket_connection + -websockets_client - -websockets. -client + +websockets_client + +websockets. +client -websockets_client->runtimepy_net_websocket_connection - + +websockets_client->runtimepy_net_websocket_connection + + -websockets_exceptions - -websockets. -exceptions + +websockets_exceptions + +websockets. +exceptions -websockets_exceptions->runtimepy_net_websocket_connection - + +websockets_exceptions->runtimepy_net_websocket_connection + -websockets_exceptions->websockets_client - - + +websockets_exceptions->websockets_client + + -websockets_server - -websockets. -server + +websockets_server + +websockets. +server -websockets_exceptions->websockets_server - - + +websockets_exceptions->websockets_server + + -websockets_server->runtimepy_net_websocket_connection - + +websockets_server->runtimepy_net_websocket_connection + + diff --git a/local/variables/package.yaml b/local/variables/package.yaml index 3158c02c..46ba57bd 100644 --- a/local/variables/package.yaml +++ b/local/variables/package.yaml @@ -1,5 +1,5 @@ --- major: 0 -minor: 12 -patch: 3 +minor: 13 +patch: 0 entry: runtimepy diff --git a/pyproject.toml b/pyproject.toml index abe25775..ffb2e23a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__" [project] name = "runtimepy" -version = "0.12.3" +version = "0.13.0" description = "A framework for implementing Python services." readme = "README.md" requires-python = ">=3.7" diff --git a/runtimepy/__init__.py b/runtimepy/__init__.py index a2a3588b..69437ec0 100644 --- a/runtimepy/__init__.py +++ b/runtimepy/__init__.py @@ -1,7 +1,7 @@ # ===================================== # generator=datazen # version=3.1.0 -# hash=f5cf7cc360be1ec5780bef4fa93e0a53 +# hash=1a71c8001105fcdb5a240f10db7ba967 # ===================================== """ @@ -10,4 +10,4 @@ DESCRIPTION = "A framework for implementing Python services." PKG_NAME = "runtimepy" -VERSION = "0.12.3" +VERSION = "0.13.0" diff --git a/runtimepy/enum/__init__.py b/runtimepy/enum/__init__.py index a72d750f..24ae125f 100644 --- a/runtimepy/enum/__init__.py +++ b/runtimepy/enum/__init__.py @@ -3,7 +3,9 @@ """ # built-in +from enum import IntEnum as _IntEnum from typing import Optional as _Optional +from typing import Type as _Type from typing import Union as _Union from typing import cast as _cast @@ -138,3 +140,20 @@ def register_int(self, name: str) -> _Optional[int]: def register_bool(self, name: str, value: bool) -> bool: """Register a boolean enumeration.""" return self.bools.register(name, value) + + @staticmethod + def data_from_enum(enum: _Type[_IntEnum]) -> _JsonObject: + """Get JSON data from an enumeration class.""" + + return { + "type": "int", + "items": {x.name.lower(): x.value for x in enum}, + } + + @staticmethod + def from_enum(enum: _Type[_IntEnum], identifier: int) -> "RuntimeEnum": + """Create a runtime enumeration from an enum class.""" + + data = RuntimeEnum.data_from_enum(enum) + data["id"] = identifier + return RuntimeEnum.create(data) diff --git a/runtimepy/enum/registry.py b/runtimepy/enum/registry.py index 03d02f3c..46f8803e 100644 --- a/runtimepy/enum/registry.py +++ b/runtimepy/enum/registry.py @@ -3,6 +3,7 @@ """ # built-in +from enum import IntEnum as _IntEnum from typing import Optional as _Optional from typing import Type as _Type from typing import cast as _cast @@ -37,3 +38,19 @@ def enum( if items is not None: data["items"] = items # type: ignore return self.register_dict(name, data) + + +class RuntimeIntEnum(_IntEnum): + """An integer enumeration extension.""" + + @classmethod + def runtime_enum(cls, identifier: int) -> _RuntimeEnum: + """Obtain a runtime enumeration from this class.""" + return _RuntimeEnum.from_enum(cls, identifier) + + @classmethod + def register_enum(cls, name: str, registry: EnumRegistry) -> _RuntimeEnum: + """Register an enumeration to a registry.""" + result = registry.register_dict(name, _RuntimeEnum.data_from_enum(cls)) + assert result is not None + return result diff --git a/runtimepy/telemetry/__init__.py b/runtimepy/telemetry/__init__.py new file mode 100644 index 00000000..f7045e93 --- /dev/null +++ b/runtimepy/telemetry/__init__.py @@ -0,0 +1,13 @@ +""" +A module implementing a telemetry interface. +""" + +# internal +from runtimepy.enum.registry import RuntimeIntEnum as _RuntimeIntEnum + + +class MessageType(_RuntimeIntEnum): + """An enumeration of viable message types.""" + + PROTOCOL_META = 1 + PROTOCOL_DATA = 2 diff --git a/tests/enum/test_enum.py b/tests/enum/test_enum.py new file mode 100644 index 00000000..72aa9d78 --- /dev/null +++ b/tests/enum/test_enum.py @@ -0,0 +1,26 @@ +""" +Test the 'enum' module. +""" + +# built-in +from enum import IntEnum, auto + +# module under test +from runtimepy.enum import RuntimeEnum + + +class SampleEnum(IntEnum): + """A sample enumeration.""" + + A = auto() + B = auto() + C = auto() + + +def test_runtime_enum_from_enum(): + """Test that we can create a runtime enumeration from a class.""" + + enum = RuntimeEnum.from_enum(SampleEnum, 1) + assert enum.get_int("a") + assert enum.get_int("b") + assert enum.get_int("c") diff --git a/tests/telemetry/__init__.py b/tests/telemetry/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/telemetry/test_telemetry.py b/tests/telemetry/test_telemetry.py new file mode 100644 index 00000000..7f9b0fec --- /dev/null +++ b/tests/telemetry/test_telemetry.py @@ -0,0 +1,20 @@ +""" +Test the 'telemetry' module. +""" + +# module under test +from runtimepy.enum.registry import EnumRegistry +from runtimepy.telemetry import MessageType + + +def test_message_type_basic(): + """Test basic interactions with the message-type enumeration.""" + + enum = MessageType.runtime_enum(1) + assert enum.get_int("protocol_meta") == 1 + assert enum.get_int("protocol_data") == 2 + + enum_reg = EnumRegistry({}) + enum = MessageType.register_enum("protocol", enum_reg) + assert enum.get_int("protocol_meta") == 1 + assert enum.get_int("protocol_data") == 2 From f5f353415ef5683501fea09a7be1957a8619b227 Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Fri, 10 Feb 2023 02:34:21 +0000 Subject: [PATCH 3/3] Optional name when registering enum class --- runtimepy/enum/registry.py | 8 +++++++- tests/telemetry/test_telemetry.py | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/runtimepy/enum/registry.py b/runtimepy/enum/registry.py index 46f8803e..cad049cf 100644 --- a/runtimepy/enum/registry.py +++ b/runtimepy/enum/registry.py @@ -49,8 +49,14 @@ def runtime_enum(cls, identifier: int) -> _RuntimeEnum: return _RuntimeEnum.from_enum(cls, identifier) @classmethod - def register_enum(cls, name: str, registry: EnumRegistry) -> _RuntimeEnum: + def register_enum( + cls, registry: EnumRegistry, name: str = None + ) -> _RuntimeEnum: """Register an enumeration to a registry.""" + + if name is None: + name = cls.__name__ + result = registry.register_dict(name, _RuntimeEnum.data_from_enum(cls)) assert result is not None return result diff --git a/tests/telemetry/test_telemetry.py b/tests/telemetry/test_telemetry.py index 7f9b0fec..d382726d 100644 --- a/tests/telemetry/test_telemetry.py +++ b/tests/telemetry/test_telemetry.py @@ -15,6 +15,7 @@ def test_message_type_basic(): assert enum.get_int("protocol_data") == 2 enum_reg = EnumRegistry({}) - enum = MessageType.register_enum("protocol", enum_reg) + enum = MessageType.register_enum(enum_reg) + assert enum_reg["MessageType"] is enum assert enum.get_int("protocol_meta") == 1 assert enum.get_int("protocol_data") == 2