MCPcopy Create free account
hub / github.com/psf/black / write_cache

Function write_cache

src/black/cache.py:84–97  ·  view source on GitHub ↗

Update the cache file.

(cache: Cache, sources: Iterable[Path], mode: Mode)

Source from the content-addressed store, hash-verified

82
83
84def write_cache(cache: Cache, sources: Iterable[Path], mode: Mode) -> None:
85 """Update the cache file."""
86 cache_file = get_cache_file(mode)
87 try:
88 CACHE_DIR.mkdir(parents=True, exist_ok=True)
89 new_cache = {
90 **cache,
91 **{str(src.resolve()): get_cache_info(src) for src in sources},
92 }
93 with tempfile.NamedTemporaryFile(dir=str(cache_file.parent), delete=False) as f:
94 pickle.dump(new_cache, f, protocol=4)
95 os.replace(f.name, cache_file)
96 except OSError:
97 pass

Callers 2

reformat_oneFunction · 0.90
schedule_formattingFunction · 0.90

Calls 4

get_cache_fileFunction · 0.85
get_cache_infoFunction · 0.85
dumpMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected