10000 Deprecate checkdep_ghostscript; bump to gs>=9.0. · matplotlib/matplotlib@29e206a · GitHub
[go: up one dir, main page]

Skip to content

Commit 29e206a

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 3c24671 commit 29e206a

File tree

5 files changed

+30
-52
lines changed

5 files changed

+30
-52
lines changed

lib/matplotlib/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,9 @@ def impl(args, regex, min_ver=None):
466466
execs = (["gswin32c", "gswin64c", "mgs", "gs"] # "mgs" for miktex.
467467
if sys.platform == "win32" else
468468
["gs"])
469-
info = next(filter(None, (impl([e, "--version"], "(.*)", "8.60")
470-
for e in execs)),
469+
info = next((info for info in (impl([e, "--version"], "(.*)", "9")
470+
for e in execs)
471+
if info),
471472
None)
472473
elif name == "inkscape":
473474
info = impl(["inkscape", "-V"], "^Inkscape ([^ ]*)")
@@ -511,6 +512,7 @@ def checkdep_dvipng():
511512
return str(get_executable_info("dvipng").version)
512513

513514

515+
@cbook.deprecated("2.2")
514516
def checkdep_ghostscript():
515517
info = get_executable_info("gs")
516518
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 i 8000 mport 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,39 +166,22 @@ 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), '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT',
195179
'-sDEVICE=png16m', '-dUseCIEColor', '-dTextAlphaBits=4',
196180
'-dGraphicsAlphaBits=4', '-dDOINTERPOLATE', '-sOutputFile=%s' % pngfile,
197181
'-r%d' % dpi, pdffile]
198182
check_output(cmd, stderr=subprocess.STDOUT)
199183
return gs_convert
200-< 6D40 div class="diff-text-inner"> else:
201-
raise RuntimeError("No suitable pdf to png renderer found.")
184+
raise RuntimeError("No suitable pdf to png renderer found")
202185

203186

204187
class LatexError(Exception):

lib/matplotlib/backends/backend_ps.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111
import glob, os, shutil, sys, time, datetime
1212
import io
1313
import logging
14-
1514
from tempfile import mkstemp
15+
16+
import matplotlib as mpl
1617
from matplotlib import cbook, __version__, rcParams, checkdep_ghostscript
1718
from matplotlib.afm import AFM
1819
from matplotlib.backend_bases import (
1920
_Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
2021
RendererBase)
21-
2222
from matplotlib.cbook import (get_realpath_and_stat, is_writable_file_like,
2323
maxdict, file_requires_unicode)
2424
from matplotlib.compat.subprocess import subprocess
25-
2625
from matplotlib.font_manager import findfont, is_opentype_cff_font, get_font
2726
from matplotlib.ft2font import KERNING_DEFAULT, LOAD_NO_HINTING
2827
from matplotlib.ttconv import convert_ttf_to_ps
@@ -52,6 +51,7 @@ def __init__(self):
5251
self._cached = {}
5352

5453
@property
54+
@cbook.deprecated("2.2")
5555
def gs_exe(self):
5656
"""
5757
excutable name of ghostscript.
@@ -69,6 +69,7 @@ def gs_exe(self):
6969
return str(gs_exe)
7070

7171
@property
72+
@cbook.deprecated("2.2")
7273
def gs_version(self):
7374
"""
7475
version of ghostscript.
@@ -94,6 +95,7 @@ def gs_version(self):
9495
return gs_version
9596

9697
@property
98+
@cbook.deprecated("2.2")
9799
def supports_ps2write(self):
98100
"""
99101
True if the installed ghostscript supports ps2write device.
@@ -1499,14 +1501,9 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
14991501
psfile = tmpfile + '.ps'
15001502
dpi = rcParams['ps.distiller.res']
15011503

1502-
gs_exe = ps_backend_helper.gs_exe
1503-
if ps_backend_helper.supports_ps2write: # gs version >= 9
1504-
device_name = "ps2write"
1505-
else:
1506-
device_name = "pswrite"
1507-
1508-
command = [str(gs_exe), "-dBATCH", "-dNOPAUSE", "-r%d" % dpi,
1509-
"-sDEVICE=%s" % device_name, paper_option,
1504+
command = [mpl.get_executable_info("gs").executable,
1505+
"-dBATCH", "-dNOPAUSE", "-r%d" % dpi,
1506+
"-sDEVICE=ps2write", paper_option,
15101507
"-sOutputFile=%s" % psfile, tmpfile]
15111508
_log.debug(command)
15121509
try:
@@ -1529,11 +1526,7 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15291526
# For some versions of gs, above steps result in an ps file
15301527
# where the original bbox is no more correct. Do not adjust
15311528
# bbox for now.
1532-
if ps_backend_helper.supports_ps2write:
1533-
# fo gs version >= 9 w/ ps2write device
1534-
pstoeps(tmpfile, bbox, rotated=rotated)
1535-
else:
1536-
pstoeps(tmpfile)
1529+
pstoeps(tmpfile, bbox, rotated=rotated)
15371530

15381531

15391532
def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
@@ -1623,8 +1616,8 @@ def get_bbox(tmpfile, bbox):
16231616
hack.
16241617
"""
16251618

1626-
gs_exe = ps_backend_helper.gs_exe
1627-
command = [gs_exe, "-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox" "%s" % tmpfile]
1619+
command = [get_executable_info("gs").executable,
1620+
"-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox" "%s" % tmpfile]
16281621
_log.debug(command)
16291622
p = subprocess.Popen(command, stdin=subprocess.PIPE,
16301623
stdout=subprocess.PIPE, stderr=subprocess.PIPE,

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)
0