Skip to content

Commit d7c6c5b

Browse files
anntzertimhoffm
authored andcommitted
Defer checking of tex install to when it is actually used. (#13285)
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.
1 parent 114d516 commit d7c6c5b

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/matplotlib/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -968,8 +968,6 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
968968
rcParams['ps.usedistiller'] = checkdep_ps_distiller(
969969
rcParams['ps.usedistiller'])
970970

971-
rcParams['text.usetex'] = checkdep_usetex(rcParams['text.usetex'])
972-
973971
if rcParams['axes.formatter.use_locale']:
974972
locale.setlocale(locale.LC_ALL, '')
975973

lib/matplotlib/texmanager.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ def _run_checked_subprocess(self, command, tex):
302302
report = subprocess.check_output(command,
303303
cwd=self.texcache,
304304
stderr=subprocess.STDOUT)
305+
except FileNotFoundError as exc:
306+
raise RuntimeError(
307+
'Failed to process string with tex because {} could not be '
308+
'found'.format(command[0])) from exc
305309
except subprocess.CalledProcessError as exc:
306310
raise RuntimeError(
307311
'{prog} was not able to process the following string:\n'
@@ -310,7 +314,7 @@ def _run_checked_subprocess(self, command, tex):
310314
'{exc}\n\n'.format(
311315
prog=command[0],
312316
tex=tex.encode('unicode_escape'),
313-
exc=exc.output.decode('utf-8')))
317+
exc=exc.output.decode('utf-8'))) from exc
314318
_log.debug(report)
315319
return report
316320

0 commit comments

Comments
 (0)