From b12a10695526062cef8d0651de052c82627fb1b3 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 25 Jan 2019 20:03:03 +0100 Subject: [PATCH] Defer checking of tex install to when it is actually used. The call to checkdep_usetex() in `__init__.py` doesn't help for people explicitly passing usetex=True. Moreover, it slows down import time for those who *do* have text.usetex set to True in their rcfile by ~20ms (when timing this, note that checkdep_ghostscript (which checkdep_usetex calls) has a cache, which should be disabled for timing purposes. Moreover, checkdep_usetex is overly broad, always requiring dvipng (which is not required for pdf/ps output) and ghostscript (which is not required for raster output). Instead, move the check to texmanager.py, which will provide a more meaningful error message to end users, speed up import time (20ms is similar to the import time of pyparsing or urllib.request, for example) and avoid the inaccuracies above. --- lib/matplotlib/__init__.py | 2 -- lib/matplotlib/texmanager.py | 6 +++++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 3098077038e8..5ffe8456c240 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -968,8 +968,6 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True): rcParams['ps.usedistiller'] = checkdep_ps_distiller( rcParams['ps.usedistiller']) -rcParams['text.usetex'] = checkdep_usetex(rcParams['text.usetex']) - if rcParams['axes.formatter.use_locale']: locale.setlocale(locale.LC_ALL, '') diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 46f0e8be4337..11f1bd99201c 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -302,6 +302,10 @@ def _run_checked_subprocess(self, command, tex): report = subprocess.check_output(command, cwd=self.texcache, stderr=subprocess.STDOUT) + except FileNotFoundError as exc: + raise RuntimeError( + 'Failed to process string with tex because {} could not be ' + 'found'.format(command[0])) from exc except subprocess.CalledProcessError as exc: raise RuntimeError( '{prog} was not able to process the following string:\n' @@ -310,7 +314,7 @@ def _run_checked_subprocess(self, command, tex): '{exc}\n\n'.format( prog=command[0], tex=tex.encode('unicode_escape'), - exc=exc.output.decode('utf-8'))) + exc=exc.output.decode('utf-8'))) from exc _log.debug(report) return report