(path: Path, payload: object)
| 47 | |
| 48 | |
| 49 | def atomic_write_json(path: Path, payload: object) -> None: |
| 50 | path.parent.mkdir(parents=True, exist_ok=True) |
| 51 | with tempfile.NamedTemporaryFile("w", encoding="utf-8", dir=path.parent, delete=False) as handle: |
| 52 | json.dump(payload, handle, indent=2, sort_keys=True) |
| 53 | handle.write("\n") |
| 54 | temp_name = handle.name |
| 55 | os.replace(temp_name, path) |
| 56 | |
| 57 | |
| 58 | def atomic_write_text(path: Path, content: str) -> None: |
no outgoing calls