"""Stable JSON representation for RepoInfo artifacts.""" from __future__ import annotations from dataclasses import asdict import json from pathlib import Path from .repo_model import RepoInfo def to_dict(info: RepoInfo) -> dict: return asdict(info) def write_json(info: RepoInfo, path: str | Path) -> None: target = Path(path) temporary = target.with_suffix(target.suffix + ".part") temporary.write_text(json.dumps(to_dict(info), ensure_ascii=False, separators=(",", ":")) + "\n") temporary.replace(target)