|
8 | 8 | any <pre>...</pre> blocks containing "thrpt" under the `benchmarks/` module |
9 | 9 | (files such as Java sources with embedded example output in javadocs). |
10 | 10 |
|
11 | | -Usage: ./scripts/update_benchmarks.py [--mvnw ./mvnw] [--module benchmarks] [--java java] [--jmh-args "-f 1 -wi 0 -i 1"] |
| 11 | +Usage: ./.mise/tasks/update_benchmarks.py [--mvnw ./mvnw] [--module benchmarks] [--java java] [--jmh-args "-f 1 -wi 0 -i 1"] |
12 | 12 |
|
13 | 13 | By default this will: |
14 | 14 | - run the maven wrapper to package the benchmarks: `./mvnw -pl benchmarks -am -DskipTests package` |
|
32 | 32 |
|
33 | 33 |
|
34 | 34 | def run_cmd(cmd: List[str], cwd: Optional[str] = None) -> str: |
35 | | - proc = subprocess.run(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 35 | + """Run a command, stream stdout/stderr to the console for progress, and return the full output. |
| 36 | +
|
| 37 | + This replaces the previous blocking subprocess.run approach so users can see build / JMH |
| 38 | + progress in real time while the command runs. |
| 39 | + """ |
| 40 | + try: |
| 41 | + proc = subprocess.Popen(cmd, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 42 | + except FileNotFoundError: |
| 43 | + # Helpful message if the executable is not found |
| 44 | + print(f"Command not found: {cmd[0]}") |
| 45 | + raise |
| 46 | + |
| 47 | + output_lines: List[str] = [] |
| 48 | + try: |
| 49 | + assert proc.stdout is not None |
| 50 | + # Stream lines as they appear and capture them for returning |
| 51 | + for line in proc.stdout: |
| 52 | + # Print immediately so callers (and CI) can observe progress |
| 53 | + print(line, end='') |
| 54 | + output_lines.append(line) |
| 55 | + proc.wait() |
| 56 | + except KeyboardInterrupt: |
| 57 | + # If the user interrupts, ensure the child process is terminated |
| 58 | + proc.kill() |
| 59 | + proc.wait() |
| 60 | + print('\nCommand interrupted by user.') |
| 61 | + raise |
| 62 | + |
| 63 | + output = ''.join(output_lines) |
36 | 64 | if proc.returncode != 0: |
37 | | - print(f"Command failed: {' '.join(cmd)}\nExit: {proc.returncode}\nOutput:\n{proc.stdout}") |
| 65 | + print(f"Command failed: {' '.join(cmd)}\nExit: {proc.returncode}\nOutput:\n{output}") |
38 | 66 | raise SystemExit(proc.returncode) |
39 | | - return proc.stdout |
| 67 | + return output |
40 | 68 |
|
41 | 69 |
|
42 | 70 | def build_benchmarks(mvnw: str, module: str) -> None: |
|
0 commit comments