Skip to content

fix(font manager): Allow Rebuilding Cache #30406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Servinjesus1
Copy link

One could never rebuild the cache given the existing conditional logic (premature return to exception based solely on fallback_to_default). Now, if a user disables fallback and enables rebuild, the rebuild logic will execute.

This allows a user to install a font and run:

import matplotlib.font_manager as fm
fm.findfont("Font Spec", fallback_to_default=False, rebuild_if_missing=True)

to force a rebuild of the font cache.

It was a simple fix to the conditional logic: if fallback is False, don't return with error if rebuild is True, but instead set result to empty string (used later in the rebuild code) so that the rebuild code can actually be proceeded to.

PR summary

PR checklist

  • new and changed code is tested

Tested on my font cache locally in my normal non-dev env.
Unless other ideas exist, a unit test would require:

  1. A dummy font file
  2. A way to create a temporary cache that does not affect the user's cache
  3. Updating of said cache with dummy font using above code
  4. Validation that cache has been updated
  5. Someone who's written unit tests (not me)

One could never rebuild the cache given the existing conditional logic (premature return to exception based solely on fallback_to_default). Now, if a user disables fallback and enables rebuild, the rebuild logic will execute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs review
Development

Successfully merging this pull request may close these issues.

2 participants