()
| 342 | |
| 343 | |
| 344 | def _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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…