8000 Merge pull request #8753 from anntzer/tex-version-search · matplotlib/matplotlib@12a0085 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit 12a0085

Browse files
authored
Merge pull request #8753 from anntzer/tex-version-search
Remove tex version check; require dvipng >=1.6
2 parents e34f4a1 + 8940c66 commit 12a0085

File tree

11 files changed

+110
-122
lines changed

11 files changed

+110
-122
lines changed

lib/matplotlib/__init__.py

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
# definitions, so it is safe to import from it here.
123123
from . import cbook
124124
from matplotlib.cbook import (
125-
mplDeprecation, dedent, get_label, sanitize_sequence)
125+
_backports, mplDeprecation, dedent, get_label, sanitize_sequence)
126126
from matplotlib.compat import subprocess
127127
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
128128

@@ -371,6 +371,9 @@ def checkdep_ghostscript():
371371
checkdep_ghostscript.version = None
372372

373373

374+
# Deprecated, as it is unneeded and some distributions (e.g. MiKTeX 2.9.6350)
375+
# do not actually report the TeX version.
376+
@cbook.deprecated("2.1")
374377
def checkdep_tex():
375378
try:
376379
s = subprocess.Popen([str('tex'), '-version'], stdout=subprocess.PIPE,
@@ -440,16 +443,9 @@ def checkdep_ps_distiller(s):
440443
return False
441444

442445
flag = True
443-
gs_req = '7.07'
444-
gs_sugg = '7.07'
446+
gs_req = '8.60'
445447
gs_exec, gs_v = checkdep_ghostscript()
446-
if compare_versions(gs_v, gs_sugg):
447-
pass
448-
elif compare_versions(gs_v, gs_req):
449-
verbose.report(('ghostscript-%s found. ghostscript-%s or later '
450-
'is recommended to use the ps.usedistiller option.')
451-
% (gs_v, gs_sugg))
452-
else:
448+
if not compare_versions(gs_v, gs_req):
453449
flag = False
454450
warnings.warn(('matplotlibrc ps.usedistiller option can not be used '
455451
'unless ghostscript-%s or later is installed on your '
@@ -480,42 +476,28 @@ def checkdep_usetex(s):
480476
if not s:
481477
return False
482478

483-
tex_req = '3.1415'
484-
gs_req = '7.07'
485-
gs_sugg = '7.07'
486-
dvipng_req = '1.5'
479+
gs_req = '8.60'
480+
dvipng_req = '1.6'
487481
flag = True
488482

489-
tex_v = checkdep_tex()
490-
if compare_versions(tex_v, tex_req):
491-
pass
492-
else:
483+
if _backports.which("tex") is None:
493484
flag = False
494-
warnings.warn(('matplotlibrc text.usetex option can not be used '
495-
'unless TeX-%s or later is '
496-
'installed on your system') % tex_req)
485+
warnings.warn('matplotlibrc text.usetex option can not be used unless '
486+
'TeX is installed on your system')
497487

498488
dvipng_v = checkdep_dvipng()
499-
if compare_versions(dvipng_v, dvipng_req):
500-
pass
501-
else:
489+
if not compare_versions(dvipng_v, dvipng_req):
502490
flag = False
503491
warnings.warn('matplotlibrc text.usetex can not be used with *Agg '
504-
'backend unless dvipng-1.5 or later is '
505-
'installed on your system')
492+
'backend unless dvipng-%s or later is installed on '
493+
'your system' % dvipng_req)
506494

507495
gs_exec, gs_v = checkdep_ghostscript()
508-
if compare_versions(gs_v, gs_sugg):
509-
pass
510-
elif compare_versions(gs_v, gs_req):
511-
verbose.report(('ghostscript-%s found. ghostscript-%s or later is '
512-
'recommended for use with the text.usetex '
513-
'option.') % (gs_v, gs_sugg))
514-
else:
496+
if not compare_versions(gs_v, gs_req):
515497
flag = False
516-
warnings.warn(('matplotlibrc text.usetex can not be used '
517-
'unless ghostscript-%s or later is '
518-
'installed on your system') % gs_req)
498+
warnings.warn('matplotlibrc text.usetex can not be used unless '
499+
'ghostscript-%s or later is installed on your system'
500+
% gs_req)
519501

520502
return flag
521503

@@ -811,7 +793,7 @@ def gen_candidates():
811793

812794
_deprecated_ignore_map = {}
813795

814-
_obsolete_set = {'legend.isaxes'}
796+
_obsolete_set = {'text.dvipnghack', 'legend.isaxes'}
815797

816798
# The following may use a value of None to suppress the warning.
817799
_deprecated_set = {'axes.hold'} # do NOT include in _all_deprecated

lib/matplotlib/cbook/_backports.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,75 @@
11
from __future__ import absolute_import
22

3+
import os
4+
import sys
5+
36
import numpy as np
47

58

9+
# Copy-pasted from Python 3.4's shutil.
10+
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
11+
"""Given a command, mode, and a PATH string, return the path which
12+
conforms to the given mode on the PATH, or None if there is no such
13+
file.
14+
15+
`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
16+
of os.environ.get("PATH"), or can be overridden with a custom search
17+
path.
18+
19+
"""
20+
# Check that a given file can be accessed with the correct mode.
21+
# Additionally check that `file` is not a directory, as on Windows
22+
# directories pass the os.access check.
23+
def _access_check(fn, mode):
24+
return (os.path.exists(fn) and os.access(fn, mode)
25+
and not os.path.isdir(fn))
26+
27+
# If we're given a path with a directory part, look it up directly rather
28+
# than referring to PATH directories. This includes checking relative to the
29+
# current directory, e.g. ./script
30+
if os.path.dirname(cmd):
31+
if _access_check(cmd, mode):
32+
return cmd
33+
return None
34+
35+
if path is None:
36+
path = os.environ.get("PATH", os.defpath)
37+
if not path:
38+
return None
39+
path = path.split(os.pathsep)
40+
41+
if sys.platform == "win32":
42+
# The current directory takes precedence on Windows.
43+
if not os.curdir in path:
44+
path.insert(0, os.curdir)
45+
46+
# PATHEXT is necessary to check on Windows.
47+
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
48+
# See if the given file matches any of the expected path extensions.
49+
# This will allow us to short circuit when given "python.exe".
50+
# If it does match, only test that one, otherwise we have to try
51+
# others.
52+
if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
53+
files = [cmd]
54+
else:
55+
files = [cmd + ext for ext in pathext]
56+
else:
57+
# On other platforms you don't have things like PATHEXT to tell you
58+
# what file suffixes are executable, so just pass on cmd as-is.
59+
files = [cmd]
60+
61+
seen = set()
62+
for dir in path:
63+
normdir = os.path.normcase(dir)
64+
if not normdir in seen:
65+
seen.add(normdir)
66+
for thefile in files:
67+
name = os.path.join(dir, thefile)
68+
if _access_check(name, mode):
69+
return name
70+
return None
71+
72+
673
# Copy-pasted from numpy.lib.stride_tricks 1.11.2.
774
def _maybe_view_as_subclass(original_array, new_array):
875
if type(original_array) is not type(new_array):

lib/matplotlib/mpl-data/stylelib/_classic_test.mplstyle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@ text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURE
124124
# may also be loaded, depending on your font settings
125125
text.latex.preview : False
126126

127-
text.dvipnghack : None # some versions of dvipng don't handle alpha
128-
# channel properly. Use True to correct
129-
# and flush ~/.matplotlib/tex.cache
130-
# before testing and False to force
131-
# correction off. None will try and
132-
# guess based on your dvipng version
133-
134127
text.hinting : auto # May be one of the following:
135128
# 'none': Perform no hinting
136129
# 'auto': Use freetype's autohinter

lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@ text.latex.preamble : # IMPROPER USE OF THIS FEATURE WILL LEAD TO LATEX FAILURE
124124
# may also be loaded, depending on your font settings
125125
text.latex.preview : False
126126

127-
text.dvipnghack : None # some versions of dvipng don't handle alpha
128-
# channel properly. Use True to correct
129-
# and flush ~/.matplotlib/tex.cache
130-
# before testing and False to force
131-
# correction off. None will try and
132-
# guess based on your dvipng version
133-
134127
text.hinting : auto # May be one of the following:
135128
# 'none': Perform no hinting
136129
# 'auto': Use freetype's autohinter

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pytest
1313

1414
import numpy as np
15-
from matplotlib import checkdep_tex, cm, rcParams
15+
from matplotlib import checkdep_usetex, cm, rcParams
1616
from matplotlib.backends.backend_pdf import PdfPages
1717
from matplotlib import pyplot as plt
1818
from matplotlib.testing.determinism import (_determinism_source_date_epoch,
@@ -21,8 +21,8 @@
2121
from matplotlib import dviread
2222

2323

24-
needs_tex = pytest.mark.xfail(
25-
not checkdep_tex(),
24+
needs_usetex = pytest.mark.xfail(
25+
not checkdep_usetex(True),
2626
reason="This test needs a TeX installation")
2727

2828

@@ -180,7 +180,7 @@ def test_grayscale_alpha():
180180

181181
# This tests tends to hit a TeX cache lock on AppVeyor.
182182
@pytest.mark.flaky(reruns=3)
183-
@needs_tex
183+
@needs_usetex
184184
def test_missing_psfont(monkeypatch):
185185
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
186186
def psfont(*args, **kwargs):

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
reason="This test needs a ghostscript installation")
2323

2424

25-
needs_tex = pytest.mark.xfail(
26-
not matplotlib.checkdep_tex(),
25+
needs_usetex = pytest.mark.xfail(
26+
not matplotlib.checkdep_usetex(True),
2727
reason="This test needs a TeX installation")
2828

2929

@@ -32,12 +32,12 @@
3232
@pytest.mark.parametrize('format, use_log, rcParams', [
3333
('ps', False, {}),
3434
needs_ghostscript(('ps', False, {'ps.usedistiller': 'ghostscript'})),
35-
needs_tex(needs_ghostscript(('ps', False, {'text.latex.unicode': True,
36-
'text.usetex': True}))),
35+
needs_usetex(needs_ghostscript(('ps', False, {'text.latex.unicode': True,
36+
'text.usetex': True}))),
3737
('eps', False, {}),
3838
('eps', True, {'ps.useafm': True}),
39-
needs_tex(needs_ghostscript(('eps', False, {'text.latex.unicode': True,
40-
'text.usetex': True}))),
39+
needs_usetex(needs_ghostscript(('eps', False, {'text.latex.unicode': True,
40+
'text.usetex': True}))),
4141
], ids=[
4242
'ps',
4343
'ps with distiller',
@@ -115,7 +115,7 @@ def test_patheffects():
115115
fig.savefig(ps, format='ps')
116116

117117

118-
@needs_tex
118+
@needs_usetex
119119
@needs_ghostscript
120120
def test_tilde_in_tempfilename():
121121
# Tilde ~ in the tempdir path (e.g. TMPDIR, TMP oder TEMP on windows
@@ -169,7 +169,7 @@ def test_determinism_all():
169169
_determinism_check(format="ps")
170170

171171

172-
@needs_tex
172+
@needs_usetex
173173
@needs_ghostscript
174174
def test_determinism_all_tex():
175175
"""Test for reproducible PS/tex output"""

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
from matplotlib import dviread
1818

1919

20-
needs_tex = pytest.mark.xfail(
21-
not matplotlib.checkdep_tex(),
20+
needs_usetex = pytest.mark.xfail(
21+
not matplotlib.checkdep_usetex(True),
2222
reason="This test needs a TeX installation")
2323

2424

@@ -187,13 +187,13 @@ def test_determinism_notex():
187187
_test_determinism('determinism_notex.svg', usetex=False)
188188

189189

190-
@needs_tex
190+
@needs_usetex
191191
def test_determinism_tex():
192192
# unique filename to allow for parallel testing
193193
_test_determinism('determinism_tex.svg', usetex=True)
194194

195195

196-
@needs_tex
196+
@needs_usetex
197197
def test_missing_psfont(monkeypatch):
198198
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
199199
from matplotlib import rc

lib/matplotlib/texmanager.py

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
Requirements:
88
99
* latex
10-
* \\*Agg backends: dvipng
11-
* PS backend: latex w/ psfrag, dvips, and Ghostscript 8.51
12-
(older versions do not work properly)
10+
* \\*Agg backends: dvipng>=1.6
11+
* PS backend: psfrag, dvips, and Ghostscript>=8.60
1312
1413
Backends:
1514
@@ -23,7 +22,7 @@
2322
texmanager = TexManager()
2423
s = ('\\TeX\\ is Number '
2524
'$\\displaystyle\\sum_{n=1}^\\infty\\frac{-e^{i\\pi}}{2^n}$!')
26-
Z = self.texmanager.get_rgba(s, size=12, dpi=80, rgb=(1,0,0))
25+
Z = texmanager.get_rgba(s, fontsize=12, dpi=80, rgb=(1,0,0))
2726
2827
To enable tex rendering of all text in your matplotlib figure, set
2928
text.usetex in your matplotlibrc file or include these two lines in
@@ -66,6 +65,7 @@
6665
cmd_split = ';'
6766

6867

68+
@mpl.cbook.deprecated("2.1")
6969
def dvipng_hack_alpha():
7070
try:
7171
p = Popen([str('dvipng'), '-version'], stdin=PIPE, stdout=PIPE,
@@ -123,8 +123,6 @@ class TexManager(object):
123123
if texcache is not None:
124124
mkdirs(texcache)
125125

126-
_dvipng_hack_alpha = None
127-
#_dvipng_hack_alpha = dvipng_hack_alpha()
128126
# mappable cache of
129127
rgba_arrayd = {}
130128
grey_arrayd = {}
@@ -543,46 +541,10 @@ def get_grey(self, tex, fontsize=None, dpi=None):
543541
"""returns the alpha channel"""
544542
key = tex, self.get_font_config(), fontsize, dpi
545543
alpha = self.grey_arrayd.get(key)
546-
547544
if alpha is None:
548545
pngfile = self.make_png(tex, fontsize, dpi)
549546
X = read_png(os.path.join(self.texcache, pngfile))
550-
551-
if rcParams['text.dvipnghack'] is not None:
552-
hack = rcParams['text.dvipnghack']
553-
else:
554-
if TexManager._dvipng_hack_alpha is None:
555-
TexManager._dvipng_hack_alpha = dvipng_hack_alpha()
556-
hack = TexManager._dvipng_hack_alpha
557-
558-
if hack:
559-
# hack the alpha channel
560-
# dvipng assumed a constant background, whereas we want to
561-
# overlay these rasters with antialiasing over arbitrary
562-
# backgrounds that may have other figure elements under them.
563-
# When you set dvipng -bg Transparent, it actually makes the
564-
# alpha channel 1 and does the background compositing and
565-
# antialiasing itself and puts the blended data in the rgb
566-
# channels. So what we do is extract the alpha information
567-
# from the red channel, which is a blend of the default dvipng
568-
# background (white) and foreground (black). So the amount of
569-
# red (or green or blue for that matter since white and black
570-
# blend to a grayscale) is the alpha intensity. Once we
571-
# extract the correct alpha information, we assign it to the
572-
# alpha channel properly and let the users pick their rgb. In
573-
# this way, we can overlay tex strings on arbitrary
574-
# backgrounds with antialiasing
575-
#
576-
# red = alpha*red_foreground + (1-alpha)*red_background
577-
#
578-
# Since the foreground is black (0) and the background is
579-
# white (1) this reduces to red = 1-alpha or alpha = 1-red
580-
#alpha = npy.sqrt(1-X[:,:,0]) # should this be sqrt here?
581-
alpha = 1 - X[:, :, 0]
582-
else:
583-
alpha = X[:, :, -1]
584-
585-
self.grey_arrayd[key] = alpha
547+
self.grey_arrayd[key] = alpha = X[:, :, -1]
586548
return alpha
587549

588550
def get_rgba(self, tex, fontsize=None, dpi=None, rgb=(0, 0, 0)):

0 commit comments

Comments
 (0)
0