16
16
from _pytask .outcomes import Persisted
17
17
from _pytask .outcomes import Skipped
18
18
from _pytask .report import ExecutionReport
19
+ from _pytask .shared import get_first_non_none_value
19
20
from _pytask .shared import reduce_node_name
20
21
from _pytask .traceback import format_exception_without_traceback
21
22
from _pytask .traceback import remove_traceback_from_exc_info
22
23
from _pytask .traceback import render_exc_info
23
24
24
25
26
+ @hookimpl
27
+ def pytask_post_parse (config ):
28
+ if config ["show_errors_immediately" ]:
29
+ config ["pm" ].register (ShowErrorsImmediatelyPlugin )
30
+
31
+
32
+ @hookimpl
33
+ def pytask_parse_config (config , config_from_cli , config_from_file ):
34
+ config ["show_errors_immediately" ] = get_first_non_none_value (
35
+ config_from_cli ,
36
+ config_from_file ,
37
+ key = "show_errors_immediately" ,
38
+ default = False ,
39
+ callback = lambda x : x if x is None else bool (x ),
40
+ )
41
+
42
+
25
43
@hookimpl
26
44
def pytask_execute (session ):
27
45
"""Execute tasks."""
@@ -172,10 +190,17 @@ def pytask_execute_task_log_end(report):
172
190
console .print (report .symbol , style = report .color , end = "" )
173
191
174
192
193
+ class ShowErrorsImmediatelyPlugin :
194
+ @staticmethod
195
+ @hookimpl (tryfirst = True )
196
+ def pytask_execute_task_log_end (session , report ):
197
+ if not report .success :
198
+ _print_errored_task_report (session , report )
199
+
200
+
175
201
@hookimpl
176
202
def pytask_execute_log_end (session , reports ):
177
203
session .execution_end = time .time ()
178
- show_locals = session .config ["show_locals" ]
179
204
180
205
n_failed = len (reports ) - sum (report .success for report in reports )
181
206
n_skipped = sum (
@@ -195,27 +220,7 @@ def pytask_execute_log_end(session, reports):
195
220
196
221
for report in reports :
197
222
if not report .success :
198
-
199
- task_name = reduce_node_name (report .task , session .config ["paths" ])
200
- if len (task_name ) > console .width - 15 :
201
- task_name = report .task .base_name
202
- console .rule (
203
- f"[{ ColorCode .FAILED } ]Task { task_name } failed" , style = ColorCode .FAILED
204
- )
205
-
206
- console .print ()
207
-
208
- if report .exc_info and isinstance (report .exc_info [1 ], Exit ):
209
- console .print (format_exception_without_traceback (report .exc_info ))
210
- else :
211
- console .print (render_exc_info (* report .exc_info , show_locals ))
212
-
213
- console .print ()
214
- show_capture = session .config ["show_capture" ]
215
- for when , key , content in report .sections :
216
- if key in ("stdout" , "stderr" ) and show_capture in (key , "all" ):
217
- console .rule (f"Captured { key } during { when } " , style = None )
218
- console .print (content )
223
+ _print_errored_task_report (session , report )
219
224
220
225
session .hook .pytask_log_session_footer (
221
226
session = session ,
@@ -235,6 +240,28 @@ def pytask_execute_log_end(session, reports):
235
240
return True
236
241
237
242
243
+ def _print_errored_task_report (session , report ):
244
+ """Print the traceback and the exception of an errored report."""
245
+ task_name = reduce_node_name (report .task , session .config ["paths" ])
246
+ if len (task_name ) > console .width - 15 :
247
+ task_name = report .task .base_name
248
+ console .rule (f"[{ ColorCode .FAILED } ]Task { task_name } failed" , style = ColorCode .FAILED )
249
+
250
+ console .print ()
251
+
252
+ if report .exc_info and isinstance (report .exc_info [1 ], Exit ):
253
+ console .print (format_exception_without_traceback (report .exc_info ))
254
+ else :
255
+ console .print (render_exc_info (* report .exc_info , session .config ["show_locals" ]))
256
+
257
+ console .print ()
258
+ show_capture = session .config ["show_capture" ]
259
+ for when , key , content in report .sections :
260
+ if key in ("stdout" , "stderr" ) and show_capture in (key , "all" ):
261
+ console .rule (f"Captured { key } during { when } " , style = None )
262
+ console .print (content )
263
+
264
+
238
265
def _update_states_in_database (dag , task_name ):
239
266
"""Update the state for each node of a task in the database."""
240
267
for name in node_and_neighbors (dag , task_name ):
0 commit comments