cloup.constraints._support#
Classes#
|
A NamedTuple storing a |
|
Internal utility |
|
Provides support for constraints. |
Functions#
|
Register a constraint on a list of parameters specified by (destination) name (e.g. the default name of |
|
Return a decorator that adds the given parameters and applies a constraint to them. Equivalent to::. |
|
Contents#
- class cloup.constraints._support.BoundConstraintSpec[source]#
Bases:
NamedTupleA NamedTuple storing a
Constraintand the names of the parameters it has to check.- Parameters:
constraint (Constraint) –
param_names (Sequence[str]) –
- constraint :cloup.constraints._core.Constraint#
- param_names :Union[Sequence[str]]#
- resolve_params(cmd)[source]#
- Parameters:
cmd (ConstraintMixin) –
- Return type:
- cloup.constraints._support.constraint(constr, params)[source]#
Register a constraint on a list of parameters specified by (destination) name (e.g. the default name of
--input-fileisinput_file).- Parameters:
constr (Constraint) –
params (Iterable[str]) –
- Return type:
Callable[[F], F]
- cloup.constraints._support.constrained_params(constr, *param_adders)[source]#
Return a decorator that adds the given parameters and applies a constraint to them. Equivalent to:
@param_adders[0] ... @param_adders[-1] @constraint(constr, <param names>)
This decorator saves you to manually (re)type the parameter names. It can also be used inside
@option_group.Instead of using this decorator, you can also call the constraint itself:
@constr(*param_adders)
but remember that:
Python 3.9 is the first that allows arbitrary expressions on the right of
@;using a long conditional/composite constraint as decorator may be less readable.
In these cases, you may consider using
@constrained_params.New in version 0.9.0.
- Parameters:
constr (Constraint) – an instance of
Constraintparam_adders (Callable[[Callable[[...], Any]], Callable[[...], Any]]) – function decorators, each attaching a single parameter to the decorated function.
- Return type:
Callable[[F], F]
- class cloup.constraints._support.BoundConstraint[source]#
Bases:
NamedTupleInternal utility
NamedTuplethat represents aConstraintbound to a collection ofclick.Parameterinstances. Note: this is not a subclass of Constraint.- Parameters:
constraint (Constraint) –
params (Sequence[Parameter]) –
- constraint :cloup.constraints._core.Constraint#
- params :Sequence[click.Parameter]#
- class cloup.constraints._support.ConstraintMixin(*args, constraints=(), show_constraints=None, **kwargs)[source]#
Provides support for constraints.
- Parameters:
constraints (Sequence[BoundConstraintSpec | BoundConstraint]) – sequence of constraints bound to specific groups of parameters. Note that constraints applied to option groups are collected from the option groups themselves, so they don’t need to be included in this argument.
show_constraints (bool | None) – whether to include a “Constraint” section in the command help. This is also available as a context setting having a lower priority than this attribute.
args (Any) – positional arguments forwarded to the next class in the MRO
kwargs (Any) – keyword arguments forwarded to the next class in the MRO
- optgroup_constraints#
Constraints applied to
OptionGroupinstances.
- param_constraints :Tuple[BoundConstraint, Ellipsis]#
Constraints registered using
@constraint(or equivalent method).
- all_constraints#
All constraints applied to parameter/option groups of this command.
- parse_args(ctx, args)[source]#
- Parameters:
ctx (click.Context) –
args (List[str]) –
- Return type:
List[str]
- get_params_by_name(names)[source]#
- Parameters:
names (Iterable[str]) –
- Return type:
Sequence[click.Parameter]
- format_constraints(ctx, formatter)[source]#
- Parameters:
ctx (click.Context) –
formatter (cloup.HelpFormatter) –
- Return type:
None