MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / write_json_atomic

Function write_json_atomic

graphify/paths.py:328–343  ·  view source on GitHub ↗

Atomically write ``obj`` as JSON to ``path``, streaming large top-level lists in C-encoded chunks rather than materializing the whole string first (matters for very large graphs). ``ensure_ascii`` mirrors ``json.dump`` so callers that emit raw UTF-8 (non-ASCII labels/paths) keep byte-for

(
    path: "str | Path", obj, *, indent: "int | None" = None, ensure_ascii: bool = True, compact: bool = False
)

Source from the content-addressed store, hash-verified

326
327
328def write_json_atomic(
329 path: "str | Path", obj, *, indent: "int | None" = None, ensure_ascii: bool = True, compact: bool = False
330) -> None:
331 """Atomically write ``obj`` as JSON to ``path``, streaming large top-level lists
332 in C-encoded chunks rather than materializing the whole string first (matters
333 for very large graphs). ``ensure_ascii`` mirrors ``json.dump`` so callers that
334 emit raw UTF-8 (non-ASCII labels/paths) keep byte-for-byte output. ``compact``
335 writes one line with no padding after ``,``/``:`` (graph.json, #3413). See
336 :func:`_atomic_replace`."""
337 separators = (",", ":") if compact else None
338 _atomic_replace(
339 path,
340 lambda f: _write_json_payload(
341 f, obj, indent=indent, ensure_ascii=ensure_ascii, separators=separators
342 ),
343 )
344
345# Directory segments that, when they appear as a whole path component, mark the
346# whole path as a test location. Matched against path *segments* (not raw

Calls 2

_atomic_replaceFunction · 0.85
_write_json_payloadFunction · 0.85