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

Commit 1e5517d

Browse filesBrowse files
story645ksunden
andcommitted
print missing font warning only once per font.
Co-authored-by: Kyle Sunden <git@ksunden.space>
1 parent 0ac170b commit 1e5517d
Copy full SHA for 1e5517d

File tree

1 file changed

+24
-14
lines changed
Filter options

1 file changed

+24
-14
lines changed

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+24-14Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ class FontManager:
10111011
# Increment this version number whenever the font cache data
10121012
# format or behavior has changed and requires an existing font
10131013
# cache files to be rebuilt.
1014-
__version__ = 330
1014+
__version__ = 335
10151015

10161016
def __init__(self, size=None, weight='normal'):
10171017
self._version = self.__version__
@@ -1031,6 +1031,9 @@ def __init__(self, size=None, weight='normal'):
10311031
self.afmlist = []
10321032
self.ttflist = []
10331033

1034+
# keep track of fonts
1035+
self._not_found = {'generic': [], 'family': [], 'fallback': []}
1036+
10341037
# Delay the warning by 5s.
10351038
timer = threading.Timer(5, lambda: _log.warning(
10361039
'Matplotlib is building the font cache; this may take a moment.'))
@@ -1049,6 +1052,12 @@ def __init__(self, size=None, weight='normal'):
10491052
finally:
10501053
timer.cancel()
10511054

1055+
def _warn_not_found(self, family, warning_id, warning_msg):
1056+
"""Log missing fonts once per warning message"""
1057+
if family not in self._not_found[warning_id]:
1058+
_log.warning(warning_msg)
1059+
self._not_found[warning_id].append(family)
1060+
10521061
def addfont(self, path):
10531062
"""
10541063
Cache the properties of the font at *path* to make it available to the
@@ -1362,13 +1371,14 @@ def _find_fonts_by_props(self, prop, fontext='ttf', directory=None,
13621371
)
13631372
except ValueError:
13641373
if family in font_family_aliases:
1365-
_log.warning(
1366-
"findfont: Generic family %r not found because "
1367-
"none of the following families were found: %s",
1368-
family, ", ".join(self._expand_aliases(family))
1369-
)
1374+
msg = (f"findfont: Generic family '{family}' not found because "
1375+
"none of the following families were found: "
1376+
f"{','.join(self._expand_aliases(family))}")
1377+
self._warn_not_found(family, 'generic', msg)
1378+
13701379
else:
1371-
_log.warning("findfont: Font family %r not found.", family)
1380+
msg = f"findfont: Font family '{family}' not found."
1381+
self._warn_not_found(family, 'family', msg)
13721382

13731383
# only add default family if no other font was found and
13741384
# fallback_to_default is enabled
@@ -1429,15 +1439,15 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default,
14291439

14301440
if best_font is None or best_score >= 10.0:
14311441
if fallback_to_default:
1432-
_log.warning(
1433-
'findfont: Font family %s not found. Falling back to %s.',
1434-
prop.get_family(), self.defaultFamily[fontext])
1442+
msg = (f"findfont: Font family {prop.get_family()} not found. "
1443+
f"Falling back to {self.defaultFamily[fontext]}.")
1444+
self._warn_not_found(prop.get_family(), 'fallback', msg)
14351445
for family in map(str.lower, prop.get_family()):
14361446
if family in font_family_aliases:
1437-
_log.warning(
1438-
"findfont: Generic family %r not found because "
1439-
"none of the following families were found: %s",
1440-
family, ", ".join(self._expand_aliases(family)))
1447+
msg = (f"findfont: Generic family '{family}' not found because "
1448+
"none of the following families were found: "
1449+
f"{','.join(self._expand_aliases(family))}")
1450+
self._warn_not_found(family, 'generic', msg)
14411451
default_prop = prop.copy()
14421452
default_prop.set_family(self.defaultFamily[fontext])
14431453
return self.findfont(default_prop, fontext, directory,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.