1616from _pytask .outcomes import Persisted
1717from _pytask .outcomes import Skipped
1818from _pytask .report import ExecutionReport
19+ from _pytask .shared import get_first_non_none_value
1920from _pytask .shared import reduce_node_name
2021from _pytask .traceback import format_exception_without_traceback
2122from _pytask .traceback import remove_traceback_from_exc_info
2223from _pytask .traceback import render_exc_info
2324
2425
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+
2543@hookimpl
2644def pytask_execute (session ):
2745 """Execute tasks."""
@@ -172,10 +190,17 @@ def pytask_execute_task_log_end(report):
172190 console .print (report .symbol , style = report .color , end = "" )
173191
174192
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+
175201@hookimpl
176202def pytask_execute_log_end (session , reports ):
177203 session .execution_end = time .time ()
178- show_locals = session .config ["show_locals" ]
179204
180205 n_failed = len (reports ) - sum (report .success for report in reports )
181206 n_skipped = sum (
@@ -195,27 +220,7 @@ def pytask_execute_log_end(session, reports):
195220
196221 for report in reports :
197222 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 )
219224
220225 session .hook .pytask_log_session_footer (
221226 session = session ,
@@ -235,6 +240,28 @@ def pytask_execute_log_end(session, reports):
235240 return True
236241
237242
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+
238265def _update_states_in_database (dag , task_name ):
239266 """Update the state for each node of a task in the database."""
240267 for name in node_and_neighbors (dag , task_name ):
0 commit comments