Skip to content

Commit

Permalink
Merge pull request #130 from vkottler/dev/2.11.0
Browse files Browse the repository at this point in the history
Dev/2.11.0
  • Loading branch information
vkottler authored Sep 19, 2023
2 parents 6b92556 + 437e8f2 commit 18f2b7c
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 18 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.10.4
repo=runtimepy version=2.11.0
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=e80a04d895371053de2f136293708ddb
hash=0d5b513fa5fde98a9fd6371397800b42
=====================================
-->

# runtimepy ([2.10.4](https://pypi.org/project/runtimepy/))
# runtimepy ([2.11.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
4 changes: 2 additions & 2 deletions local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 2
minor: 10
patch: 4
minor: 11
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.10.4"
version = "2.11.0"
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=ecdca268d8d6298f7b49567a705b295e
# hash=75678e755b9ec7eac077dba7fa2c2be8
# =====================================

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

DESCRIPTION = "A framework for implementing Python services."
PKG_NAME = "runtimepy"
VERSION = "2.10.4"
VERSION = "2.11.0"

# runtimepy-specific content.
METRICS_NAME = "metrics"
18 changes: 18 additions & 0 deletions runtimepy/channel/environment/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,21 @@ def command(self, value: str) -> CommandResult:
result = self.handle_command(args)

return result


EnvironmentMap = dict[str, ChannelCommandProcessor]
ENVIRONMENTS: EnvironmentMap = {}


def clear_env() -> None:
"""Reset the global environment mapping."""
ENVIRONMENTS.clear()


def register_env(name: str, env: ChannelCommandProcessor) -> None:
"""Register a channel environment globally."""

assert (
name not in ENVIRONMENTS or ENVIRONMENTS[name] is env
), f"Can't register environment '{name}'!"
ENVIRONMENTS[name] = env
8 changes: 8 additions & 0 deletions runtimepy/net/arbiter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from vcorelib.namespace import NamespaceMixin as _NamespaceMixin

# internal
from runtimepy.channel.environment.command import clear_env, register_env
from runtimepy.net.arbiter.housekeeping import metrics_poller
from runtimepy.net.arbiter.info import AppInfo, ConnectionMap
from runtimepy.net.arbiter.task import (
Expand Down Expand Up @@ -186,6 +187,13 @@ async def _entry(

tasks = {x.name: x for x in self.task_manager.tasks}

# Register environments.
clear_env()
for task in tasks.values():
register_env(task.name, task.command)
for name, conn in self._connections.items():
register_env(name, conn.command)

# Run application, but only if all the registered connections are
# still alive after initialization.
if not check_connections or not any(
Expand Down
3 changes: 3 additions & 0 deletions runtimepy/net/arbiter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,7 @@ async def process_config(

# Update application configuration data if necessary.
if config.config is not None:
root = self._config["root"]
self._config = config.config
assert "root" not in config.config, config.config
config.config["root"] = root
11 changes: 4 additions & 7 deletions runtimepy/net/stream/json/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

# internal
from runtimepy import PKG_NAME, VERSION
from runtimepy.channel.environment.command import (
ChannelCommandProcessor,
FieldOrChannel,
)
from runtimepy.channel.environment.command import ENVIRONMENTS, FieldOrChannel
from runtimepy.channel.environment.command.result import CommandResult
from runtimepy.net.stream.json.handlers import (
ChannelCommand,
Expand Down Expand Up @@ -55,10 +52,11 @@ def _register_handlers(self) -> None:
# Extra handlers.
self.typed_handler("find_file", FindFile, find_file_request_handler)
self.typed_handler(
"channel_command", ChannelCommand, channel_env_handler(self.envs)
"channel_command",
ChannelCommand,
channel_env_handler(ENVIRONMENTS, self.command),
)

envs: dict[str, ChannelCommandProcessor]
outgoing_commands: asyncio.Queue[ChannelCommandParams]

async def process_command_queue(self) -> None:
Expand Down Expand Up @@ -104,7 +102,6 @@ def init(self) -> None:
"kind": type(self).__name__,
}

self.envs = {"default": self.command}
self.command.hooks.append(self._handle_remote_command)

self.curr_id: int = 1
Expand Down
10 changes: 7 additions & 3 deletions runtimepy/net/stream/json/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ChannelCommand(RuntimepyDictCodec, BasicDictCodec):


def channel_env_handler(
envs: dict[str, ChannelCommandProcessor]
envs: dict[str, ChannelCommandProcessor], default: ChannelCommandProcessor
) -> TypedHandler[ChannelCommand]:
"""Create a channel-environment map command handler."""

Expand All @@ -36,9 +36,13 @@ async def handler(outbox: JsonMessage, request: ChannelCommand) -> None:

env_name = request.data["environment"]

env = envs.get(env_name)
if env_name == "default":
env = default

# Run the command if we have the environment.
if env_name in envs:
result = envs[env_name].command(request.data["command"])
if env is not None:
result = env.command(request.data["command"])
outbox["success"] = result.success
outbox["reason"] = result.reason

Expand Down
2 changes: 2 additions & 0 deletions tests/net/arbiter/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ async def echo_test_app(app: AppInfo) -> int:
"""Test some of the echo connections."""

# Ensure that configuration data got set correctly.
if "root" in app.config:
del app.config["root"]
assert app.config == {"a": 1, "b": 2, "c": 3}

assert len(list(app.search(pattern="sample"))) == 3
Expand Down

0 comments on commit 18f2b7c

Please sign in to comment.