8000 Merge pull request #17277 from anntzer/fmwarning · matplotlib/matplotlib@080fdc9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 080fdc9

Browse files
authored
Merge pull request #17277 from anntzer/fmwarning
Move slow FontManager warning to FontManager constructor.
2 parents 67a987e + 290ca2a commit 080fdc9

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/matplotlib/font_manager.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,6 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
256256
@lru_cache()
257257
def _call_fc_list():
258258
"""Cache and list the font filenames known to `fc-list`."""
259-
# Delay the warning by 5s.
260-
timer = Timer(5, lambda: _log.warning(
261-
'Matplotlib is building the font cache using fc-list. '
262-
'This may take a moment.'))
263-
timer.start()
264259
try:
265260
if b'--format' not in subprocess.check_output(['fc-list', '--help']):
266261
_log.warning( # fontconfig 2.7 implemented --format.
@@ -269,8 +264,6 @@ def _call_fc_list():
269264
out = subprocess.check_output(['fc-list', '--format=%{file}\\n'])
270265
except (OSError, subprocess.CalledProcessError):
271266
return []
272-
finally:
273-
timer.cancel()
274267
return [os.fsdecode(fname) for fname in out.split(b'\n')]
275268

276269

@@ -983,16 +976,24 @@ def __init__(self, size=None, weight='normal'):
983976

984977
self.afmlist = []
985978
self.ttflist = []
986-
for fontext in ["afm", "ttf"]:
987-
for path in [*findSystemFonts(paths, fontext=fontext),
988-
*findSystemFonts(fontext=fontext)]:
989-
try:
990-
self.addfont(path)
991-
except OSError as exc:
992-
_log.info("Failed to open font file %s: %s", path, exc)
993-
except Exception as exc:
994-
_log.info("Failed to extract font properties from %s: %s",
995-
path, exc)
979+
980+
# Delay the warning by 5s.
981+
timer = Timer(5, lambda: _log.warning(
982+
'Matplotlib is building the font cache; this may take a moment.'))
983+
timer.start()
984+
try:
985+
for fontext in ["afm", "ttf"]:
986+
for path in [*findSystemFonts(paths, fontext=fontext),
987+
*findSystemFonts(fontext=fontext)]:
988+
try:
989+
self.addfont(path)
990+
except OSError as exc:
991+
_log.info("Failed to open font file %s: %s", path, exc)
992+
except Exception as exc:
993+
_log.info("Failed to extract font properties from %s: "
994+
"%s", path, exc)
995+
finally:
996+
timer.cancel()
996997

997998
def addfont(self, path):
998999
"""

0 commit comments

Comments
 (0)
0