From fe4094240463916ee3a425fbae0b79ea33bcb490 Mon Sep 17 00:00:00 2001 From: Vaughn Kottler Date: Tue, 19 Sep 2023 23:55:56 -0500 Subject: [PATCH] 2.11.1 - Add 'get' command and port overrides --- .github/workflows/python-package.yml | 2 +- README.md | 4 ++-- local/variables/package.yaml | 2 +- pyproject.toml | 2 +- runtimepy/__init__.py | 4 ++-- runtimepy/channel/environment/base.py | 4 ++++ runtimepy/channel/environment/command/__init__.py | 4 ++++ runtimepy/channel/environment/command/parser.py | 1 + runtimepy/data/schemas/ConnectionArbiterConfig.yaml | 10 ++++++++++ runtimepy/net/arbiter/config.py | 10 +++++++++- tests/channel/environment/test_command.py | 2 ++ tests/data/valid/connection_arbiter/basic.yaml | 3 +++ 12 files changed, 40 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 75361ad1..e6da41d7 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -67,7 +67,7 @@ jobs: - run: | mk python-release owner=vkottler \ - repo=runtimepy version=2.11.0 + repo=runtimepy version=2.11.1 if: | matrix.python-version == '3.11' && matrix.system == 'ubuntu-latest' diff --git a/README.md b/README.md index 28a6bcef..6ee16964 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,11 @@ ===================================== generator=datazen version=3.1.3 - hash=0d5b513fa5fde98a9fd6371397800b42 + hash=b44aaca14f66bd1757ae95f327e5ec63 ===================================== --> -# runtimepy ([2.11.0](https://pypi.org/project/runtimepy/)) +# runtimepy ([2.11.1](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) diff --git a/local/variables/package.yaml b/local/variables/package.yaml index ced7da13..ec601bca 100644 --- a/local/variables/package.yaml +++ b/local/variables/package.yaml @@ -1,5 +1,5 @@ --- major: 2 minor: 11 -patch: 0 +patch: 1 entry: runtimepy diff --git a/pyproject.toml b/pyproject.toml index 380a1106..0196bdc7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__" [project] name = "runtimepy" -version = "2.11.0" +version = "2.11.1" description = "A framework for implementing Python services." readme = "README.md" requires-python = ">=3.11" diff --git a/runtimepy/__init__.py b/runtimepy/__init__.py index 40c41bd1..8e41542e 100644 --- a/runtimepy/__init__.py +++ b/runtimepy/__init__.py @@ -1,7 +1,7 @@ # ===================================== # generator=datazen # version=3.1.3 -# hash=75678e755b9ec7eac077dba7fa2c2be8 +# hash=cbf96c08875d153d468e456331e45fa5 # ===================================== """ @@ -10,7 +10,7 @@ DESCRIPTION = "A framework for implementing Python services." PKG_NAME = "runtimepy" -VERSION = "2.11.0" +VERSION = "2.11.1" # runtimepy-specific content. METRICS_NAME = "metrics" diff --git a/runtimepy/channel/environment/base.py b/runtimepy/channel/environment/base.py index 48d80ada..6cc9c8ba 100644 --- a/runtimepy/channel/environment/base.py +++ b/runtimepy/channel/environment/base.py @@ -180,6 +180,10 @@ def value( return value + def exists(self, val: _RegistryKey) -> bool: + """Determine if a channel exists.""" + return self.fields.has_field(val) or self.get(val) is not None + def get(self, val: _RegistryKey) -> _Optional[ChannelResult]: """Attempt to get a channel and its enumeration (if it has one).""" diff --git a/runtimepy/channel/environment/command/__init__.py b/runtimepy/channel/environment/command/__init__.py index 1c5df7ca..77e75b65 100644 --- a/runtimepy/channel/environment/command/__init__.py +++ b/runtimepy/channel/environment/command/__init__.py @@ -109,6 +109,10 @@ def handle_command(self, args: Namespace) -> CommandResult: hook(args, None) return result + if args.command == ChannelCommand.GET: + if self.env.exists(args.channel): + return CommandResult(True, str(self.env.value(args.channel))) + chan = self.env.get(args.channel) channel: FieldOrChannel diff --git a/runtimepy/channel/environment/command/parser.py b/runtimepy/channel/environment/command/parser.py index da61aef2..0a50aec5 100644 --- a/runtimepy/channel/environment/command/parser.py +++ b/runtimepy/channel/environment/command/parser.py @@ -13,6 +13,7 @@ class ChannelCommand(StrEnum): SET = "set" TOGGLE = "toggle" + GET = "get" class CommandParser(ArgumentParser): diff --git a/runtimepy/data/schemas/ConnectionArbiterConfig.yaml b/runtimepy/data/schemas/ConnectionArbiterConfig.yaml index 53133084..6ba6f87a 100644 --- a/runtimepy/data/schemas/ConnectionArbiterConfig.yaml +++ b/runtimepy/data/schemas/ConnectionArbiterConfig.yaml @@ -58,6 +58,16 @@ properties: kwargs: type: object + port_overrides: + type: object + required: [] + additionalProperties: false + patternProperties: + "^.*$": + type: integer + minimum: 1 + maximum: 65535 + ports: type: array items: diff --git a/runtimepy/net/arbiter/config.py b/runtimepy/net/arbiter/config.py index 08fc9251..770ac29b 100644 --- a/runtimepy/net/arbiter/config.py +++ b/runtimepy/net/arbiter/config.py @@ -44,11 +44,19 @@ def init(self, data: _JsonObject) -> None: self.data = data + port_overrides: _Dict[str, int] = data.get( + "port_overrides", + {}, # type: ignore + ) + # Process ports. self.ports: _Dict[str, int] = {} for item in _cast(_List[_Dict[str, _Any]], data.get("ports", [])): self.ports[item["name"]] = get_free_socket_name( - local=normalize_host(item["host"], item["port"]), + local=normalize_host( + item["host"], + port_overrides.get(item["name"], item["port"]), + ), kind=_socket.SOCK_STREAM if item["type"] == "tcp" else _socket.SOCK_DGRAM, diff --git a/tests/channel/environment/test_command.py b/tests/channel/environment/test_command.py index b12eb0ff..a7830838 100644 --- a/tests/channel/environment/test_command.py +++ b/tests/channel/environment/test_command.py @@ -55,6 +55,8 @@ def test_channel_command_processor_basic(): assert not processor.command("toggle asdf") assert env.value("bool1") + assert processor.command("get bool1") + assert env.value("int1") == 0 assert not processor.command("set int1") assert processor.command("set int1 42") diff --git a/tests/data/valid/connection_arbiter/basic.yaml b/tests/data/valid/connection_arbiter/basic.yaml index 62ad0d4c..7e343ee1 100644 --- a/tests/data/valid/connection_arbiter/basic.yaml +++ b/tests/data/valid/connection_arbiter/basic.yaml @@ -66,3 +66,6 @@ servers: kwargs: host: "0.0.0.0" port: "$websocket_server" + +port_overrides: + not_a_port: 1