Skip to content

Fix rebuilding font cache #13852

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

Closed
wants to merge 1 commit into from

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Apr 2, 2019

PR Summary

Fixes #13810.

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 fix reorders the logic.

Anybody an idea how to unit-test this?

@anntzer
Copy link
Contributor

anntzer commented Apr 2, 2019

looks fine, left some minor comments.

for testing (depending on how much effort you want to put into it... not sure it's worth it) you could (ab)use the recent #13766 which adds $XDG_DATA_HOME/fonts to the font search path on linux (run a subprocess with $XDG_DATA_HOME pointing to a tmpdir and drop mpltest.ttf (which we have for testing purposes) there, build a font cache, then delete mpltest.ttf and check that the right thing happens if you then make a call to findfont that should find mpltest.ttf and trigger a rebuild.

@timhoffm timhoffm force-pushed the fix-rebuilding-font-cache branch from db77e33 to 565915c Compare April 2, 2019 22:43
'findfont: Found a missing font file. Rebuilding cache.')
_rebuild()
return self.findfont(prop, fontext, directory,
fallback_to_default=True,
Copy link
Member Author

Choose a reason for hiding this comment

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

Shouldn't that be fallback_to_default=fallback_to_default? Otherwise we overwrite the user's choice in the recursive call.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, sounds reasonable... but why was it not failing before?

prop.get_family(), self.defaultFamily[fontext])
default_prop = prop.copy()
default_prop.set_family(self.defaultFamily[fontext])
return self.findfont(default_prop, fontext, directory,
Copy link
Member Author

@timhoffm timhoffm Apr 2, 2019

Choose a reason for hiding this comment

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

Similarly, shouldn't that contain rebuild_if_missing=rebuild_if_missung?

@timhoffm
Copy link
Member Author

timhoffm commented Apr 2, 2019

Ok, testing is a bit complicated. For now, I wouldn't dive into crafting that unit test unless somebody really wishes that.

@timhoffm timhoffm force-pushed the fix-rebuilding-font-cache branch from 565915c to 4cd263d Compare April 13, 2019 14:28
# No sufficently good font found.
if rebuild_if_missing:
_log.info(
'findfont: Found a missing font file. Rebuilding cache.')
Copy link
Contributor

Choose a reason for hiding this comment

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

the log message no longer corresponds to the condition (previously this was only triggered if not os.path.isfile(result.fname) -- perhaps(?) the logic should be changed (dunno), but then the log message should be changed too)

@tacaswell tacaswell added this to the v3.2.0 milestone Apr 15, 2019
@timhoffm
Copy link
Member Author

Given #13810 (comment)

Also, imagine the case where someone's code was requesting a font that didn't exist in the cache or on the system. Every single time there was a cache-miss, they'd be paying that rebuild penalty (or at the least, the system search penalty).

I'm wondering if we need a smarter rebuild method that e.g. does only try to rebuild once per session for a specific font. Otherwise, when doing 20 plots with a non-existing font, I'd rebuild the cache 20 times to just find out that the font is still not available.

@anntzer
Copy link
Contributor

anntzer commented Apr 17, 2019

rebuild_if_missing should only trigger if we find a font that's listed in the cache but does not actually exist in the filesystem; in that case, after rebuilding, the font should no longer be listed in the cache so it won't trigger further rebuilds.

@github-actions
Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 12, 2023
@timhoffm
Copy link
Member Author

I'm not going to continue on this.

@timhoffm timhoffm closed this Sep 20, 2024
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.

Font found via FontManager.find_font() but not when using it in Figure.text()
4 participants