cloup.constraints.conditions

This modules contains described predicates that you can use as conditions of conditional constraints (see cloup.constraints.If).

Predicates should be treated as immutable objects, even though immutability is not (at the moment) enforced.

Classes summary

cloup.constraints.conditions.Predicate()

A Callable that takes a Context and returns a boolean, with an associated description.

cloup.constraints.conditions.Not(predicate)

cloup.constraints.conditions.IsSet(param_name)

True if the parameter is set.

cloup.constraints.conditions.Equal(…)

True if the parameter value equals value.

Contents

cloup.constraints.conditions.P
class cloup.constraints.conditions.Predicate[source]

Bases: abc.ABC

A Callable that takes a Context and returns a boolean, with an associated description. Meant to be used as condition in a conditional constraint (see If).

abstract description(self, ctx: click.Context)str[source]

Succint description of the predicate (alias: desc).

negated_description(self, ctx: click.Context)str[source]

Succint description of the negation of this predicate (alias: neg_desc).

desc(self, ctx: click.Context)str[source]

Short alias for description().

neg_desc(self, ctx: click.Context)str[source]

Short alias for negated_description().

negated(self)[source]
abstract __call__(self, ctx: click.Context)bool[source]

Evaluate the predicate on the given context.

__invert__(self)cloup.constraints.conditions.Predicate[source]
__or__(self, other: cloup.constraints.conditions.Predicate) → cloup.constraints.conditions._Or[source]
__and__(self, other: cloup.constraints.conditions.Predicate) → cloup.constraints.conditions._And[source]
__repr__(self)[source]

Return repr(self).

class cloup.constraints.conditions.Not(predicate: P)[source]

Bases: cloup.constraints.conditions.Predicate, Generic[P]

A Callable that takes a Context and returns a boolean, with an associated description. Meant to be used as condition in a conditional constraint (see If).

description(self, ctx: click.Context)str[source]

Succint description of the predicate (alias: desc).

negated_description(self, ctx: click.Context)str[source]

Succint description of the negation of this predicate (alias: neg_desc).

__call__(self, ctx: click.Context)bool[source]

Evaluate the predicate on the given context.

__invert__(self)P[source]
__repr__(self)str[source]

Return repr(self).

class cloup.constraints.conditions.IsSet(param_name: str)[source]

Bases: cloup.constraints.conditions.Predicate

A Callable that takes a Context and returns a boolean, with an associated description. Meant to be used as condition in a conditional constraint (see If).

Parameters

param_name (str) –

description(self, ctx: click.Context)str[source]

Succint description of the predicate (alias: desc).

negated_description(self, ctx: click.Context)str[source]

Succint description of the negation of this predicate (alias: neg_desc).

__call__(self, ctx: click.Context)bool[source]

Evaluate the predicate on the given context.

class cloup.constraints.conditions.Equal(param_name: str, value: Any)[source]

Bases: cloup.constraints.conditions.Predicate

True if the parameter value equals value.

Parameters
  • param_name (str) –

  • value (Any) –

description(self, ctx: click.Context)str[source]

Succint description of the predicate (alias: desc).

negated_description(self, ctx: click.Context)str[source]

Succint description of the negation of this predicate (alias: neg_desc).

__call__(self, ctx: click.Context)bool[source]

Evaluate the predicate on the given context.