FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

MNT: print missing font warning only once per font. by story645 · Pull Request #26602 · matplotlib/matplotlib · GitHub

Repository navigation

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

Draft
story645 wants to merge 2 commits into
matplotlib:mainfrom
story645:font_error
Draft

story645 wants to merge 2 commits into
matplotlib:mainfrom
story645:font_error

Conversation

Copy link
Copy Markdown
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

Comment thread lib/matplotlib/font_manager.py Outdated

Copy link
Copy Markdown
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 commented Aug 27, 2023 •
edited
Loading

Copy link
Copy Markdown
Member Author

, 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.

Copy link
Copy Markdown
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 commented Aug 27, 2023 •
edited
Loading

Copy link
Copy Markdown
Member Author

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 commented Aug 27, 2023 •
edited
Loading

Copy link
Copy Markdown
Member Author

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?

Comment thread lib/matplotlib/font_manager.py Outdated
_log = logging.getLogger(__name__)


class findfontFilter(logging.Filter):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

story645 marked this pull request as draft September 1, 2023 20:33

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL