Typer integration¶
The same command scope as Click's, with nothing seeded into it. See the command and message hosts for the measurement behind that and how to seed the context yourself.
install ¶
install(
ctx: Context, container: FrozenContainer
) -> ScopeFrame
Open one depin scope bound to a Typer invocation.
Call it from the first function Typer runs for an invocation, taking the
context as a parameter annotated typer.Context: the callback registered
with @app.callback(), or the command itself when the application
declares no callback. depin.ext.cli.install states the lifetime the scope
takes on, what the frame is for, and what nesting an install inside another
one does.
Nothing is placed into the fresh frame. The module docstring records the measurement behind that and shows how to seed the context under a key of your own.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context of the callback or command being invoked. It ends the scope when it closes, so the scope lasts exactly as long as the invocation. |
required |
container
|
FrozenContainer
|
The frozen container to host for that invocation. |
required |
Returns:
| Type | Description |
|---|---|
ScopeFrame
|
The scope's frame, for placing values into with |
ScopeFrame
|
|
ScopeFrame
|
itself, a tenant, a correlation id read off an option. |
Raises:
| Type | Description |
|---|---|
TeardownError
|
An async provider left a teardown in the invocation's synchronous scope. Raised when the Typer context closes: a command callback cannot await, so an async provider has no place in one. |
ExceptionGroup
|
One or more teardowns failed when the invocation's scope closed. Every failure is included; one does not hide another. |
Example
Install once, in the callback, and every command of the application runs inside the one scope::
@app.callback()
def main(ctx: typer.Context) -> None:
install(ctx, di)