Skip to content

Commit

Permalink
Merge pull request #84 from vkottler/dev/1.7.4
Browse files Browse the repository at this point in the history
1.7.4 - Some small improvements
  • Loading branch information
vkottler authored Aug 16, 2023
2 parents b647b68 + 67b7262 commit c10858a
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 19 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=1.7.3
repo=runtimepy version=1.7.4
if: |
matrix.python-version == '3.11'
&& matrix.system == 'ubuntu-latest'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.2
hash=817cf762c796141c0bcef9a9834f06ac
hash=2ef9727ee775cc1db5301385b5959bd0
=====================================
-->

# runtimepy ([1.7.3](https://pypi.org/project/runtimepy/))
# runtimepy ([1.7.4](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
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: 1
minor: 7
patch: 3
patch: 4
entry: runtimepy
4 changes: 3 additions & 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 = "1.7.3"
version = "1.7.4"
description = "A framework for implementing Python services."
readme = "README.md"
requires-python = ">=3.8"
Expand Down Expand Up @@ -39,6 +39,8 @@ test = [
"yamllint",
"yambs",
"vmklib",
"sphinx",
"sphinx-book-theme",
"pytest-asyncio",
"setuptools-wrapper",
"types-setuptools"
Expand Down
4 changes: 2 additions & 2 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=02cdfc0846a87475ac589dd14f49608a
# hash=548569c24ddae75778158fe4d0904de5
# =====================================

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

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "1.7.3"
VERSION = "1.7.4"
7 changes: 7 additions & 0 deletions runtimepy/codec/protocol/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ def value(self, name: str, resolve_enum: bool = True) -> ProtocolPrimitive:

return self._fields.get(name, resolve_enum=resolve_enum)

def __str__(self) -> str:
"""Get this instance as a string."""

return f"({self.array.size})\t" + "\t".join(
f"{name}={self[name]}" for name in self._names.registered_order
)

def __getitem__(self, name: str) -> ProtocolPrimitive:
"""Get the value of a protocol field."""
return self.value(name)
Expand Down
2 changes: 2 additions & 0 deletions runtimepy/dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ isort
yamllint
yambs
vmklib
sphinx
sphinx-book-theme
pytest-asyncio
setuptools-wrapper
types-setuptools
9 changes: 7 additions & 2 deletions runtimepy/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Dict as _Dict
from typing import Generic as _Generic
from typing import Iterator as _Iterator
from typing import List as _List
from typing import MutableMapping as _MutableMapping
from typing import Optional as _Optional
from typing import Type as _Type
Expand Down Expand Up @@ -48,6 +49,7 @@ def __init__(

self._mapping: _Dict[T, str] = {}
self._reverse: _Dict[str, T] = {}
self.registered_order: _List[str] = []

if mapping is not None:
self.load_key_to_name(mapping)
Expand All @@ -64,14 +66,17 @@ def _set(self, key: T, name: str) -> None:
self._mapping[key] = name
else:
# Ensure the mappings are consistent.
assert self._mapping[key] == name
curr_name = self._mapping[key]
assert curr_name == name, f"{curr_name} != {name} ({key})"

# Add to the name->key mapping.
if name not in self._reverse:
self._reverse[name] = key
self.registered_order.append(name)
else:
# Ensure the mappings are consistent.
assert self._reverse[name] == key
curr_key = self._reverse[name]
assert curr_key == key, f"{curr_key} != {key} ({name})"

def load_key_to_name(self, mapping: KeyToName[T]) -> None:
"""Load a key-to-name mapping."""
Expand Down
9 changes: 6 additions & 3 deletions runtimepy/net/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ def increment(self, count: int, time_ns: int = None) -> None:
)

self.bytes.raw.value += count
self.kbps.raw.value = self._kbps_tracker(
time_ns=time_ns, value=float(count) / 1000.0

# Multiply by 8 to get bits from bytes.
self.kbps.raw.value = (
self._kbps_tracker(time_ns=time_ns, value=float(count) / 1000.0)
* 8
)

def reset(self) -> None:
Expand All @@ -66,7 +69,7 @@ def reset(self) -> None:
self.messages.raw.value = 0
self.bytes.raw.value = 0
self.kbps.raw.value = 0.0
self._kbps_tracker()
self._kbps_tracker.reset()


class ConnectionMetrics:
Expand Down
12 changes: 6 additions & 6 deletions runtimepy/registry/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def register_name(
) -> _Optional[int]:
"""Register a new name."""

curr = self.identifier(name)
if curr is not None:
assert identifier is None or curr == identifier
return curr

# Ensure the name is valid.
if not self.validate_name(name):
return None
Expand All @@ -51,12 +56,7 @@ def register_name(

# Store the mapping and return the identifier.
if identifier not in self._mapping:
self._mapping[identifier] = name
self._reverse[name] = identifier
return identifier

# If this name is already registered, return the identifier.
if self._reverse.get(name) == identifier:
self._set(identifier, name)
return identifier

return None
2 changes: 2 additions & 0 deletions tests/codec/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ def test_protocol_basic():
assert proto.write_meta(stream)
stream.seek(0)
assert Protocol.import_json(load(stream))

assert str(proto)

0 comments on commit c10858a

Please sign in to comment.