@@ -197,26 +197,41 @@ def set_conditional_expr(self, expr):
197
197
198
198
Examples:
199
199
# GH #3644 construct conditional expression when one task name
200
- # is a substring of another: foo | xfoo => bar.
201
- # Add 'foo' to the 'satisfied' dict before 'xfoo'.
200
+ # is a substring of another: 11/foo | 1/foo => bar.
202
201
>>> preq = Prerequisite(1)
203
202
>>> preq[(1, 'foo', 'succeeded')] = False
204
- >>> preq[(1 , 'xfoo ', 'succeeded')] = False
205
- >>> preq.set_conditional_expr("1 /foo succeeded|1/xfoo succeeded")
203
+ >>> preq[(11 , 'foo ', 'succeeded')] = False
204
+ >>> preq.set_conditional_expr("11 /foo succeeded|1/foo succeeded")
206
205
>>> expr = preq.conditional_expression
207
206
>>> expr.split('|') # doctest: +NORMALIZE_WHITESPACE
208
- ['bool(self._satisfied[("1 ", "foo", "succeeded")])',
209
- 'bool(self._satisfied[("1", "xfoo ", "succeeded")])']
207
+ ['bool(self._satisfied[("11 ", "foo", "succeeded")])',
208
+ 'bool(self._satisfied[("1", "foo ", "succeeded")])']
210
209
210
+ # GH #6588 integer offset "x[-P2] | a" gives a negative cycle point
211
+ # during validation, for evaluation at the initial cycle point 1.
212
+ >>> preq = Prerequisite(1)
213
+ >>> preq[(-1, 'x', 'succeeded')] = False
214
+ >>> preq[(1, 'a', 'succeeded')] = False
215
+ >>> preq.set_conditional_expr("-1/x succeeded|1/a succeeded")
216
+ >>> expr = preq.conditional_expression
217
+ >>> expr.split('|') # doctest: +NORMALIZE_WHITESPACE
218
+ ['bool(self._satisfied[("-1", "x", "succeeded")])',
219
+ 'bool(self._satisfied[("1", "a", "succeeded")])']
211
220
"""
212
221
self ._cached_satisfied = None
213
222
if '|' in expr :
214
223
# Make a Python expression so we can eval() the logic.
215
224
for t_output in self ._satisfied :
216
225
# Use '\b' in case one task name is a substring of another
217
226
# and escape special chars ('.', timezone '+') in task IDs.
227
+ msg = self .MESSAGE_TEMPLATE % t_output
228
+ if msg [0 ] == '-' :
229
+ # -ve cycles: \b needs to be to the right of the `-` char.
230
+ pattern = fr"-\b{ re .escape (msg [1 :])} \b"
231
+ else :
232
+ pattern = fr"\b{ re .escape (msg )} \b"
218
233
expr = re .sub (
219
- fr"\b { re . escape ( self . MESSAGE_TEMPLATE % t_output ) } \b" ,
234
+ pattern ,
220
235
self .SATISFIED_TEMPLATE % t_output ,
221
236
expr
222
237
)
0 commit comments