Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c1ae97

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 8b513a5 commit 8c1ae97

File tree

5 files changed

+30
-50
lines changed

5 files changed

+30
-50
lines changed

lib/matplotlib/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,9 @@ def impl(args, regex, min_ver=None):
471471
execs = (["gswin32c", "gswin64c", "mgs", "gs"] # "mgs" for miktex.
472472
if sys.platform == "win32" else
473473
["gs"])
474-
info = next(filter(None, (impl([e, "--version"], "(.*)", "8.60")
475-
for e in execs)),
474+
info = next((info for info in (impl([e, "--version"], "(.*)", "9")
475+
for e in execs)
476+
if info),
476477
None)
477478
elif name == "inkscape":
478479
info = impl(["inkscape", "-V"], "^Inkscape ([^ ]*)")
@@ -516,6 +517,7 @@ def checkdep_dvipng():
516517
return str(get_executable_info("dvipng").version)
517518

518519

520+
@cbook.deprecated("2.2")
519521
def checkdep_ghostscript():
520522
info = get_executable_info("gs")
521523
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
@@ -26,7 +26,7 @@
2626
from matplotlib.text import Text
2727
from matplotlib.path import Path
2828
from matplotlib import _png, rcParams
29-
from matplotlib.cbook import is_writable_file_like
29+
from matplotlib.cbook import _backports, is_writable_file_like
3030
from matplotlib.compat import subprocess
3131
from matplotlib.compat.subprocess import check_output
3232

@@ -170,39 +170,22 @@ def _font_properties_str(prop):
170170

171171

172172
def make_pdf_to_png_converter():
173-
"""
174-
Returns a function that converts a pdf file to a png file.
175-
"""
176-
177-
tools_available = []
178-
# check for pdftocairo
179-
try:
180-
check_output([str("pdftocairo"), "-v"], stderr=subprocess.STDOUT)
181-
tools_available.append("pdftocairo")
182-
except:
183-
pass
184-
# check for ghostscript
185-
gs, ver = mpl.checkdep_ghostscript()
186-
if gs:
187-
tools_available.append("gs")
188-
189-
# pick converter
190-
if "pdftocairo" in tools_available:
173+
"""Returns a function that converts a pdf file to a png file."""
174+
if _backports.which("pdftocairo"):
191175
def cairo_convert(pdffile, pngfile, dpi):
192176
cmd = [str("pdftocairo"), "-singlefile", "-png", "-r", "%d" % dpi,
193177
pdffile, os.path.splitext(pngfile)[0]]
194178
check_output(cmd, stderr=subprocess.STDOUT)
195179
return cairo_convert
196-
elif "gs" in tools_available:
180+
if mpl.get_executable_info("gs"):
197181
def gs_convert(pdffile, pngfile, dpi):
198182
cmd = [str(gs), '-dQUIET', '-dSAFER', '-dBATCH', '-dNOPAUSE', '-dNOPROMPT',
199183
'-sDEVICE=png16m', '-dUseCIEColor', '-dTextAlphaBits=4',
200184
'-dGraphicsAlphaBits=4', '-dDOINTERPOLATE', '-sOutputFile=%s' % pngfile,
201185
'-r%d' % dpi, pdffile]
202186
check_output(cmd, stderr=subprocess.STDOUT)
203187
return gs_convert
204-
else:
205-
raise RuntimeError("No suitable pdf to png renderer found.")
188+
raise RuntimeError("No suitable pdf to png renderer found")
206189

207190

208191
class LatexError(Exception):

lib/matplotlib/backends/backend_ps.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import logging
1414

1515
from tempfile import mkstemp
16-
from matplotlib import __version__, rcParams, checkdep_ghostscript
16+
import matplotlib as mpl
17+
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,
@@ -53,6 +54,7 @@ def __init__(self):
5354
self._cached = {}
5455

5556
@property
57+
@cbook.deprecated("2.2")
5658
def gs_exe(self):
5759
"""
5860
excutable name of ghostscript.
@@ -70,6 +72,7 @@ def gs_exe(self):
7072
return str(gs_exe)
7173

7274
@property
75+
@cbook.deprecated("2.2")
7376
def gs_version(self):
7477
"""
7578
version of ghostscript.
@@ -95,6 +98,7 @@ def gs_version(self):
9598
return gs_version
9699

97100
@property
101+
@cbook.deprecated("2.2")
98102
def supports_ps2write(self):
99103
"""
100104
True if the installed ghostscript supports ps2write device.
@@ -1506,14 +1510,9 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15061510
psfile = tmpfile + '.ps'
15071511
dpi = rcParams['ps.distiller.res']
15081512

1509-
gs_exe = ps_backend_helper.gs_exe
1510-
if ps_backend_helper.supports_ps2write: # gs version >= 9
1511-
device_name = "ps2write"
1512-
else:
1513-
device_name = "pswrite"
1514-
1515-
command = [str(gs_exe), "-dBATCH", "-dNOPAUSE", "-r%d" % dpi,
1516-
"-sDEVICE=%s" % device_name, paper_option,
1513+
command = [mpl.get_executable_info("gs").executable,
1514+
"-dBATCH", "-dNOPAUSE", "-r%d" % dpi,
1515+
"-sDEVICE=ps2write", paper_option,
15171516
"-sOutputFile=%s" % psfile, tmpfile]
15181517
_log.debug(command)
15191518
try:
@@ -1536,11 +1535,7 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15361535
# For some versions of gs, above steps result in an ps file
15371536
# where the original bbox is no more correct. Do not adjust
15381537
# bbox for now.
1539-
if ps_backend_helper.supports_ps2write:
1540-
# fo gs version >= 9 w/ ps2write device
1541-
pstoeps(tmpfile, bbox, rotated=rotated)
1542-
else:
1543-
pstoeps(tmpfile)
1538+
pstoeps(tmpfile, bbox, rotated=rotated)
15441539

15451540

15461541
def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
@@ -1630,8 +1625,8 @@ def get_bbox(tmpfile, bbox):
16301625
hack.
16311626
"""
16321627

1633-
gs_exe = ps_backend_helper.gs_exe
1634-
command = [gs_exe, "-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox" "%s" % tmpfile]
1628+
command = [get_executable_info("gs").executable,
1629+
"-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox" "%s" % tmpfile]
16351630
_log.debug(command)
16361631
p = subprocess.Popen(command, stdin=subprocess.PIPE,
16371632
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
@@ -106,8 +106,8 @@ def get_file_hash(path, block_size=2 ** 20):
106106
md5.update(data)
107107

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

239239

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

249249
if matplotlib.get_executable_info("inkscape"):
250250
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)