Skip to content

Commit a1cd024

Browse files
authored
Merge pull request #16537 from anntzer/delaydistillercheck
Delay checking for existence of postscript distillers.
2 parents ffe6c78 + 926c347 commit a1cd024

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

lib/matplotlib/backends/backend_ps.py

+19-5
Original file line numberDiff line numberDiff line change
@@ -981,9 +981,11 @@ def print_figure_impl(fh):
981981
with open(tmpfile, 'w', encoding='latin-1') as fh:
982982
print_figure_impl(fh)
983983
if mpl.rcParams['ps.usedistiller'] == 'ghostscript':
984-
gs_distill(tmpfile, is_eps, ptype=papertype, bbox=bbox)
984+
_try_distill(gs_distill,
985+
tmpfile, is_eps, ptype=papertype, bbox=bbox)
985986
elif mpl.rcParams['ps.usedistiller'] == 'xpdf':
986-
xpdf_distill(tmpfile, is_eps, ptype=papertype, bbox=bbox)
987+
_try_distill(xpdf_distill,
988+
tmpfile, is_eps, ptype=papertype, bbox=bbox)
987989
_move_path_to_path_or_stream(tmpfile, outfile)
988990

989991
else:
@@ -1141,10 +1143,12 @@ def write(self, *args, **kwargs):
11411143

11421144
if (mpl.rcParams['ps.usedistiller'] == 'ghostscript'
11431145
or mpl.rcParams['text.usetex']):
1144-
gs_distill(tmpfile, is_eps, ptype=papertype, bbox=bbox,
1145-
rotated=psfrag_rotated)
1146+
_try_distill(gs_distill,
1147+
tmpfile, is_eps, ptype=papertype, bbox=bbox,
1148+
rotated=psfrag_rotated)
11461149
elif mpl.rcParams['ps.usedistiller'] == 'xpdf':
1147-
xpdf_distill(tmpfile, is_eps, ptype=papertype, bbox=bbox,
1150+
_try_distill(xpdf_distill,
1151+
tmpfile, is_eps, ptype=papertype, bbox=bbox,
11481152
rotated=psfrag_rotated)
11491153

11501154
_move_path_to_path_or_stream(tmpfile, outfile)
@@ -1198,6 +1202,13 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
11981202
return psfrag_rotated
11991203

12001204

1205+
def _try_distill(func, *args, **kwargs):
1206+
try:
1207+
func(*args, **kwargs)
1208+
except mpl.ExecutableNotFoundError as exc:
1209+
_log.warning("%s. Distillation step skipped.", exc)
1210+
1211+
12011212
def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
12021213
"""
12031214
Use ghostscript's pswrite or epswrite device to distill a file.
@@ -1239,6 +1250,9 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
12391250
operators. This distiller is preferred, generating high-level postscript
12401251
output that treats text as text.
12411252
"""
1253+
mpl._get_executable_info("gs") # Effectively checks for ps2pdf.
1254+
mpl._get_executable_info("pdftops")
1255+
12421256
pdffile = tmpfile + '.pdf'
12431257
psfile = tmpfile + '.ps'
12441258

lib/matplotlib/rcsetup.py

+1-18
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import numpy as np
2626

27-
import matplotlib as mpl
2827
from matplotlib import animation, cbook
2928
from matplotlib.cbook import ls_mapper
3029
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
@@ -524,24 +523,8 @@ def validate_ps_distiller(s):
524523
s = s.lower()
525524
if s in ('none', None, 'false', False):
526525
return None
527-
elif s in ('ghostscript', 'xpdf'):
528-
try:
529-
mpl._get_executable_info("gs")
530-
except mpl.ExecutableNotFoundError:
531-
_log.warning("Setting rcParams['ps.usedistiller'] requires "
532-
"ghostscript.")
533-
return None
534-
if s == "xpdf":
535-
try:
536-
mpl._get_executable_info("pdftops")
537-
except mpl.ExecutableNotFoundError:
538-
_log.warning("Setting rcParams['ps.usedistiller'] to 'xpdf' "
539-
"requires xpdf.")
540-
return None
541-
return s
542526
else:
543-
raise ValueError('matplotlibrc ps.usedistiller must either be none, '
544-
'ghostscript or xpdf')
527+
return ValidateInStrings('ps.usedistiller', ['ghostscript', 'xpdf'])(s)
545528

546529

547530
# A validator dedicated to the named line styles, based on the items in

0 commit comments

Comments
 (0)