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

Skip to content

Commit c3ac4ec

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 2a3edfe commit c3ac4ec

File tree

5 files changed

+29
-49
lines changed

5 files changed

+29
-49
lines changed

lib/matplotlib/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ def impl(args, regex, min_ver=None):
373373
execs = (["gswin32c", "gswin64c", "mgs", "gs"] # "mgs" for miktex.
374374
if sys.platform == "win32" else
375375
["gs"])
376-
info = next(filter(None, (impl([e, "--version"], "(.*)", "8.60")
376+
info = next(filter(None, (impl([e, "--version"], "(.*)", "9")
377377
for e in execs)),
378378
None)
379379
elif name == "inkscape":
@@ -418,6 +418,7 @@ def checkdep_dvipng():
418418
return str(get_executable_info("dvipng").version)
419419

420420

421+
@cbook.deprecated("2.2")
421422
def checkdep_ghostscript():
422423
info = get_executable_info("gs")
423424
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: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
import io
1313

1414
from tempfile import mkstemp
15-
from matplotlib import verbose, __version__, rcParams, checkdep_ghostscript
15+
import matplotlib as mpl
16+
from matplotlib import (
17+
cbook, verbose, __version__, rcParams, checkdep_ghostscript)
1618
from matplotlib.afm import AFM
1719
from matplotlib.backend_bases import (
1820
_Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
@@ -53,6 +55,7 @@ def __init__(self):
5355
self._cached = {}
5456

5557
@property
58+
@cbook.deprecated("2.2")
5659
def gs_exe(self):
5760
"""
5861
excutable name of ghostscript.
@@ -70,6 +73,7 @@ def gs_exe(self):
7073
return str(gs_exe)
7174

7275
@property
76+
@cbook.deprecated("2.2")
7377
def gs_version(self):
7478
"""
7579
version of ghostscript.
@@ -95,6 +99,7 @@ def gs_version(self):
9599
return gs_version
96100

97101
@property
102+
@cbook.deprecated("2.2")
98103
def supports_ps2write(self):
99104
"""
100105
True if the installed ghostscript supports ps2write device.
@@ -1506,14 +1511,9 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15061511
psfile = tmpfile + '.ps'
15071512
dpi = rcParams['ps.distiller.res']
15081513

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,
1514+
command = [mpl.get_executable_info("gs").executable,
1515+
"-dBATCH", "-dNOPAUSE", "-r%d" % dpi,
1516+
"-sDEVICE=ps2write", paper_option,
15171517
"-sOutputFile=%s" % psfile, tmpfile]
15181518
verbose.report(command, 'debug')
15191519
try:
@@ -1536,11 +1536,7 @@ def gs_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
15361536
# For some versions of gs, above steps result in an ps file
15371537
# where the original bbox is no more correct. Do not adjust
15381538
# 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)
1539+
pstoeps(tmpfile, bbox, rotated=rotated)
15441540

15451541

15461542
def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
@@ -1630,8 +1626,8 @@ def get_bbox(tmpfile, bbox):
16301626
hack.
16311627
"""
16321628

1633-
gs_exe = ps_backend_helper.gs_exe
1634-
command = [gs_exe, "-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox" "%s" % tmpfile]
1629+
command = [get_executable_info("gs").executable,
1630+
"-dBATCH", "-dNOPAUSE", "-sDEVICE=bbox" "%s" % tmpfile]
16351631
verbose.report(command, 'debug')
16361632
p = subprocess.Popen(command, stdin=subprocess.PIPE,
16371633
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)