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 290ca2a

Browse filesBrowse files
committed
Move slow FontManager warning to FontManager constructor.
Currently, we warn if fc-list is slow, but not if iterating over the fonts is slow, which is actually more likely. Fix that.
1 parent 99ba9f9 commit 290ca2a
Copy full SHA for 290ca2a

File tree

Expand file treeCollapse file tree

1 file changed

+18
-17
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-17
lines changed

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
+18-17Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.