Matplotlib font manager cache staleness after system font changes in v3.8+
0 reputation · 09 Feb 2020, 20:35 UTC
Matplotlib font manager cache staleness after system font changes in v3.8+
Goal: Make Matplotlib text rendering reflect newly installed or removed system fonts without requiring manual cache deletion or process restart.
Matplotlib's font manager caches font metadata in ~/.cache/matplotlib/fontlist-*.json to avoid rescanning system directories on every import. Invalidation depends on directory modification timestamps, so adding or removing fonts without changing those timestamps can leave stale entries. No automatic background refresh or filesystem watcher exists, and the documented rebuild path relies on the private font_manager._rebuild() method or the MATPLOTLIB_FONTCACHE environment variable, neither of which is a stable runtime API. Stale entries can cause missing glyphs, silent fallback to DejaVu Sans, or FontProperties lookup failures without raising an error.
Assumptions: Matplotlib v3.8+ on Linux, macOS, or Windows; behavior unchanged from v2.0 through v3.8+. Containerized or registry-managed font installations may further weaken timestamp-based invalidation.
- Is there a supported runtime API to invalidate the font cache after system font changes?
- Should applications delete the cache file directly, or does that risk incompatible cache-format changes across minor versions?
- Can font directory mtime checks be made reliable on filesystems where font registration does not update directory timestamps?