8000 Drop tex version check. · matplotlib/matplotlib@83db163 · GitHub
[go: up one dir, main page]

Skip to content

Commit 83db163

Browse files
committed
Drop tex version check.
Recent MiKTeXs don't report the TeX version, but given that any TeX released after 1995 (TeX 3.14159), or possibly even older will work, we can realistically drop the version check. Also drop the "suggested" gs version, which has matched the required gs version since 2006 (released on 2007-08-01), and up the minimum version to 8.60, to match the docs in usetex.py.
1 parent 545af7a commit 83db163

File tree

7 files changed

+105
-54
lines changed

7 files changed

+105
-54
lines changed

lib/matplotlib/__init__.py

Lines changed: 17 additions & 35 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

@@ -390,6 +390,9 @@ def checkdep_ghostscript():
390390
checkdep_ghostscript.version = None
391391

392392

393+
# Deprecated, as it is unneeded and some distributions (e.g. MiKTeX 2.9.6350)
394+
# do not actually report the TeX version.
395+
@cbook.deprecated("2.1")
393396
def checkdep_tex():
394397
try:
395398
s = subprocess.Popen([str('tex'), '-version'], stdout=subprocess.PIPE,
@@ -459,16 +462,9 @@ def checkdep_ps_distiller(s):
459462
return False
460463

461464
flag = True
462-
gs_req = '7.07'
463-
gs_sugg = '7.07'
465+
gs_req = '8.60'
464466
gs_exec, gs_v = checkdep_ghostscript()
465-
if compare_versions(gs_v, gs_sugg):
466-
pass
467-
elif compare_versions(gs_v, gs_req):
468-
verbose.report(('ghostscript-%s found. ghostscript-%s or later '
469-
'is recommended to use the ps.usedistiller option.')
470-
% (gs_v, gs_sugg))
471-
else:
467+
if not compare_versions(gs_v, gs_req):
472468
flag = False
473469
warnings.warn(('matplotlibrc ps.usedistiller option can not be used '
474470
'unless ghostscript-%s or later is installed on your '
@@ -499,42 +495,28 @@ def checkdep_usetex(s):
499495
if not s:
500496
return False
501497

502-
tex_req = '3.1415'
503-
gs_req = '7.07'
504-
gs_sugg = '7.07'
498+
gs_req = '8.60'
505499
dvipng_req = '1.5'
506500
flag = True
507501

508-
tex_v = checkdep_tex()
509-
if compare_versions(tex_v, tex_req):
510-
pass
511-
else:
502+
if _backports.which("tex") is None:
512503
flag = False
513-
warnings.warn(('matplotlibrc text.usetex option can not be used '
514-
'unless TeX-%s or later is '
515-
'installed on your system') % tex_req)
504+
warnings.warn('matplotlibrc text.usetex option can not be used unless '
505+
'TeX is installed on your system')
516506

517507
dvipng_v = checkdep_dvipng()
518-
if compare_versions(dvipng_v, dvipng_req):
519-
pass
520-
else:
508+
if not compare_versions(dvipng_v, dvipng_req):
521509
flag = False
522510
warnings.warn('matplotlibrc text.usetex can not be used with *Agg '
523-
'backend unless dvipng-1.5 or later is '
524-
'installed on your system')
511+
'backend unless dvipng-1.5 or later is installed on '
512+
'your system')
525513

526514
gs_exec, gs_v = checkdep_ghostscript()
527-
if compare_versions(gs_v, gs_sugg):
528-
pass
529-
elif compare_versions(gs_v, gs_req):
530-
verbose.report(('ghostscript-%s found. ghostscript-%s or later is '
531-
'recommended for use with the text.usetex '
532-
'option.') % (gs_v, gs_sugg))
533-
else:
515+
if not compare_versions(gs_v, gs_req):
534516
flag = False
535-
warnings.warn(('matplotlibrc text.usetex can not be used '
536-
'unless ghostscript-%s or later is '
537-
'installed on your system') % gs_req)
517+
warnings.warn('matplotlibrc text.usetex can not be used unless '
518+
'ghostscript-%s or later is installed on your system'
519+
% gs_req)
538520

539521
return flag
540522

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/tests/test_backend_pdf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 4 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

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ pep8ignore =
1414
setup.py E402 E501
1515
setupext.py E301 E302 E501
1616
setup_external_compile.py E302 E501 E711
17+
1718
versioneer.py ALL # External file.
1819
tools/gh_api.py ALL # External file.
1920
tools/github_stats.py ALL # External file.
21+
matplotlib/cbook/_backports.py ALL # Copy-pasted functions.
22+
2023
tools/subset.py E221 E231 E251 E261 E302 E501 E701 E703
2124

2225
matplotlib/backends/qt_editor/formlayout.py E301 E402 E501

0 commit comments

Comments
 (0)
0