-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from vkottler/dev/3.4.0
3.4.0 - Initial scaffolding for 'task' command
- Loading branch information
Showing
17 changed files
with
196 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
major: 3 | ||
minor: 3 | ||
patch: 1 | ||
minor: 4 | ||
patch: 0 | ||
entry: runtimepy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
An entry-point for the 'task' command. | ||
""" | ||
|
||
# built-in | ||
from argparse import ArgumentParser as _ArgumentParser | ||
from argparse import Namespace as _Namespace | ||
from typing import Any, Dict | ||
|
||
# third-party | ||
from vcorelib.args import CommandFunction as _CommandFunction | ||
|
||
# internal | ||
from runtimepy import PKG_NAME | ||
from runtimepy.commands.arbiter import arbiter_cmd | ||
from runtimepy.commands.common import arbiter_args, cmd_with_jit | ||
|
||
|
||
def config_data(args: _Namespace) -> Dict[str, Any]: | ||
"""Get configuration data for the 'task' command.""" | ||
|
||
return { | ||
"includes": [f"package://{PKG_NAME}/factories.yaml"], | ||
"tasks": [ | ||
{ | ||
"name": args.factory, | ||
"factory": args.factory, | ||
"period_s": 1.0 / args.rate, | ||
} | ||
], | ||
} | ||
|
||
|
||
def task_cmd(args: _Namespace) -> int: | ||
"""Execute the task command.""" | ||
|
||
return cmd_with_jit(arbiter_cmd, args, config_data(args)) | ||
|
||
|
||
def add_task_cmd(parser: _ArgumentParser) -> _CommandFunction: | ||
"""Add task-command arguments to its parser.""" | ||
|
||
with arbiter_args(parser, nargs="*"): | ||
parser.add_argument( | ||
"-r", | ||
"--rate", | ||
default=10, | ||
type=float, | ||
help=( | ||
"rate (in Hz) that the task should run " | ||
"(default: %(default)s)" | ||
), | ||
) | ||
parser.add_argument( | ||
"factory", help="name of task factory to create task with" | ||
) | ||
|
||
return task_cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
A module implementing basic trigonometric tasks. | ||
""" | ||
|
||
# built-in | ||
import math | ||
|
||
# internal | ||
from runtimepy.net.arbiter.task import ArbiterTask as _ArbiterTask | ||
from runtimepy.net.arbiter.task import TaskFactory as _TaskFactory | ||
from runtimepy.primitives import Float as _Float | ||
|
||
|
||
class SinusoidTask(_ArbiterTask): | ||
"""A task for logging metrics.""" | ||
|
||
auto_finalize = True | ||
|
||
def _init_state(self) -> None: | ||
"""Add channels to this instance's channel environment.""" | ||
|
||
self.sin = _Float() | ||
self.cos = _Float() | ||
self.steps = _Float(10.0) | ||
|
||
self.env.channel("sin", self.sin) | ||
self.env.channel("cos", self.cos) | ||
self.env.channel("steps", self.steps, commandable=True) | ||
|
||
async def dispatch(self) -> bool: | ||
"""Dispatch an iteration of this task.""" | ||
|
||
step = (math.tau / self.steps.value) * self.metrics.dispatches.value | ||
|
||
self.sin.value = math.sin(step) | ||
self.cos.value = math.cos(step) | ||
|
||
return True | ||
|
||
|
||
class Sinusoid(_TaskFactory[SinusoidTask]): | ||
"""A factory for the sinusoid task.""" | ||
|
||
kind = SinusoidTask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
Test the 'commands.task' module. | ||
""" | ||
|
||
# module under test | ||
from runtimepy.entry import main as runtimepy_main | ||
|
||
# internal | ||
from tests.resources import base_args | ||
|
||
|
||
def test_task_command_basic(): | ||
"""Test basic usages of the 'task' command.""" | ||
|
||
base = base_args("task") | ||
assert runtimepy_main(base + ["sinusoid"]) == 0 |