File size: 535 Bytes
f764cdf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | """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)
|