asphalt.core.component
¶
-
class
asphalt.core.component.
Component
¶ This is the base class for all Asphalt components.
-
coroutine
start
(self, ctx)¶ Perform any necessary tasks to start the services provided by this component.
- Components typically use the context to:
- publish resources (
publish_resource()
andpublish_lazy_resource()
) - request resources (
request_resource()
)
- publish resources (
It is advisable for Components to first publish all the resources they can before requesting any. This will speed up the dependency resolution and prevent deadlocks.
Parameters: ctx ( Context
) – the containing context for this component
-
coroutine
-
class
asphalt.core.component.
ContainerComponent
(components=None)¶ A component that can contain other components.
Parameters: components (
Optional
[Dict
[str
,Dict
[str
,Any
]]]) – dictionary of component alias ⭢ component configuration dictionaryVariables: -
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:
-
-
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.