the-stack-go / stackgo /stackbuild /repo_serialization.py
s0duku's picture
Add end-to-end stackgo pipeline
f764cdf verified
Raw History Blame Contribute Delete
535 Bytes
"""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)