Skip to content

Delay checking for existence of postscript distillers. #16537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,11 @@ def print_figure_impl(fh):
with open(tmpfile, 'w', encoding='latin-1') as fh:
print_figure_impl(fh)
if mpl.rcParams['ps.usedistiller'] == 'ghostscript':
gs_distill(tmpfile, is_eps, ptype=papertype, bbox=bbox)
_try_distill(gs_distill,
tmpfile, is_eps, ptype=papertype, bbox=bbox)
elif mpl.rcParams['ps.usedistiller'] == 'xpdf':
xpdf_distill(tmpfile, is_eps, ptype=papertype, bbox=bbox)
_try_distill(xpdf_distill,
tmpfile, is_eps, ptype=papertype, bbox=bbox)
_move_path_to_path_or_stream(tmpfile, outfile)

else:
Expand Down Expand Up @@ -1141,10 +1143,12 @@ def write(self, *args, **kwargs):

if (mpl.rcParams['ps.usedistiller'] == 'ghostscript'
or mpl.rcParams['text.usetex']):
gs_distill(tmpfile, is_eps, ptype=papertype, bbox=bbox,
rotated=psfrag_rotated)
_try_distill(gs_distill,
tmpfile, is_eps, ptype=papertype, bbox=bbox,
rotated=psfrag_rotated)
elif mpl.rcParams['ps.usedistiller'] == 'xpdf':
xpdf_distill(tmpfile, is_eps, ptype=papertype, bbox=bbox,
_try_distill(xpdf_distill,
tmpfile, is_eps, ptype=papertype, bbox=bbox,
rotated=psfrag_rotated)

_move_path_to_path_or_stream(tmpfile, outfile)
Expand Down Expand Up @@ -1198,6 +1202,13 @@ def convert_psfrags(tmpfile, psfrags, font_preamble, custom_preamble,
return psfrag_rotated


def _try_distill(func, *args, **kwargs):
try:
func(*args, **kwargs)
except mpl.ExecutableNotFoundError as exc:
_log.warning("%s. Distillation step skipped.", exc)


def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
"""
Use ghostscript's pswrite or epswrite device to distill a file.
Expand Down Expand Up @@ -1239,6 +1250,9 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
operators. This distiller is preferred, generating high-level postscript
output that treats text as text.
"""
mpl._get_executable_info("gs") # Effectively checks for ps2pdf.
mpl._get_executable_info("pdftops")

pdffile = tmpfile + '.pdf'
psfile = tmpfile + '.ps'

Expand Down
19 changes: 1 addition & 18 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import numpy as np

import matplotlib as mpl
from matplotlib import animation, cbook
from matplotlib.cbook import ls_mapper
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
Expand Down Expand Up @@ -486,24 +485,8 @@ def validate_ps_distiller(s):
s = s.lower()
if s in ('none', None, 'false', False):
return None
elif s in ('ghostscript', 'xpdf'):
try:
mpl._get_executable_info("gs")
except mpl.ExecutableNotFoundError:
_log.warning("Setting rcParams['ps.usedistiller'] requires "
"ghostscript.")
return None
if s == "xpdf":
try:
mpl._get_executable_info("pdftops")
except mpl.ExecutableNotFoundError:
_log.warning("Setting rcParams['ps.usedistiller'] to 'xpdf' "
"requires xpdf.")
return None
return s
else:
raise ValueError('matplotlibrc ps.usedistiller must either be none, '
'ghostscript or xpdf')
return ValidateInStrings('ps.usedistiller', ['ghostscript', 'xpdf'])(s)


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