From 24f29704b28e53dc092e71dcbfd1b40357fc7fc2 Mon Sep 17 00:00:00 2001 From: K900 Date: Tue, 2 Jul 2024 12:49:36 +0300 Subject: [PATCH] Don't fail if we can't query system fonts on macOS The query can fail in some environments where system_profiler is not available on PATH, but we don't want it to just crash the entire thing. --- lib/matplotlib/font_manager.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/font_manager.py b/lib/matplotlib/font_manager.py index 312e8ee97246..813bee6eb623 100644 --- a/lib/matplotlib/font_manager.py +++ b/lib/matplotlib/font_manager.py @@ -266,8 +266,11 @@ def _get_fontconfig_fonts(): @lru_cache def _get_macos_fonts(): """Cache and list the font paths known to ``system_profiler SPFontsDataType``.""" - d, = plistlib.loads( - subprocess.check_output(["system_profiler", "-xml", "SPFontsDataType"])) + try: + d, = plistlib.loads( + subprocess.check_output(["system_profiler", "-xml", "SPFontsDataType"])) + except (OSError, subprocess.CalledProcessError, plistlib.InvalidFileException): + return [] return [Path(entry["path"]) for entry in d["_items"]]