Extract JSON data from subprocess output. Skips any print statements before the JSON output and parses the JSON. Args: output: Raw stdout from subprocess Returns: Parsed JSON as dictionary Raises: SystemExit: If JSON cannot be f
(output: str)
| 507 | |
| 508 | @staticmethod |
| 509 | def _extract_json_from_output(output: str) -> Dict[str, Dict[str, Any]]: |
| 510 | """Extract JSON data from subprocess output. |
| 511 | |
| 512 | Skips any print statements before the JSON output and parses the JSON. |
| 513 | |
| 514 | Args: |
| 515 | output: Raw stdout from subprocess |
| 516 | |
| 517 | Returns: |
| 518 | Parsed JSON as dictionary |
| 519 | |
| 520 | Raises: |
| 521 | SystemExit: If JSON cannot be found or parsed |
| 522 | """ |
| 523 | output_lines = output.strip().split('\n') |
| 524 | json_start = -1 |
| 525 | for i, line in enumerate(output_lines): |
| 526 | if line.strip().startswith('{'): |
| 527 | json_start = i |
| 528 | break |
| 529 | |
| 530 | if json_start == -1: |
| 531 | print("Error: Could not find JSON output from baseline", file=sys.stderr) |
| 532 | sys.exit(1) |
| 533 | |
| 534 | json_output = '\n'.join(output_lines[json_start:]) |
| 535 | try: |
| 536 | return json.loads(json_output) |
| 537 | except json.JSONDecodeError as e: |
| 538 | print(f"Error: Could not parse baseline JSON output: {e}", file=sys.stderr) |
| 539 | sys.exit(1) |
| 540 | |
| 541 | @staticmethod |
| 542 | def run_baseline_benchmark(baseline_python: str, args: argparse.Namespace) -> Dict[str, Dict[str, Any]]: |
no test coverage detected