Skip to content

Commit

Permalink
2.6.0 - Add channel env to all connections
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Sep 6, 2023
1 parent b0cee05 commit ce68fa5
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- run: |
mk python-release owner=vkottler \
repo=runtimepy version=2.5.0
repo=runtimepy version=2.6.0
if: |
matrix.python-version == '3.11'
&& matrix.system == 'ubuntu-latest'
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!--
=====================================
generator=datazen
version=3.1.2
hash=b7f4f833830e6d02bb40fa8830398467
version=3.1.3
hash=6f4a1197f00eb12e7c4413bda1eb6bb1
=====================================
-->

# runtimepy ([2.5.0](https://pypi.org/project/runtimepy/))
# runtimepy ([2.6.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)
Expand Down Expand Up @@ -74,13 +74,14 @@ commands:
```
$ ./venv3.11/bin/runtimepy arbiter -h
usage: runtimepy arbiter [-h] configs [configs ...]
usage: runtimepy arbiter [-h] [--curses] configs [configs ...]
positional arguments:
configs the configuration to load
options:
-h, --help show this help message and exit
--curses whether or not to use curses.wrapper when starting
```

Expand Down
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 2
minor: 5
minor: 6
patch: 0
entry: runtimepy
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "runtimepy"
version = "2.5.0"
version = "2.6.0"
description = "A framework for implementing Python services."
readme = "README.md"
requires-python = ">=3.8"
Expand Down
6 changes: 3 additions & 3 deletions runtimepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.2
# hash=13cec9f3eb806319008b56d8dd4df98d
# version=3.1.3
# hash=229f080e52433eff00bcf6060ea75b13
# =====================================

"""
Expand All @@ -10,4 +10,4 @@

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "2.5.0"
VERSION = "2.6.0"
2 changes: 1 addition & 1 deletion runtimepy/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =====================================
# generator=datazen
# version=3.1.2
# version=3.1.3
# hash=b28a8111bcc727e854c1f6474a3c4232
# =====================================
"""
Expand Down
2 changes: 1 addition & 1 deletion runtimepy/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =====================================
# generator=datazen
# version=3.1.2
# version=3.1.3
# hash=a4deafb4ebcc179d8d85f9376d22dc92
# =====================================

Expand Down
2 changes: 1 addition & 1 deletion runtimepy/commands/all.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =====================================
# generator=datazen
# version=3.1.2
# version=3.1.3
# hash=9e87f6454df00f68a60186c6e98c7f81
# =====================================

Expand Down
2 changes: 1 addition & 1 deletion runtimepy/entry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =====================================
# generator=datazen
# version=3.1.2
# version=3.1.3
# hash=40f5c85d844b6d42a5dd10ff46c82cdd
# =====================================

Expand Down
33 changes: 0 additions & 33 deletions runtimepy/net/channel/__init__.py

This file was deleted.

37 changes: 36 additions & 1 deletion runtimepy/net/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from vcorelib.logging import LoggerType as _LoggerType

# internal
from runtimepy.channel.environment import ChannelEnvironment
from runtimepy.net.metrics import ConnectionMetrics
from runtimepy.primitives.byte_order import DEFAULT_BYTE_ORDER, ByteOrder

Expand All @@ -30,7 +31,12 @@ class Connection(_LoggerMixin, _ABC):

byte_order: ByteOrder = DEFAULT_BYTE_ORDER

def __init__(self, logger: _LoggerType) -> None:
def __init__(
self,
logger: _LoggerType,
env: ChannelEnvironment = None,
add_metrics: bool = True,
) -> None:
"""Initialize this connection."""

super().__init__(logger=logger)
Expand All @@ -53,8 +59,37 @@ def __init__(self, logger: _LoggerType) -> None:
self._tasks: _List[_asyncio.Task[None]] = []
self.initialized = _asyncio.Event()
self.disabled_event = _asyncio.Event()

self._init_channel_environment(env=env, add_metrics=add_metrics)
self.init()

def _init_channel_environment(
self,
add_metrics: bool = True,
env: ChannelEnvironment = None,
**kwargs,
) -> None:
"""Initialize this connection's channel environment."""

if env is None:
env = ChannelEnvironment(**kwargs)
self.env = env

if add_metrics:
# Add metrics channels.
with self.env.names_pushed("metrics"):
for name, direction in [
("tx", self.metrics.tx),
("rx", self.metrics.rx),
]:
with self.env.names_pushed(name):
self.env.channel("messages", direction.messages)
self.env.channel(
"messages_rate", direction.message_rate
)
self.env.channel("bytes", direction.bytes)
self.env.channel("kbps", direction.kbps)

def init(self) -> None:
"""Initialize this instance."""

Expand Down
4 changes: 1 addition & 3 deletions runtimepy/net/stream/json/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

# internal
from runtimepy import PKG_NAME, VERSION
from runtimepy.net.channel import ChannelEnvironmentMixin
from runtimepy.net.stream.json.handlers import (
FindFile,
event_wait,
Expand All @@ -35,7 +34,7 @@
from runtimepy.net.udp import UdpConnection


class JsonMessageConnection(StringMessageConnection, ChannelEnvironmentMixin):
class JsonMessageConnection(StringMessageConnection):
"""A connection interface for JSON messaging."""

_log_messages: List[Dict[str, Any]]
Expand All @@ -51,7 +50,6 @@ def init(self) -> None:
"""Initialize this instance."""

super().init()
ChannelEnvironmentMixin.init(self)

self.handlers: MessageHandlers = {}
self.typed_handlers: Dict[
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =====================================
# generator=datazen
# version=3.1.2
# version=3.1.3
# hash=6701839983d2292671c1f49f66c938ae
# =====================================

Expand Down
2 changes: 1 addition & 1 deletion tasks/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =====================================
# generator=datazen
# version=3.1.2
# version=3.1.3
# hash=9f62028523c3b5a953733ca89dcc3018
# =====================================
"""
Expand Down

0 comments on commit ce68fa5

Please sign in to comment.