asphalt.core.component
- class asphalt.core.component.CLIApplicationComponent(components=None)
Specialized subclass of
ContainerComponent
for command line tools.Command line tools and similar applications should use this as their root component and implement their main code in the
run()
method.When all the subcomponents have been started,
run()
is started as a new task. When the task is finished, the application will exit using the return value as its exit code.If
run()
raises an exception, a stack trace is printed and the exit code will be set to 1. If the returned exit code is out of range or of the wrong data type, it is set to 1 and a warning is emitted.- abstract async run(ctx)
Run the business logic of the command line tool.
Do not call this method yourself.
- Return type:
int | None
- Returns:
the application’s exit code (0-127;
None
= 0)
- class asphalt.core.component.Component
This is the base class for all Asphalt components.
- abstract async start(ctx)
Perform any necessary tasks to start the services provided by this component.
- In this method, components typically use the context to:
add resources and/or resource factories to it (
add_resource()
andadd_resource_factory()
)request resources from it asynchronously (
request_resource()
)
It is advisable for Components to first add all the resources they can to the context before requesting any from it. This will speed up the dependency resolution and prevent deadlocks.
- class asphalt.core.component.ContainerComponent(components=None)
A component that can contain other components.
- Parameters:
components – dictionary of component alias ⭢ component configuration dictionary
- Variables:
- add_component(alias, type=None, **config)
Add a child component.
This will instantiate a component class, as specified by the
type
argument.If the second argument is omitted, the value of
alias
is used as its value.The locally given configuration can be overridden by component configuration parameters supplied to the constructor (via the
components
argument).When configuration values are provided both as keyword arguments to this method and component configuration through the
components
constructor argument, the configurations are merged together usingmerge_config()
in a way that the configuration values from thecomponents
argument override the keyword arguments to this method.- Parameters:
alias (str) – a name for the component instance, unique within this container
type (str | type | None) – entry point name or
Component
subclass or amodule:varname
reference to oneconfig – keyword arguments passed to the component’s constructor
- Return type:
None