@@ -249,7 +249,9 @@ def pytask_log_session_footer(session: Session) -> None:
249
249
grouped_warnings [warning .message ].append (location )
250
250
sorted_gw = {k : sorted (v ) for k , v in grouped_warnings .items ()}
251
251
252
- renderable = MyRenderable (sorted_gw )
252
+ reduced_gw = _reduce_grouped_warnings (sorted_gw )
253
+
254
+ renderable = MyRenderable (reduced_gw )
253
255
254
256
panel = Panel (renderable , title = "Warnings" , style = "warning" )
255
257
console .print (panel )
@@ -271,3 +273,19 @@ def __rich_console__(
271
273
"[bold red]♥[/bold red] "
272
274
+ "https://pytask-dev.rtdf.io/en/stable/how_to_guides/capture_warnings.html"
273
275
)
276
+
277
+
278
+ def _reduce_grouped_warnings (
279
+ grouped_warnings : dict [str , list [str ]], max_locations : int = 5
280
+ ) -> dict [str , list [str ]]:
281
+ """Reduce grouped warnings."""
282
+ reduced_gw = {}
283
+ for message , locations in grouped_warnings .items ():
284
+ if len (locations ) > max_locations :
285
+ adjusted_locations = locations [:max_locations ]
286
+ n_more_locations = len (locations [max_locations :])
287
+ adjusted_locations .append (f"... in { n_more_locations } more locations." )
288
+ else :
289
+ adjusted_locations = locations
290
+ reduced_gw [message ] = adjusted_locations
291
+ return reduced_gw
0 commit comments