MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _clean_conversion_cache

Function _clean_conversion_cache

lib/matplotlib/testing/compare.py:344–364  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

342
343
344def _clean_conversion_cache():
345 # This will actually ignore mpl_toolkits baseline images, but they're
346 # relatively small.
347 baseline_images_size = sum(
348 path.stat().st_size
349 for path in Path(mpl.__file__).parent.glob("**/baseline_images/**/*"))
350 # 2x: one full copy of baselines, and one full copy of test results
351 # (actually an overestimate: we don't convert png baselines and results).
352 max_cache_size = 2 * baseline_images_size
353 # Reduce cache until it fits.
354 with cbook._lock_path(_get_cache_path()):
355 cache_stat = {
356 path: path.stat() for path in _get_cache_path().glob("*")}
357 cache_size = sum(stat.st_size for stat in cache_stat.values())
358 paths_by_atime = sorted( # Oldest at the end.
359 cache_stat, key=lambda path: cache_stat[path].st_atime,
360 reverse=True)
361 while cache_size > max_cache_size:
362 path = paths_by_atime.pop()
363 cache_size -= cache_stat[path].st_size
364 path.unlink()
365
366
367@functools.cache # Ensure this is only registered once.

Callers

nothing calls this directly

Calls 4

PathClass · 0.85
_get_cache_pathFunction · 0.85
valuesMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…