Skip to content

FontManager fixes. #15941

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

Merged
merged 1 commit into from
Jun 25, 2020
Merged

FontManager fixes. #15941

merged 1 commit into from
Jun 25, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Dec 15, 2019

Previously, when using findfont with rebuild_is_missing (the default)
_rebuild() would generate a new fontManager instance, but because
findfont is defined as findfont = fontManager.findfont, this would
keep using the old fontManager instance; we can't just fix this with
def findfont(...): return fontManager.findfont(...) because people may
be importing the fontManager instance anyways and not benefitting from
the rebuilt one.

Instead, overwrite(!) the contents of the existing fontManager instance
with the new one as needed.

@timhoffm IIRC you had some issues with font cache rebuilding, perhaps this helps?

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@timhoffm
Copy link
Member

I don't think this addresses my issue (#13852):

The current implementation did fallback_to_default prior to rebuild_if_missing. Therefore rebuild was only performed if also the default font was not found, rendering the parameter rebuild_if_missing essentially meaningless.

This would need changes somewhere in lines 1288-1299. The actual logic when to rebuild and when not is yet to be clarified. That's why #13852 is "work in progress".

@anntzer
Copy link
Contributor Author

anntzer commented Dec 15, 2019

OK, but I think previous versions of rebuilding would not work anyways because the correct fontManager instance was not swapped?

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but I think previous versions of rebuilding would not work anyways because the correct fontManager instance was not swapped?

That may well be. This is a consistent fix, even tough it might not adress all FontManager issues.

_log.debug("Using fontManager instance from %s", fm_path)
return fm
fm = FontManager()
with cbook._lock_path(fm_path):
Copy link
Member

@QuLogic QuLogic Mar 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fm_path is only set in the if, so this should not work in your new call with try_read_cache=False. Additionally, you should keep the lock held for the entirety of the function to prevent race conditions. I'm confusing this with #16111, but if that goes through, the lock really should be held for the entirety of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll wait for #16111 to go in first?

@anntzer
Copy link
Contributor Author

anntzer commented May 3, 2020

rebased.

Previously, when using findfont with rebuild_is_missing (the default)
_rebuild() would generate a new fontManager instance, but because
findfont is defined as `findfont = fontManager.findfont`, this would
keep using the old fontManager instance; we can't just fix this with
`def findfont(...): return fontManager.findfont(...)` because people may
be importing the fontManager instance anyways and not benefitting from
the rebuilt one.

Instead, overwrite(!) the contents of the existing fontManager instance
with the new one as needed.
@QuLogic
Copy link
Member

QuLogic commented Jun 25, 2020

Travis passed, though it doesn't want to post.

@QuLogic
Copy link
Member

QuLogic commented Jun 25, 2020

Is there a way we can test this; maybe using a tempdir with a font that gets deleted?

@anntzer
Copy link
Contributor Author

anntzer commented Jun 25, 2020

I think that would be rather tricky (or require quite a bit of surgery), if we don't want the test suite to fully regen the font cache every time (you'd need to be able to point the font cache to another path, patch FontManager() to let it temporarily find fonts in a tmpdir, etc.).

@QuLogic QuLogic merged commit 1f2d424 into matplotlib:master Jun 25, 2020
@QuLogic QuLogic added this to the v3.4.0 milestone Jun 25, 2020
@anntzer anntzer deleted the fm branch June 25, 2020 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants