Coverage for src / mafw / enumerators.py: 100%
54 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-30 16:10 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-30 16:10 +0000
1# Copyright 2025–2026 European Union
2# Author: Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)
3# SPDX-License-Identifier: EUPL-1.2
4"""
5Module provides a set of enumerators for dealing with standard tasks.
6"""
8from __future__ import annotations
10from enum import Enum, IntEnum, StrEnum, auto
13class ProcessorExitStatus(IntEnum):
14 """The processor exit status enumerator class
16 * Successful: means that the processor reached the end with success
17 * Failed: means that the processor did not reach the end with success
18 * Aborted: means that the user aborted the processor execution
20 """
22 Successful = auto()
23 """The processor execution was successfully concluded"""
25 Failed = auto()
26 """The processor execution was failed"""
28 Aborted = auto()
29 """The processor execution was aborted by the user"""
32class ProcessorStatus(StrEnum):
33 """Enumerator to describe the status of a processor."""
35 Unknown = 'unknown'
36 """Unknown status"""
37 Init = 'initializing'
38 """Initialized"""
39 Start = 'starting'
40 """Started"""
41 Run = 'processing'
42 """Running"""
43 Finish = 'finishing'
44 """Finished"""
47class LoopingStatus(IntEnum):
48 """
49 Enumerator to modify the looping cycle.
51 In the case of a looping Processor, the user has the ability to slightly modify the looping structure using this
52 enumerator.
54 In the :meth:`~mafw.processor.Processor.process` the user can set the variable `looping_status` to one of the following values:
56 - :attr:`LoopingStatus.Continue`. It means that everything is working well and the loop cycle must go ahead as
57 foreseen and the :meth:`~mafw.processor.Processor.accept_item` will be invoked.
59 - :attr:`LoopingStatus.Skip`. The :meth:`~mafw.processor.Processor.skip_item` will be called soon after the
60 :meth:`~mafw.processor.Processor.process` is finished. The status will be reset to Continue and the next item will be processed.
62 - :attr:`LoopingStatus.Abort`. The cycle is broken immediately.
64 - :attr:`LoopingStatus.Quit`. The cycle is broken immediately.
66 The last two options are apparently identical, but they offer the possibility to implement a different behaviour
67 in the :meth:`~mafw.processor.Processor.finish` method. When abort is used, then the
68 :class:`~mafw.mafw_errors.AbortProcessorException` will be raised. For example, the user can decide to rollback
69 all changes if an abort as occurred or to save what done so far in case of a quit.
70 """
72 Continue = auto()
73 """The loop can continue"""
75 #: Skip this item.
76 Skip = auto()
78 #: Break the loop and force the outside container (:class:`mafw.processor.ProcessorList`) to quit.
79 Abort = auto()
81 #: Break the loop but let the outside container (:class:`mafw.processor.ProcessorList`) to continue.
82 Quit = auto()
85class LoopType(StrEnum):
86 """
87 The loop strategy for the processor.
89 Each processor can be executed in one of the following modes:
91 #. **Single mode.** The process method is executed only once.
93 #. **For loop mode.** The process method is executed inside a for loop after the start and before the finish. The
94 loop is based on a list of elements, the user **must** overload the :meth:`~mafw.processor.Processor.get_items`
95 method to define the list of items for the loop.
97 #. **Parallel for loop mode.** Conceptually identical to the for loop mode, but instead of a serial
98 processing, items are shared among a pool of different threads. This looping mode is only available when
99 running with a `free-threading <https://docs.python.org/3/howto/free-threading-python.html>`__ version of
100 Python (recommended >= 3.14.4). In case free-threading is not available, the item processing will
101 automatically fall back to the serial for loop mode.
103 #. **Parallel for loop with queue mode.** Similar to the parallel for loop, but processed items are pushed to
104 a queue and handled by a single consumer thread. This allows serialized handling of
105 :meth:`~mafw.processor.Processor.accept_item` and :meth:`~mafw.processor.Processor.skip_item` while still
106 distributing the main processing over multiple workers. As with the parallel for loop, this execution
107 mode is only available with free-threading and falls back to the serial for loop otherwise.
109 #. **While loop mode.** The process method is executed inside a while loop after the start and before the finish.
110 The user **must** overload the :meth:`~mafw.processor.Processor.while_condition` to define when to stop the loop.
112 """
114 SingleLoop = 'single'
115 """Value for the single mode execution."""
117 ForLoop = 'for_loop'
118 """Value for the for loop on item list execution."""
120 ParallelForLoop = 'parallel_for_loop'
121 """Value for the parallel for loop on item list execution."""
123 ParallelForLoopWithQueue = 'parallel_for_loop_with_queue'
124 """Value for the parallel for loop with queue execution."""
126 WhileLoop = 'while_loop'
127 """Value for the while loop execution."""
130class LogicalOp(Enum):
131 """
132 Enumeration of supported logical operations.
134 .. versionadded:: v1.3.0
135 """
137 EQ = '==' # Equal
138 NE = '!=' # Not equal
139 LT = '<' # Less than
140 LE = '<=' # Less than or equal
141 GT = '>' # Greater than
142 GE = '>=' # Greater than or equal
143 GLOB = 'GLOB' # String pattern matching
144 LIKE = 'LIKE' # SQL LIKE pattern matching
145 REGEXP = 'REGEXP' # Regular expression matching
146 IN = 'IN' # Value in list
147 NOT_IN = 'NOT_IN' # Value not in list
148 BETWEEN = 'BETWEEN' # Value between two bounds
149 BIT_AND = 'BIT_AND' # Bitwise AND
150 BIT_OR = 'BIT_OR' # Bitwise OR
151 IS_NULL = 'IS_NULL' # Field is NULL
152 IS_NOT_NULL = 'IS_NOT_NULL' # Field is not NULL