- mark task 04 as implemented in the project overview - add convert_json.py as the entry script for task 04 - clarify output paths for JSON-LD conversion artifacts
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Idempotent per-format updates to out/bench/storage_sizes.csv.
|
|
|
|
Contract (docs/rules/build-pipeline-tasks.md section 4): columns
|
|
format,variant,bytes; a task re-run REPLACES its own format's rows and never
|
|
touches other formats' rows.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
HEADER = "format,variant,bytes"
|
|
|
|
|
|
def update_storage_sizes(bench_dir: Path, fmt: str, variants: list[tuple[str, int]]) -> Path:
|
|
path = bench_dir / "storage_sizes.csv"
|
|
kept: list[str] = []
|
|
if path.exists():
|
|
lines = path.read_text(encoding="ascii").splitlines()
|
|
if lines and lines[0] != HEADER:
|
|
raise ValueError(f"{path}: unexpected header {lines[0]!r}")
|
|
kept = [ln for ln in lines[1:] if ln and ln.split(",", 1)[0] != fmt]
|
|
rows = kept + [f"{fmt},{variant},{nbytes}" for variant, nbytes in variants]
|
|
bench_dir.mkdir(parents=True, exist_ok=True)
|
|
with open(path, "w", encoding="ascii", newline="\n") as fh:
|
|
fh.write(HEADER + "\n" + "\n".join(rows) + "\n")
|
|
logger.info("storage_sizes.csv: %s -> %s", fmt, ", ".join(f"{v}={b}" for v, b in variants))
|
|
return path
|