Skip to content

Commit 9602bff

Browse files
committed
Deprecate checkdep_ghostscript; bump to gs>=9.0.
gs 9.0 was released in 2010 (https://www.ghostscript.com/doc/current/History9.htm#Version9.00).
1 parent 33f199e commit 9602bff

File tree

5 files changed

+34
-58
lines changed

5 files changed

+34
-58
lines changed

lib/matplotlib/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,9 @@ def impl(args, regex, min_ver=None):
474474
execs = (["gswin32c", "gswin64c", "mgs", "gs"] # "mgs" for miktex.
475475
if sys.platform == "win32" else
476476
["gs"])
477-
info = next(filter(None, (impl([e, "--version"], "(.*)", "8.60")
478-
for e in execs)),
477+
info = next((info for info in (impl([e, "--version"], "(.*)", "9")
478+
for e in execs)
479+
if info),
479480
None)
480481
elif name == "inkscape":
481482
info = impl(["inkscape", "-V"], "^Inkscape ([^ ]*)")
@@ -519,6 +520,7 @@ def checkdep_dvipng():
519520
return str(get_executable_info("dvipng").version)
520521

521522

523+
@cbook.deprecated("2.2")
522524
def checkdep_ghostscript():
523525
info = get_executable_info("gs")
524526
checkdep_ghostscript.executable = info.executable

lib/matplotlib/backends/backend_pgf.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
_Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
2222
RendererBase)
2323
from matplotlib.backends.backend_mixed import MixedModeRenderer
24-
from matplotlib.cbook import is_writable_file_like
24+
from matplotlib.cbook import _backports, is_writable_file_like
2525
from matplotlib.compat import subprocess
2626
from matplotlib.compat.subprocess import check_output
2727
from matplotlib.path import Path
@@ -166,30 +166,14 @@ def _font_properties_str(prop):
166166

167167

168168
def make_pdf_to_png_converter():
169-
"""
170-
Returns a function that converts a pdf file to a png file.
171-
"""
172-
173-
tools_available = []
174-
# check for pdftocairo
175-
try:
176-
check_output([str("pdftocairo"), "-v"], stderr=subprocess.STDOUT)
177-
tools_available.append("pdftocairo")
178-
except:
179-
pass
180-
# check for ghostscript
181-
gs, ver = mpl.checkdep_ghostscript()
182-
if gs:
183-
tools_available.append("gs")
184-
185-
# pick converter
186-
if "pdftocairo" in tools_available:
169+
"""Returns a function that converts a pdf file to a png file."""
170+
if _backports.which("pdftocairo"):
187171
def cairo_convert(pdffile, pngfile, dpi):
188172
cmd = [str("pdftocairo"), "-singlefile", "-png", "-r", "%d" % dpi,
189173
pdffile, os.path.splitext(pngfile)[0]]
190174
check_output(cmd, stderr=subprocess.STDOUT)
191175
return cairo_convert
192-
elif "gs" in tools_available:
176+
if mpl.get_executable_info("gs"):
193177
def gs_convert(pdffile, pngfile, dpi):
194178
cmd = [str(gs),
195179
'-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT',
@@ -199,8 +183,7 @@ def gs_convert(pdffile, pngfile, dpi):
199183
'-r%d' % dpi, pdffile]
200184
check_output(cmd, stderr=subprocess.STDOUT)
201185
return gs_convert
202-
else:
203-
raise RuntimeError("No suitable pdf to png renderer found.")
186+
raise RuntimeError("No suitable pdf to png renderer found")
204187

205188

206189
class LatexError(Exception):

lib/matplotlib/backends/backend_ps.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@
22
A PostScript backend, which can produce both PostScript .ps and .eps
33
"""
44

5-
from __future__ import (absolute_import, division, print_function,
6-
unicode_literals)
7-
85
import six
96
from six.moves import StringIO
107

118
import glob, os, shutil, sys, time, datetime
129
import io
1310
import logging
14-
1511
from tempfile import mkstemp
12+
13+
import matplotlib as mpl
1614
from matplotlib import cbook, __version__, rcParams, checkdep_ghostscript
1715
from matplotlib.afm import AFM
1816
from matplotlib.backend_bases import (
1917
_Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
2018
RendererBase)
21-
2219
from matplotlib.cbook import (get_realpath_and_stat, is_writable_file_like,
2320
maxdict, file_requires_unicode)
2421
from matplotlib.compat.subprocess import subprocess
25-
2622
from matplotlib.font_manager import findfont, is_opentype_cff_font, get_font
2723
from matplotlib.ft2font import KERNING_DEFAULT, LOAD_NO_HINTING
2824
from matplotlib.ttconv import convert_ttf_to_ps
@@ -52,6 +48,7 @@ def __init__(self):
5248
self._cached = {}
5349

5450
@property
51+
@cbook.deprecated("2.2")
5552
def gs_exe(self):
5653
"""
5754
executable name of ghostscript.
@@ -69,6 +66,7 @@ def gs_exe(self):
6966
return str(gs_exe)
7067

7168
@property
69+
@cbook.deprecated("2.2")
7270
def gs_version(self):
7371
"""
7472
version of ghostscript.
@@ -94,6 +92,7 @@ def gs_version(self):
9492
return gs_version
9593

9694
@property
95+
@cbook.deprecated("2.2")
9796
def supports_ps2write(self):
9897
"""
9998
True if the installed ghostscript supports ps2write device.
@@ -1495,14 +1494,9 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
14951494
psfile = tmpfile + '.ps'
14961495
dpi = rcParams['ps.distiller.res']
14971496

1498-
gs_exe = ps_backend_helper.gs_exe
1499-
if ps_backend_helper.supports_ps2write: # gs version >= 9
1500-
device_name = "ps2write"
1501-
else:
1502-
device_name = "pswrite"
1503-
1504-
command = [str(gs_exe), "-dBATCH", "-dNOPAUSE", "-r%d" % dpi,
1505-
"-sDEVICE=%s" % device_name, paper_option,
1497+
command = [mpl.get_executable_info("gs").executable,
1498+
"-dBATCH", "-dNOPAUSE", "-r%d" % dpi,
1499+
"-sDEVICE=ps2write", paper_option,
15061500
"-sOutputFile=%s" % psfile, tmpfile]
15071501
_log.debug(command)
15081502
try:
@@ -1525,11 +1519,7 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15251519
# For some versions of gs, above steps result in an ps file
15261520
# where the original bbox is no more correct. Do not adjust
15271521
# bbox for now.
1528-
if ps_backend_helper.supports_ps2write:
1529-
# fo gs version >= 9 w/ ps2write device
1530-
pstoeps(tmpfile, bbox, rotated=rotated)
1531-
else:
1532-
pstoeps(tmpfile)
1522+
pstoeps(tmpfile, bbox, rotated=rotated)
15331523

15341524

15351525
def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
@@ -1609,8 +1599,8 @@ def get_bbox(tmpfile, bbox):
16091599
hack.
16101600
"""
16111601

1612-
gs_exe = ps_backend_helper.gs_exe
1613-
command = [gs_exe, "-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox", "%s" % tmpfile]
1602+
command = [get_executable_info("gs").executable,
1603+
"-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox", "%s" % tmpfile]
16141604
_log.debug(command)
16151605
p = subprocess.Popen(command, stdin=subprocess.PIPE,
16161606
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
@@ -1623,11 +1613,12 @@ def get_bbox(tmpfile, bbox):
16231613
if bbox_found:
16241614
bbox_info = bbox_found.group()
16251615
else:
1626-
raise RuntimeError('Ghostscript was not able to extract a bounding box.\
1627-
Here is the Ghostscript output:\n\n%s' % bbox_info)
1616+
raise RuntimeError(
1617+
"Ghostscript was not able to extract a bounding box. "
1618+
"Here is the Ghostscript output:\n\n%s" % bbox_info)
16281619
l, b, r, t = [float(i) for i in bbox_info.split()[-4:]]
16291620

1630-
# this is a hack to deal with the fact that ghostscript does not return the
1621+
# This is a hack to deal with the fact that ghostscript does not return the
16311622
# intended bbox, but a tight bbox. For now, we just center the ink in the
16321623
# intended bbox. This is not ideal, users may intend the ink to not be
16331624
# centered.

lib/matplotlib/testing/compare.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def get_file_hash(path, block_size=2 ** 20):
105105
md5.update(data)
106106

107107
if path.endswith('.pdf'):
108-
from matplotlib import checkdep_ghostscript
109-
md5.update(checkdep_ghostscript()[1].encode('utf-8'))
108+
md5.update(str(matplotlib.get_executable_info("gs").version)
109+
.encode('utf-8'))
110110
elif path.endswith('.svg'):
111111
md5.update(str(matplotlib.get_executable_info("inkscape").version)
112112
.encode('utf-8'))
@@ -237,13 +237,13 @@ def __del__(self):
237237

238238

239239
def _update_converter():
240-
gs, gs_v = matplotlib.checkdep_ghostscript()
241-
if gs_v is not None:
242-
def cmd(old, new):
243-
return [str(gs), '-q', '-sDEVICE=png16m', '-dNOPAUSE', '-dBATCH',
244-
'-sOutputFile=' + new, old]
245-
converter['pdf'] = make_external_conversion_command(cmd)
246-
converter['eps'] = make_external_conversion_command(cmd)
240+
info = matplotlib.get_executable_info("gs")
241+
if info:
242+
@make_external_conversion_command
243+
def _converter(old, new):
244+
return [info.executable, '-q', '-sDEVICE=png16m', '-dNOPAUSE',
245+
'-dBATCH', '-sOutputFile=' + new, old]
246+
converter['eps'] = converter['pdf'] = _converter
247247

248248
if matplotlib.get_executable_info("inkscape"):
249249
converter['svg'] = _SVGConverter()

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
needs_ghostscript = pytest.mark.xfail(
21-
matplotlib.checkdep_ghostscript()[0] is None,
21+
matplotlib.get_executable_info("gs") is None,
2222
reason="This test needs a ghostscript installation")
2323

2424

0 commit comments

Comments
 (0)