| 481 | |
| 482 | |
| 483 | def write_csv(path: Path, rows: Sequence[Dict[str, Any]]) -> None: |
| 484 | path.parent.mkdir(parents=True, exist_ok=True) |
| 485 | if not rows: |
| 486 | path.write_text("", encoding="utf-8") |
| 487 | return |
| 488 | fields = list(rows[0].keys()) |
| 489 | with path.open("w", encoding="utf-8", newline="") as handle: |
| 490 | writer = csv.DictWriter(handle, fieldnames=fields) |
| 491 | writer.writeheader() |
| 492 | for row in rows: |
| 493 | writer.writerow(row) |
| 494 | |
| 495 | |
| 496 | def write_markdown(path: Path, rows: Sequence[Dict[str, Any]], context: Dict[str, Any]) -> None: |