Skip to content

Commit

Permalink
2.11.1 - Add 'get' command and port overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Sep 20, 2023
1 parent 18f2b7c commit fe40942
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
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.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)
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: 11
patch: 0
patch: 1
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.11.0"
version = "2.11.1"
description = "A framework for implementing Python services."
readme = "README.md"
requires-python = ">=3.11"
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.3
# hash=75678e755b9ec7eac077dba7fa2c2be8
# hash=cbf96c08875d153d468e456331e45fa5
# =====================================

"""
Expand All @@ -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"
4 changes: 4 additions & 0 deletions runtimepy/channel/environment/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."""

Expand Down
4 changes: 4 additions & 0 deletions runtimepy/channel/environment/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtimepy/channel/environment/command/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ChannelCommand(StrEnum):

SET = "set"
TOGGLE = "toggle"
GET = "get"


class CommandParser(ArgumentParser):
Expand Down
10 changes: 10 additions & 0 deletions runtimepy/data/schemas/ConnectionArbiterConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion runtimepy/net/arbiter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions tests/channel/environment/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions tests/data/valid/connection_arbiter/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@ servers:
kwargs:
host: "0.0.0.0"
port: "$websocket_server"

port_overrides:
not_a_port: 1

0 comments on commit fe40942

Please sign in to comment.