mafw.processor.processor_list

ProcessorList container for orchestrating sequences of processors.

This module defines ProcessorList, a specialised list that holds Processor instances (or nested ProcessorLists) and executes them sequentially. It manages shared resources — timer, user interface, and database connection — distributing them to each processor before execution.

Scientists typically construct a ProcessorList in their analysis script, populate it with processor instances representing successive analysis steps, and call execute() to run the full pipeline.

Added in version 2.3: Extracted from the monolithic processor.py module for improved maintainability and focused testing.

Classes

ProcessorList(*args[, name, description, ...])

A list like collection of processors.

class mafw.processor.processor_list.ProcessorList(*args: Processor | ProcessorList, name: str | None = None, description: str | None = None, timer: Timer | None = None, timer_params: dict[str, Any] | None = None, user_interface: UserInterfaceBase | None = None, database: Database | None = None, database_conf: dict[str, Any] | None = None, create_standard_tables: bool = True)[source]

Bases: list[Processor | ProcessorList]

A list like collection of processors.

ProcessorList is a subclass of list containing only Processor subclasses or other ProcessorList.

An attempt to add an element that is not a Processor or a ProcessorList will raise a TypeError.

Along with an iterable of processors, a new processor list can be built using the following parameters.

Constructor parameters:

Parameters:
  • name (str, Optional) – The name of the processor list. Defaults to ProcessorList.

  • description (str, Optional) – An optional short description. Default to ProcessorList.

  • timer (Timer, Optional) – The timer object. If None is provided, a new one will be created. Defaults to None.

  • timer_params (dict, Optional) – A dictionary of parameter to build the timer object. Defaults to None.

  • user_interface (UserInterfaceBase, Optional) – A user interface. Defaults to None

  • database (Database, Optional) – A database instance. Defaults to None.

  • database_conf (dict, Optional) – Configuration for the database. Default to None.

  • create_standard_tables (bool, Optional) – Whether or not to create the standard tables. Defaults to True.

static validate_item(item: Processor | ProcessorList) Processor | ProcessorList[source]

Validates the item being added.

static validate_items(items: tuple[Processor | ProcessorList, ...] = ()) tuple[Processor | ProcessorList, ...][source]

Validates a tuple of items being added.

acquire_resources() None[source]

Acquires external resources.

The resource acquisition strategy mirrors processor.Processor.acquire_resources(): if a resource (timer, database) is already provided, it is reused; otherwise a new one is created and registered with the exit stack for automatic cleanup.

append(_ProcessorList__object: Processor | ProcessorList) None[source]

Appends a new processor at the end of the list.

distribute_resources(processor: Processor | Self) None[source]

Distributes the external resources to the items in the list.

execute() ProcessorExitStatus[source]

Execute the list of processors.

Similarly to the processor.Processor, ProcessorList can be executed. In simple words, the execute method of each processor in the list is called exactly in the same sequence as they were added.

extend(_ProcessorList__iterable: Iterable[Processor | ProcessorList]) None[source]

Extends the processor list with a list of processors.

insert(_ProcessorList__index: SupportsIndex, _ProcessorList__object: Processor | ProcessorList) None[source]

Adds a new processor at the specified index.

create_standard_tables

The boolean flag to proceed or skip with standard table creation and initialisation

property database: Database

Returns the database instance

Returns:

A database instance

Raises:

MissingDatabase – if a database connection is missing.

property name: str

The name of the processor list

Returns:

The name of the processor list

Return type:

str

nested_list

Boolean flag to identify that this list is actually inside another list.

Similarly to the local resource flag for the base.Processor, this flag prevent the user interface to be added to the resource stack.

property processor_exit_status: ProcessorExitStatus

The processor exit status.

It refers to the whole processor list execution.