33from pathlib import Path
44from subprocess import run
55from time import perf_counter
6+ from concurrent .futures import ThreadPoolExecutor , as_completed
7+ import os
8+
9+
10+ def _run_linter (path : Path ):
11+ """Run a single linter and return (name, returncode, duration, stdout, stderr).
12+
13+ We capture output so concurrent runs don't interleave in the terminal.
14+ """
15+ name = path .name
16+ start = perf_counter ()
17+ res = run ([str (path )], capture_output = True , text = True )
18+ duration = perf_counter () - start
19+ return {
20+ "name" : name ,
21+ "path" : path ,
22+ "returncode" : res .returncode ,
23+ "duration" : duration ,
24+ "stdout" : res .stdout ,
25+ "stderr" : res .stderr ,
26+ }
627
728
829def main ():
@@ -12,14 +33,32 @@ def main():
1233 p for p in linters_dir .iterdir () if p .is_file () and p .name .startswith ("lint-" )
1334 )
1435
36+ results = []
1537 rc = 0
16- for lint in linters :
17- res = run ([str (lint )])
18- if res .returncode :
19- print (f"^---- failure(s) from { lint .name } \n " )
20- rc |= res .returncode
2138
22- print (f"{ len (linters )} linters in { perf_counter () - start :0.2f} s" )
39+ max_workers = min (32 , len (linters ))
40+ with ThreadPoolExecutor (max_workers = max_workers ) as ex :
41+ futures = {ex .submit (_run_linter , lint ): lint for lint in linters }
42+ for fut in as_completed (futures ):
43+ res = fut .result ()
44+ results .append (res )
45+ rc |= res ["returncode" ]
46+ print (f" { res ['duration' ]:0.2f} s { "⛔" if res ['returncode' ] else "✅" } { res ['name' ]} " )
47+
48+
49+ # Print failures first (with captured output), then a brief timing summary.
50+ print ()
51+ failures = [r for r in results if r ["returncode" ]]
52+ for r in failures :
53+ if r ["stdout" ]:
54+ print (r ["stdout" ].rstrip ())
55+ if r ["stderr" ]:
56+ print (r ["stderr" ].rstrip ())
57+ print (f"^---- failure(s) from { r ['name' ]} \n " )
58+ print ()
59+
60+ total_duration = perf_counter () - start
61+ print (f"{ len (linters )} linters in { total_duration :0.2f} s" )
2362 raise SystemExit (rc )
2463
2564
0 commit comments