Skip to content

Commit

Permalink
2.1.2 - Some TypeSystem methods
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Aug 30, 2023
1 parent f13efff commit c1c06e0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 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.1.1
repo=runtimepy version=2.1.2
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=3fefcc8e6720ba32defa794a99a02d02
hash=64a758df8095e218dce93935454221a7
=====================================
-->

# runtimepy ([2.1.1](https://pypi.org/project/runtimepy/))
# runtimepy ([2.1.2](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: 2
minor: 1
patch: 1
patch: 2
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.1.1"
version = "2.1.2"
description = "A framework for implementing Python services."
readme = "README.md"
requires-python = ">=3.8"
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=48f84a8c64666c2d207321d75e066401
# hash=f83181278a252952c4fdf15493634816
# =====================================

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

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "2.1.1"
VERSION = "2.1.2"
15 changes: 15 additions & 0 deletions runtimepy/codec/system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# internal
from runtimepy import PKG_NAME
from runtimepy.codec.protocol import Protocol
from runtimepy.enum import RuntimeEnum
from runtimepy.enum.registry import (
DEFAULT_ENUM_PRIMITIVE,
EnumRegistry,
Expand Down Expand Up @@ -45,6 +46,13 @@ def __init__(self, *namespace: str) -> None:

self.root_namespace = global_namespace.child(*namespace)

def get_enum(self, name: str, *namespace: str) -> RuntimeEnum:
"""Lookup an enum type at runtime."""

found = self._find_name(name, *namespace, strict=True)
assert found is not None
return self._enums[found]

def runtime_int_enum(self, enum: Type[RuntimeIntEnum]) -> None:
"""Register an enumeration class."""

Expand Down Expand Up @@ -76,6 +84,13 @@ def register(self, name: str, *namespace: str) -> Protocol:
] = new_type
return new_type

def get_protocol(self, name: str, *namespace: str) -> Protocol:
"""Get a custom protocol by name."""

found = self._find_name(name, *namespace, strict=True)
assert found is not None
return self.custom[found]

def add(self, custom_type: str, field_name: str, field_type: str) -> None:
"""Add a field to a custom type."""

Expand Down
4 changes: 4 additions & 0 deletions tests/codec/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def get_test_system() -> TypeSystem:

assert system.size("SampleStruct") == 7

assert system.get_enum("TestEnum2")

return system


Expand All @@ -42,6 +44,8 @@ def test_type_system_compound_types():

assert system.size("SomeStruct") == 16

assert system.get_protocol("SomeStruct")


def test_type_system_basic():
"""Test basic interactions with a custom type system."""
Expand Down

0 comments on commit c1c06e0

Please sign in to comment.