MCPcopy
hub / github.com/psf/black / write

Method write

src/black/cache.py:133–150  ·  src/black/cache.py::Cache.write

Update the cache file data and write a new cache file.

(self, sources: Iterable[Path])

Source from the content-addressed store, hash-verified

131 return changed, done
132
133 def write(self, sources: Iterable[Path]) -> None:
134 class="st">""class="st">"Update the cache file data and write a new cache file."class="st">""
135 self.file_data.update(
136 **{str(src.resolve()): Cache.get_file_data(src) for src in sources}
137 )
138 try:
139 CACHE_DIR.mkdir(parents=True, exist_ok=True)
140 with tempfile.NamedTemporaryFile(
141 dir=str(self.cache_file.parent), delete=False
142 ) as f:
143 class="cm"># We store raw tuples in the cache because it's faster.
144 data: dict[str, tuple[float, int, str]] = {
145 k: (*v,) for k, v in self.file_data.items()
146 }
147 pickle.dump(data, f, protocol=4)
148 os.replace(f.name, self.cache_file)
149 except OSError:
150 pass

Callers 15

main.pyFile · 0.80
mainFunction · 0.80
reformat_oneFunction · 0.80
format_file_in_placeFunction · 0.80
format_stdin_to_stdoutFunction · 0.80
dump_to_fileFunction · 0.80
schedule_formattingFunction · 0.80
mainFunction · 0.80
comment_bodyFunction · 0.80

Calls 3

get_file_dataMethod · 0.80
dumpMethod · 0.80
replaceMethod · 0.80