|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import json |
| 3 | +import os |
| 4 | +from pathlib import Path |
| 5 | +from typing import Dict, List |
| 6 | + |
| 7 | + |
| 8 | +def generate_markdown_table(files_data: List[tuple[str, Dict]]) -> str: |
| 9 | + """Generate a markdown table from the capabilities data.""" |
| 10 | + if not files_data: |
| 11 | + return "No capability files found." |
| 12 | + |
| 13 | + all_caps = set() |
| 14 | + for _, data in files_data: |
| 15 | + all_caps.update(data.keys()) |
| 16 | + all_caps = sorted(all_caps) |
| 17 | + |
| 18 | + lines = [ |
| 19 | + "| Model | " + " | ".join(c.replace('_', ' ') for c in all_caps) + " |", |
| 20 | + "|" + "|".join("-" * (len(cap) + 2) for cap in ["Model"] + list(all_caps)) + "|", |
| 21 | + ] |
| 22 | + |
| 23 | + # Sort data by most supports and least requires |
| 24 | + def sort_key(item): |
| 25 | + model, data = item |
| 26 | + supports_count = sum(1 for k, v in data.items() |
| 27 | + if k.startswith("supports_") and str(v).lower() == "true") |
| 28 | + requires_count = sum(1 for k, v in data.items() |
| 29 | + if k.startswith("requires_") and str(v).lower() == "true") |
| 30 | + return (-supports_count, requires_count) # negative for descending supports |
| 31 | + |
| 32 | + for model, data in sorted(files_data, key=sort_key): |
| 33 | + model_name = os.path.basename(model).replace(".caps.json", "") |
| 34 | + row = [model_name] |
| 35 | + for cap in all_caps: |
| 36 | + raw_value = str(data.get(cap, "N/A")).lower() |
| 37 | + if raw_value == "true": |
| 38 | + if cap.startswith("supports_"): |
| 39 | + value = "✅" |
| 40 | + elif cap.startswith("requires_"): |
| 41 | + value = "⚠️" |
| 42 | + else: |
| 43 | + value = raw_value |
| 44 | + elif raw_value == "false": |
| 45 | + value = "" |
| 46 | + else: |
| 47 | + value = raw_value |
| 48 | + row.append(value) |
| 49 | + lines.append("| " + " | ".join(row) + " |") |
| 50 | + |
| 51 | + return "\n".join(lines) |
| 52 | + |
| 53 | +def main(): |
| 54 | + script_dir = Path(__file__).parent |
| 55 | + build_dir = script_dir.parent / "build" |
| 56 | + |
| 57 | + files_data = [ |
| 58 | + (str(f), json.loads(f.read_text())) |
| 59 | + for f in list((build_dir / "tests").rglob("*.caps.json")) |
| 60 | + ] |
| 61 | + |
| 62 | + markdown = generate_markdown_table(files_data) |
| 63 | + |
| 64 | + (build_dir / "capabilities.md").write_text(markdown) |
| 65 | + |
| 66 | + print(markdown) |
| 67 | + |
| 68 | +if __name__ == "__main__": |
| 69 | + main() |
0 commit comments