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

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""" 

7 

8from __future__ import annotations 

9 

10from enum import Enum, IntEnum, StrEnum, auto 

11 

12 

13class ProcessorExitStatus(IntEnum): 

14 """The processor exit status enumerator class 

15 

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 

19 

20 """ 

21 

22 Successful = auto() 

23 """The processor execution was successfully concluded""" 

24 

25 Failed = auto() 

26 """The processor execution was failed""" 

27 

28 Aborted = auto() 

29 """The processor execution was aborted by the user""" 

30 

31 

32class ProcessorStatus(StrEnum): 

33 """Enumerator to describe the status of a processor.""" 

34 

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""" 

45 

46 

47class LoopingStatus(IntEnum): 

48 """ 

49 Enumerator to modify the looping cycle. 

50 

51 In the case of a looping Processor, the user has the ability to slightly modify the looping structure using this 

52 enumerator. 

53 

54 In the :meth:`~mafw.processor.Processor.process` the user can set the variable `looping_status` to one of the following values: 

55 

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. 

58 

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. 

61 

62 - :attr:`LoopingStatus.Abort`. The cycle is broken immediately. 

63 

64 - :attr:`LoopingStatus.Quit`. The cycle is broken immediately. 

65 

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 """ 

71 

72 Continue = auto() 

73 """The loop can continue""" 

74 

75 #: Skip this item. 

76 Skip = auto() 

77 

78 #: Break the loop and force the outside container (:class:`mafw.processor.ProcessorList`) to quit. 

79 Abort = auto() 

80 

81 #: Break the loop but let the outside container (:class:`mafw.processor.ProcessorList`) to continue. 

82 Quit = auto() 

83 

84 

85class LoopType(StrEnum): 

86 """ 

87 The loop strategy for the processor. 

88 

89 Each processor can be executed in one of the following modes: 

90 

91 #. **Single mode.** The process method is executed only once. 

92 

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. 

96 

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. 

102 

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. 

108 

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. 

111 

112 """ 

113 

114 SingleLoop = 'single' 

115 """Value for the single mode execution.""" 

116 

117 ForLoop = 'for_loop' 

118 """Value for the for loop on item list execution.""" 

119 

120 ParallelForLoop = 'parallel_for_loop' 

121 """Value for the parallel for loop on item list execution.""" 

122 

123 ParallelForLoopWithQueue = 'parallel_for_loop_with_queue' 

124 """Value for the parallel for loop with queue execution.""" 

125 

126 WhileLoop = 'while_loop' 

127 """Value for the while loop execution.""" 

128 

129 

130class LogicalOp(Enum): 

131 """ 

132 Enumeration of supported logical operations. 

133 

134 .. versionadded:: v1.3.0 

135 """ 

136 

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