Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MNT: print missing font warning only once per font. #26602

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
Loading
from

Conversation

story645
Copy link
Member

Wrapping the log calls in a check that the missing font isn't in a list of missing fonts. Goal is to make the doc builds easier to read by squashing the extra prints.

I have it separated out my msg cause I'm not sure if that's important, could totally see easier versions that check if the entire msg has been seen (so stores a list of msgs) or that only looks at font and not the msg. base on call convo w/ @ksunden

lib/matplotlib/font_manager.py Outdated Show resolved Hide resolved
@timhoffm
Copy link
Member

I’ve not following the details here, but if this is only about suppressing expected warnings in the doc builds, a warnings filter in conf.py would be the way to go.

@story645
Copy link
Member Author

story645 commented Aug 27, 2023

, a warnings filter in conf.py would be the way to go.

Not sure how since we want one warning per missing font to print out at once. I tried using the once filter and couldn't get that working.

@timhoffm
Copy link
Member

Ah sorry, I was thining about warnings.warn() not logging.warning(). Forget the filter comment then.

I would base deduplication on the message. Separate ids is more effort than it's worth. Likely the simplest approach is to wrap your logging in use a functools.cache.

@story645
Copy link
Member Author

story645 commented Aug 27, 2023

Likely the simplest approach is to wrap your logging in use a functools.cache.

Going down that rabbit hole, it looks like the least extra/most generalizable may be to make a custom loghandler or use a handler filter (which is what I'm trying now)

@story645
Copy link
Member Author

story645 commented Aug 27, 2023

So uh adding a filter works really nicely, and I can move it to the sphinxextensions - there's one for missing references I used as a model-but I think the multiple prints are annoying in any context. Only problem is it works a bit too well and I can't get the messages to show up on new runs -> any tips for resetting the msg_cache on new runs?

@@ -50,6 +50,26 @@

_log = logging.getLogger(__name__)


class findfontFilter(logging.Filter):
Copy link
Member

Choose a reason for hiding this comment

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

I would consider making this a private class, as this is internal functionality added to an already private logger.

(This is what stubtest is complaining about, as it sees this as public but not added to the stub files)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree, made those changes locally but didn't push cause I'm still struggling w/ clearing the msg_cache

@story645 story645 marked this pull request as draft September 1, 2023 20:33
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.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.