Click integration¶
install ¶
install(
ctx: Context, container: FrozenContainer
) -> ScopeFrame
Open one depin scope bound to a Click invocation, seeded with its context.
Call it from the callback of a command or a group, which is the first code
Click runs for an invocation. 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; this adds the seed, so a scoped provider can
declare a click.Context parameter and be handed the context of the
callback that opened the scope.
Click closes that context after the command body has run and, for a group, after the group's result callback, so both are inside the scope.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context of the command or group being invoked, taken with
|
required |
container
|
FrozenContainer
|
The frozen container to host for that invocation. |
required |
Returns:
| Type | Description |
|---|---|
ScopeFrame
|
The scope's frame, for placing further values into with |
ScopeFrame
|
|
ScopeFrame
|
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 Click 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 group callback, and every subcommand of that group runs inside the one scope::
@click.group()
@click.pass_context
def cli(ctx: click.Context) -> None:
install(ctx, di)
seed_context ¶
seed_context(ctx: Context) -> ScopeSeed
Build the click.Context binding that install places into the invocation's frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
The context of the command or group the scope is opened for. |
required |
Returns:
| Type | Description |
|---|---|
ScopeSeed
|
The key to bind the context under, and the context itself. |
Example
from click import Command, Context ctx = Context(Command('report')) seed = seed_context(ctx) seed.key is Context True seed.value is ctx True