pynenc.trigger.arguments.argument_providers

Argument providers for trigger-based task executions.

This module defines the abstractions and implementations for generating arguments for tasks triggered by various conditions. It enables flexible mapping from trigger contexts to task arguments.

Module Contents

Classes

ArgumentProvider

Base class for argument providers.

StaticArgumentProvider

Provides static arguments independent of trigger context.

ContextCallable

Protocol for callables that process a specific context type.

ContextTypeArgumentProvider

Generates arguments from a specific context type using a user-provided function.

DirectArgumentProvider

Provides complete control over argument generation by giving direct access to the trigger context.

CompositeArgumentProvider

Combines multiple argument providers and merges their results.

Data

API

pynenc.trigger.arguments.argument_providers.C

‘TypeVar(…)’

pynenc.trigger.arguments.argument_providers.C_contra

‘TypeVar(…)’

pynenc.trigger.arguments.argument_providers.logger

‘getLogger(…)’

exception pynenc.trigger.arguments.argument_providers.ArgumentProviderError(provider: pynenc.trigger.arguments.argument_providers.ArgumentProvider, message: str | None = None)[source]

Bases: Exception

Raised when an argument provider cannot generate arguments for a task.

This can occur when:

  • A context-specific provider can’t find a matching context

  • A provider encounters an error while extracting arguments

  • A provider receives an incompatible context type

Initialization

Initialize with details about the provider failure.

Parameters:
  • message (str | None) – Explanation of the error

  • provider (ArgumentProvider) – Argument provider that failed

  • cause (Optional[Exception]) – Original exception that caused this error, if any

class pynenc.trigger.arguments.argument_providers.ArgumentProvider[source]

Bases: abc.ABC

Base class for argument providers.

Argument providers generate arguments for tasks based on trigger contexts.

_argument_provider_class_cache: ClassVar[dict[str, type[pynenc.trigger.arguments.argument_providers.ArgumentProvider]]]

None

_cache_initialized: ClassVar[bool]

False

classmethod _initialize_class_cache() None[source]

Initialize the condition class cache by recursively finding all subclasses.

classmethod get_argument_provider_class(argument_provider_type: str) type[pynenc.trigger.arguments.argument_providers.ArgumentProvider] | None[source]

Get an argument provider class by its name from the class cache.

Parameters:

argument_provider_type – Name of the argument provider class to find

Returns:

The argument provider class or None if not found

abstractmethod get_arguments(trigger_context: pynenc.trigger.trigger_context.TriggerContext) dict[str, Any][source]

Generate arguments for a task based on a trigger context.

Parameters:

trigger_context (TriggerContext) – Context containing the satisfied conditions

Returns:

Dictionary of arguments

Raises:

Exception – If the provider fails to generate arguments

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

abstractmethod _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.arguments.argument_providers.ArgumentProvider[source]

Create a argument provider instance from a JSON string.

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

Parameters:
  • json_str – JSON string containing serialized argument provider data

  • 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

abstractmethod classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.arguments.argument_providers.ArgumentProvider[source]

Create an argument provider instance from parsed JSON data.

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

Parameters:
  • data – Dictionary with argument provider data from JSON

  • app – Pynenc application instance for deserializing complex arguments

Returns:

A new instance of this argument provider class

Raises:

ValueError – If the data is invalid for this argument provider type

class pynenc.trigger.arguments.argument_providers.StaticArgumentProvider(arguments: dict[str, Any])[source]

Bases: pynenc.trigger.arguments.argument_providers.ArgumentProvider

Provides static arguments independent of trigger context.

Initialization

Initialize with fixed arguments.

Parameters:

arguments – Static arguments to provide

get_arguments(trigger_context: pynenc.trigger.trigger_context.TriggerContext) dict[str, Any][source]

Return the static arguments.

Parameters:

trigger_context – Ignored for static providers

Returns:

The static arguments dictionary

_to_json(app: pynenc.app.Pynenc) dict[str, Any][source]
classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.arguments.argument_providers.StaticArgumentProvider[source]
__eq__(value: Any) bool[source]

Check equality with another object.

Parameters:

value – Object to compare with

Returns:

True if equal, False otherwise

class pynenc.trigger.arguments.argument_providers.ContextCallable[source]

Bases: typing.Protocol[pynenc.trigger.arguments.argument_providers.C_contra]

Protocol for callables that process a specific context type.

__call__(context: pynenc.trigger.arguments.argument_providers.C_contra) dict[str, Any][source]
class pynenc.trigger.arguments.argument_providers.ContextTypeArgumentProvider(context_type: type[pynenc.trigger.arguments.argument_providers.C], callback: pynenc.trigger.arguments.argument_providers.ContextCallable[pynenc.trigger.arguments.argument_providers.C] | pynenc.trigger.arguments.arguments_common.SerializableCallable)[source]

Bases: pynenc.trigger.arguments.argument_providers.ArgumentProvider, typing.Generic[pynenc.trigger.arguments.argument_providers.C]

Generates arguments from a specific context type using a user-provided function.

Initialization

Initialize with context type and callback.

Parameters:
  • context_type – Type of context this provider handles

  • callback – Function to extract arguments from the context

get_arguments(trigger_context: pynenc.trigger.trigger_context.TriggerContext) dict[str, Any][source]
_to_json(app: pynenc.app.Pynenc) dict[str, Any][source]
classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.arguments.argument_providers.ContextTypeArgumentProvider[source]
class pynenc.trigger.arguments.argument_providers.DirectArgumentProvider(callback: collections.abc.Callable[[pynenc.trigger.trigger_context.TriggerContext], dict[str, Any]] | pynenc.trigger.arguments.arguments_common.SerializableCallable)[source]

Bases: pynenc.trigger.arguments.argument_providers.ArgumentProvider

Provides complete control over argument generation by giving direct access to the trigger context.

Initialization

Initialize with a callback that processes the entire trigger context.

Parameters:
  • callback – Function to extract arguments from the trigger context

  • fallback – If True, ignores failures and returns None; if False, raises exceptions

get_arguments(trigger_context: pynenc.trigger.trigger_context.TriggerContext) dict[str, Any][source]
_to_json(app: pynenc.app.Pynenc) dict[str, Any][source]
classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.arguments.argument_providers.DirectArgumentProvider[source]
class pynenc.trigger.arguments.argument_providers.CompositeArgumentProvider(providers: list[pynenc.trigger.arguments.argument_providers.ArgumentProvider])[source]

Bases: pynenc.trigger.arguments.argument_providers.ArgumentProvider

Combines multiple argument providers and merges their results.

Initialization

Initialize with a list of argument providers.

Parameters:

providers – List of argument providers to combine

get_arguments(trigger_context: pynenc.trigger.trigger_context.TriggerContext) dict[str, Any][source]
_to_json(app: pynenc.app.Pynenc) dict[str, Any][source]
classmethod _from_json(data: dict[str, Any], app: pynenc.app.Pynenc) pynenc.trigger.arguments.argument_providers.CompositeArgumentProvider[source]