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

Predicate()

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

Not(predicate)

IsSet(param_name)

True if the parameter is set.

Equal(param_name, value)

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)[source]

Succint description of the predicate (alias: desc).

Parameters

ctx (click.Context) –

Return type

str

negated_description(self, ctx)[source]

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

Parameters

ctx (click.Context) –

Return type

str

desc(self, ctx)[source]

Short alias for description().

Parameters

ctx (click.Context) –

Return type

str

neg_desc(self, ctx)[source]

Short alias for negated_description().

Parameters

ctx (click.Context) –

Return type

str

negated(self)[source]
abstract __call__(self, ctx)[source]

Evaluate the predicate on the given context.

Parameters

ctx (click.Context) –

Return type

bool

__invert__(self)[source]
Return type

Predicate

__or__(self, other)[source]
Parameters

other (Predicate) –

Return type

_Or

__and__(self, other)[source]
Parameters

other (Predicate) –

Return type

_And

__repr__(self)[source]

Return repr(self).

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

Bases: 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)[source]

Succint description of the predicate (alias: desc).

Parameters

ctx (click.Context) –

Return type

str

negated_description(self, ctx)[source]

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

Parameters

ctx (click.Context) –

Return type

str

__call__(self, ctx)[source]

Evaluate the predicate on the given context.

Parameters

ctx (click.Context) –

Return type

bool

__invert__(self)[source]
Return type

P

__repr__(self)[source]

Return repr(self).

Return type

str

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

Bases: 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)[source]

Succint description of the predicate (alias: desc).

Parameters

ctx (click.Context) –

Return type

str

negated_description(self, ctx)[source]

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

Parameters

ctx (click.Context) –

Return type

str

__call__(self, ctx)[source]

Evaluate the predicate on the given context.

Parameters

ctx (click.Context) –

Return type

bool

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

Bases: Predicate

True if the parameter value equals value.

Parameters
  • param_name (str) –

  • value (Any) –

description(self, ctx)[source]

Succint description of the predicate (alias: desc).

Parameters

ctx (click.Context) –

Return type

str

negated_description(self, ctx)[source]

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

Parameters

ctx (click.Context) –

Return type

str

__call__(self, ctx)[source]

Evaluate the predicate on the given context.

Parameters

ctx (click.Context) –

Return type

bool