pynenc.trigger.conditions.base

Base class for all trigger conditions.

This module defines the core abstractions for condition-based triggering in Pynenc. Trigger conditions are used to evaluate whether a task should be triggered based on specific criteria such as task status, time schedules, or custom events.

Module Contents

Classes

ConditionContext

Base class for condition contexts.

TriggerCondition

Base class for all trigger conditions.

ValidCondition

Represents a satisfied condition with its associated context.

Data

C

API

class pynenc.trigger.conditions.base.ConditionContext[source]

Bases: abc.ABC

Base class for condition contexts.

Contains the minimum data required for condition evaluation and provides the foundation for type-specific context classes.

timestamp: datetime.datetime

‘field(…)’

_context_class_cache: ClassVar[dict[str, type[pynenc.trigger.conditions.base.ConditionContext]]]

None

_cache_initialized: ClassVar[bool]

False

classmethod _initialize_class_cache() None[source]

Initialize the context class cache by recursively finding all subclasses.

classmethod get_context_class(context_type: str) type[pynenc.trigger.conditions.base.ConditionContext][source]

Get a context class by its name from the class cache.

Parameters:

context_type – Name of the context class to find

Returns:

The context class

abstract property context_id: str

Generate a stable, unique ID for this context based on its parameters.

Returns:

A string ID uniquely identifying this context

to_json(app: pynenc.app.Pynenc) str[source]

Serialize this context to a JSON string.

Parameters:

app – Pynenc application instance

Returns:

JSON string representation

abstract _to_json(app: pynenc.app.Pynenc) dict[str, Any][source]

Create a serializable representation of this context.

Subclasses must implement this method to handle their specific serialization logic.

Parameters:

app – Pynenc application instance

Returns:

Dictionary with serialized context data

classmethod from_json(json_str: str, app: pynenc.app.Pynenc) pynenc.trigger.conditions.base.ConditionContext[source]

Create a context instance from a JSON string.

Parameters:
  • json_str – JSON string containing serialized context

  • app – Pynenc application instance

Returns:

A new instance of the appropriate ConditionContext subclass

Raises:

ValueError – If the JSON data is invalid

abstract classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.conditions.base.ConditionContext[source]

Create a context instance from parsed JSON data.

Subclasses must implement this method to handle their specific deserialization logic.

Parameters:
  • data – Dictionary with context data

  • app – Pynenc application instance

Returns:

A new instance of this context class

pynenc.trigger.conditions.base.C

‘TypeVar(…)’

class pynenc.trigger.conditions.base.TriggerCondition[source]

Bases: typing.Generic[pynenc.trigger.conditions.base.C], abc.ABC

Base class for all trigger conditions.

A trigger condition evaluates whether a task should be triggered based on specific criteria and a matching context type.

context_type: ClassVar[type[pynenc.trigger.conditions.base.ConditionContext]]

None

_condition_class_cache: ClassVar[dict[str, type[pynenc.trigger.conditions.base.TriggerCondition]]]

None

_cache_initialized: ClassVar[bool]

False

classmethod _initialize_class_cache() None[source]

Initialize the condition class cache by recursively finding all subclasses.

classmethod get_condition_class(condition_type: str) type[pynenc.trigger.conditions.base.TriggerCondition] | None[source]

Get a condition class by its name from the class cache.

Parameters:

condition_type – Name of the condition class to find

Returns:

The condition class or None if not found

abstract get_source_task_ids() set[str][source]

Get the ID of the task this condition is sourced from, if any.

Some conditions directly monitor specific tasks (like StatusCondition or ResultCondition). This method identifies if this condition is monitoring a specific source task.

Returns:

The ID of the source task, or None if this condition is not task-specific

abstract property condition_id: str

Generate a stable, unique ID for this condition based on its parameters.

Returns:

A string ID uniquely identifying this condition

to_json(app: pynenc.app.Pynenc) str[source]

Serialize this condition to a JSON string.

Parameters:

app – Pynenc application instance for serializing complex arguments

Returns:

JSON string representation of this condition

abstract _to_json(app: pynenc.app.Pynenc) dict[str, Any][source]

Create a serializable representation of this condition.

Subclasses must implement this method to handle their specific serialization logic.

Parameters:

app – Pynenc application instance for serializing complex arguments

Returns:

Dictionary with serialized condition data

classmethod from_json(json_str: str, app: pynenc.app.Pynenc) pynenc.trigger.conditions.base.TriggerCondition[source]

Create a condition instance from a JSON string.

This is a factory method that instantiates the correct subclass based on the condition_type field in the JSON data.

Parameters:
  • json_str – JSON string containing serialized condition

  • app – Pynenc application instance for deserializing complex arguments

Returns:

A new instance of the appropriate TriggerCondition subclass

Raises:

ValueError – If the JSON data is invalid or the condition type is unknown

abstract classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.conditions.base.TriggerCondition[source]

Create a condition instance from parsed JSON data.

Each subclass must implement this method to handle its specific deserialization logic.

Parameters:
  • data – Dictionary with condition data from JSON

  • app – Pynenc application instance for deserializing complex arguments

Returns:

A new instance of this condition class

Raises:

ValueError – If the data is invalid for this condition type

is_satisfied_by(context: pynenc.trigger.conditions.base.ConditionContext) bool[source]

Check if this condition is satisfied by the given context.

First validates if the context is of the expected type, then delegates to the type-specific implementation.

Parameters:

context – Context to evaluate against

Returns:

True if the condition is satisfied, False otherwise

abstract _is_satisfied_by(context: pynenc.trigger.conditions.base.C) bool[source]

Type-specific implementation of condition satisfaction.

This method is called by is_satisfied_by after type validation.

Parameters:

context – Context of the correct type for this condition

Returns:

True if the condition is satisfied, False otherwise

affects_task(task_id: str) bool[source]

Check if this condition is affected by a specific task.

Default implementation returns False as most conditions are not directly affected by specific tasks.

Parameters:

task_id – ID of the task to check

Returns:

True if the condition is affected by the task

class pynenc.trigger.conditions.base.ValidCondition(condition: pynenc.trigger.conditions.base.TriggerCondition, context: pynenc.trigger.conditions.base.ConditionContext)[source]

Represents a satisfied condition with its associated context.

This class pairs a TriggerCondition with the specific ConditionContext that caused it to be satisfied, creating a “valid condition” that can be used to evaluate triggers.

Initialization

Create a valid condition.

Parameters:
  • condition – The satisfied trigger condition

  • context – The context that satisfied the condition

property valid_condition_id: str

Get the ID of the underlying condition and context.

to_json(app: pynenc.app.Pynenc) str[source]

Serialize this valid condition to a JSON string.

Parameters:

app – Pynenc application instance

Returns:

JSON string representation

classmethod from_json(json_str: str, app: pynenc.app.Pynenc) pynenc.trigger.conditions.base.ValidCondition[source]

Create a valid condition instance from a JSON string.

Parameters:
  • json_str – JSON string containing serialized valid condition

  • app – Pynenc application instance

Returns:

A new ValidCondition instance