rats.runtime
¶
Run rats applications, providing external context.
The provided rats-runtime
cli allows the registration and execution of rats.apps.AppContainer
applications. Register to the python plugin group called rats.runtime.apps
, and list available
plugins with rats-runtime list
.
[project.entry-points."rats.runtime.apps"]
"rats_e2e.runtime" = "rats_e2e.runtime:Application"
We register an example application you can run with rats-runtime run rats_e2e.runtime
. The name
of the registered entry point in your pyproject.toml
will map to the name provided to
rats-runtime run
.
$ rats-runtime run rats_e2e.runtime
hello, world!
looking for any registered context: rats_e2e.runtime._app:AppServices[example-data]
Our example application looks for any context services, which can be provided to the run
command.
$ rats-runtime run rats_e2e.runtime --context-file src/rats_resources/runtime/example-context.yaml
hello, world!
looking for any registered context: rats_e2e.runtime._app:AppServices[example-data]
found example data element: ExampleData(id='111', thing_a='111', thing_b='111')
found example data element: ExampleData(id='222', thing_a='222', thing_b='222')
from collections.abc import Iterator
from rats import apps, runtime
from ._data import ExampleData
@apps.autoscope
class AppServices:
EXAMPLE_DATA = apps.ServiceId[ExampleData]("example-data")
class Application(apps.AppContainer, apps.PluginMixin):
def execute(self) -> None:
print("hello, world!")
print(f"looking for any registered context: {AppServices.EXAMPLE_DATA.name}")
for data in self._app.get_group(AppServices.EXAMPLE_DATA):
print(f"found example data element: {data}")
@apps.fallback_group(AppServices.EXAMPLE_DATA)
def _data_from_context(self) -> Iterator[ExampleData]:
collection = self._app.get(runtime.AppServices.CONTEXT)
yield from collection.decoded_values(ExampleData, AppServices.EXAMPLE_DATA)
Info
Most users won't typically use rats-runtime
directly, but this interface is used by other
abstractions to execute applications remotely, like the rats.aml module, adding the ability
to execute applications within an azure ml job.
__all__ = ['AppServices', 'Application', 'DuplicateRequestError', 'Request', 'RequestNotFoundError', 'main']
module-attribute
¶
Application(app)
¶
Bases: apps.AppContainer
, cli.Container
, apps.PluginMixin
The rats-runtime
cli application.
$ rats-runtime --help
Usage: rats-runtime [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
list List all the exes and groups that are configured to run with `rats-
runtime run`.
run Run one or more apps, adding an optional additional context.
Source code in rats/apps/_app_containers.py
execute()
¶
Runs the rats-runtime
cli.
Source code in rats/runtime/_app.py
AppServices
¶
Services used by the rats.runtime.Application
cli command.
CONTEXT = apps.ServiceId[app_context.Collection[Any]]('app-ctx-collection.config')
class-attribute
instance-attribute
¶
rats.app_context.Collection available in the application run using rats-runtime run
.
REQUEST = apps.ServiceId[Request]('runtime-details-client')
class-attribute
instance-attribute
¶
The request information, available after the call to rats.runtime.Application.execute.
DuplicateRequestError()
¶
Request
¶
Bases: NamedTuple
app_ids
instance-attribute
¶
The app ids being run by rats.runtime.Application.
context
instance-attribute
¶
The rats.app_context.Collection that was submitted and made available to executed apps.
RequestNotFoundError()
¶
Bases: RuntimeError
Thrown if rats.runtime.AppServices.REQUEST is accessed without the application being run.
Source code in rats/runtime/_request.py
main()
¶
Main entry-point to the rats-runtime
cli command.