Skip to content

Commit 926df4a

Browse files
committed
5.15.3. - config commands
1 parent a7eb308 commit 926df4a

File tree

13 files changed

+73
-13
lines changed

13 files changed

+73
-13
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
7979
- run: |
8080
mk python-release owner=libre-embedded \
81-
repo=runtimepy version=5.15.2
81+
repo=runtimepy version=5.15.3
8282
if: |
8383
matrix.python-version == '3.12'
8484
&& matrix.system == 'ubuntu-latest'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
=====================================
33
generator=datazen
44
version=3.2.3
5-
hash=f1c75c9b812e8ff29fdda46f58009aef
5+
hash=ed2f5b3731ba189c4a3ec2f2252b622e
66
=====================================
77
-->
88

9-
# runtimepy ([5.15.2](https://pypi.org/project/runtimepy/))
9+
# runtimepy ([5.15.3](https://pypi.org/project/runtimepy/))
1010

1111
[![python](https://img.shields.io/pypi/pyversions/runtimepy.svg)](https://pypi.org/project/runtimepy/)
1212
![Build Status](https://github.com/libre-embedded/runtimepy/workflows/Python%20Package/badge.svg)

local/variables/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
major: 5
33
minor: 15
4-
patch: 2
4+
patch: 3
55
entry: runtimepy

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta:__legacy__"
44

55
[project]
66
name = "runtimepy"
7-
version = "5.15.2"
7+
version = "5.15.3"
88
description = "A framework for implementing Python services."
99
readme = "README.md"
1010
requires-python = ">=3.12"

runtimepy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# =====================================
22
# generator=datazen
33
# version=3.2.3
4-
# hash=839ec3c3fa52de16f775789c0d38bf3e
4+
# hash=f5155e85b2694b012648fdbe9c12b1cd
55
# =====================================
66

77
"""
@@ -10,7 +10,7 @@
1010

1111
DESCRIPTION = "A framework for implementing Python services."
1212
PKG_NAME = "runtimepy"
13-
VERSION = "5.15.2"
13+
VERSION = "5.15.3"
1414

1515
# runtimepy-specific content.
1616
METRICS_NAME = "metrics"

runtimepy/channel/environment/command/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
CommandHook,
2626
EnvironmentMap,
2727
)
28+
from runtimepy.channel.environment.command.result import CommandResult
2829
from runtimepy.channel.registry import ParsedEvent
2930
from runtimepy.mapping import DEFAULT_PATTERN
3031

@@ -243,6 +244,25 @@ def register(self, name: str, env: ChannelCommandProcessor) -> None:
243244
ENVIRONMENTS = GLOBAL
244245

245246

247+
def global_command(env: str, value: str) -> Optional[CommandResult]:
248+
"""Handle a global command."""
249+
250+
result = None
251+
if env in GLOBAL:
252+
result = GLOBAL[env].command(value)
253+
else:
254+
GLOBAL.logger.error(
255+
"Couldn't run command env='%s' value='%s'.", env, value
256+
)
257+
return result
258+
259+
260+
def global_commands(*cmds: tuple[str, str]) -> None:
261+
"""Handle a global command."""
262+
for env, value in cmds:
263+
global_command(env, value)
264+
265+
246266
def clear_env() -> None:
247267
"""Reset the global environment mapping."""
248268
GLOBAL.clear()

runtimepy/data/dummy_load.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ processes:
107107
app: runtimepy.sample.program.run
108108

109109
program: runtimepy.sample.program.SampleProgram
110+
111+
commands:
112+
- [udp_json_client, "set log_level warning"]
113+
- [proc1.peer, "set log_level warning"]

runtimepy/data/schemas/ConnectionArbiterConfig.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ properties:
2626
items:
2727
$ref: package://runtimepy/schemas/StructConfig.yaml
2828

29+
commands:
30+
type: array
31+
items:
32+
type: array
33+
minItems: 2
34+
maxItems: 2
35+
items:
36+
- type: string
37+
- type: string
38+
2939
tasks:
3040
type: array
3141
items:

runtimepy/net/arbiter/base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from runtimepy.channel.environment.command import (
2727
clear_env,
2828
env_json_data,
29+
global_commands,
2930
register_env,
3031
)
3132
from runtimepy.net.arbiter.housekeeping import housekeeping
@@ -145,6 +146,8 @@ def __init__(
145146
# A copy of named port mappings (loaded via external config).
146147
self._ports: dict[str, int] = {}
147148

149+
self._commands: list[tuple[str, str]] = []
150+
148151
self._init()
149152

150153
def _init(self) -> None:
@@ -318,6 +321,11 @@ async def _main(
318321

319322
# Run initialization methods.
320323
result = await self._run_apps_list(self._inits, info)
324+
325+
# Run commands.
326+
await _asyncio.sleep(0)
327+
global_commands(*self._commands)
328+
321329
if result == 0:
322330
# Get application methods.
323331
apps = self._apps

runtimepy/net/arbiter/config/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,8 @@ async def process_config(
245245
assert "root" not in config.config, config.config
246246
config.config["root"] = root
247247

248+
# Register commands.
249+
self._commands = config.commands
250+
248251

249252
ConfigConnectionArbiter.add_search_package(PKG_NAME)

0 commit comments

Comments
 (0)