Skip to content

Commit 64f2b28

Browse files
committed
Also check luatex version using the general executable checker.
1 parent 41eac98 commit 64f2b28

File tree

3 files changed

+32
-41
lines changed

3 files changed

+32
-41
lines changed

lib/matplotlib/__init__.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,20 @@ def wrapper(*args, **kwargs):
423423

424424

425425
_ExecInfo = namedtuple("_ExecInfo", "executable version")
426+
# Moved out to allow unit-testing.
427+
_version_regexes = {
428+
"dvipng": "(?m)^dvipng .* (.+)",
429+
"gs": "(.*)",
430+
"inkscape": "^Inkscape ([^ ]*)",
431+
"luatex": r"^This is LuaTeX, Version (?:beta-)?(\d+\.\d+\.\d+)",
432+
"pdftops": "^pdftops version (.*)",
433+
}
426434

427435

428436
@functools.lru_cache()
429437
def get_executable_info(name):
430-
"""Get the version of some executables that Matplotlib depends on.
438+
"""
439+
Get the version of some executables that Matplotlib depends on.
431440
432441
.. warning:
433442
The list of executables that this function supports is set according to
@@ -437,8 +446,8 @@ def get_executable_info(name):
437446
----------
438447
name : str
439448
The executable to query. The following values are currently supported:
440-
"dvipng", "gs", "inkscape", "pdftops", "tex". This list is subject to
441-
change without notice.
449+
"dvipng", "gs", "inkscape", "luatex", "pdftops", "tex". This list is
450+
subject to change without notice.
442451
443452
Returns
444453
-------
@@ -473,19 +482,23 @@ def impl(args, regex, min_ver=None):
473482
return None
474483

475484
if name == "dvipng":
476-
info = impl(["dvipng", "-version"], "(?m)^dvipng .* (.+)", "1.6")
485+
info = impl(["dvipng", "-version"], _version_regexes["dvipng"], "1.6")
477486
elif name == "gs":
478487
execs = (["gswin32c", "gswin64c", "mgs", "gs"] # "mgs" for miktex.
479488
if sys.platform == "win32" else
480489
["gs"])
481-
info = next((info for info in (impl([e, "--version"], "(.*)", "9")
482-
for e in execs)
483-
if info),
484-
None)
490+
info = next(
491+
(info for info in (
492+
impl([e, "--version"], _version_regexes["gs"], "9")
493+
for e in execs)
494+
if info),
495+
None)
485496
elif name == "inkscape":
486-
info = impl(["inkscape", "-V"], "^Inkscape ([^ ]*)")
497+
info = impl(["inkscape", "-V"], _version_regexes["inkscape"])
498+
elif name == "luatex":
499+
info = impl(["luatex", "--version"], _version_regexes["luatex"])
487500
elif name == "pdftops":
488-
info = impl(["pdftops", "-v"], "^pdftops version (.*)")
501+
info = impl(["pdftops", "-v"], _version_regexes["pdftops"])
489502
if info and not ("3.0" <= info.version
490503
# poppler version numbers.
491504
or "0.9" <= info.version <= "1.0"):
@@ -502,7 +515,8 @@ def impl(args, regex, min_ver=None):
502515

503516

504517
def get_all_executable_infos():
505-
"""Query all executables that Matplotlib may need.
518+
"""
519+
Query all executables that Matplotlib may need.
506520
507521
.. warning:
508522
The list of executables that this function queries is set according to
@@ -515,7 +529,8 @@ def get_all_executable_infos():
515529
to change without notice.
516530
"""
517531
return {name: get_executable_info(name)
518-
for name in ["dvipng", "gs", "inkscape", "pdftops", "tex"]}
532+
for name in ["dvipng", "gs", "inkscape", "luatex", "pdftops",
533+
"tex"]}
519534

520535

521536
@cbook.deprecated("3.0")

lib/matplotlib/backends/backend_pgf.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
###############################################################################
3131

3232

33-
_luatex_version_re = re.compile(
34-
r'This is LuaTeX, Version (?:beta-)?([0-9]+)\.([0-9]+)\.([0-9]+)'
35-
)
36-
37-
3833
@cbook.deprecated("3.0")
3934
def get_texcommand():
4035
"""Get chosen TeX system from rc."""
@@ -43,18 +38,6 @@ def get_texcommand():
4338
return texsystem if texsystem in texsystem_options else "xelatex"
4439

4540

46-
def _get_lualatex_version():
47-
"""Get version of luatex"""
48-
output = subprocess.check_output(['lualatex', '--version'])
49-
return _parse_lualatex_version(output.decode())
50-
51-
52-
def _parse_lualatex_version(output):
53-
'''parse the lualatex version from the output of `lualatex --version`'''
54-
match = _luatex_version_re.match(output)
55-
return tuple(map(int, match.groups()))
56-
57-
5841
def get_fontspec():
5942
"""Build fontspec preamble from rc."""
6043
latex_fontspec = []
@@ -1166,8 +1149,8 @@ def _build_newpage_command(self, width, height):
11661149
so we need to check the lualatex version and use `\pagewidth` if
11671150
the version is 0.85 or newer
11681151
'''
1169-
texcommand = get_texcommand()
1170-
if texcommand == 'lualatex' and _get_lualatex_version() >= (0, 85, 0):
1152+
if (get_texcommand() == 'lualatex'
1153+
and mpl.get_executable_info('luatex').version >= '0.85'):
11711154
cmd = r'\page'
11721155
else:
11731156
cmd = r'\pdfpage'

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
from pathlib import Path
3+
import re
34
import shutil
45
import subprocess
56
from tempfile import TemporaryDirectory
@@ -272,11 +273,7 @@ def test_pdf_pages_lualatex():
272273
assert pdf.get_pagecount() == 2
273274

274275

275-
@needs_lualatex
276276
def test_luatex_version():
277-
from matplotlib.backends.backend_pgf import _parse_lualatex_version
278-
from matplotlib.backends.backend_pgf import _get_lualatex_version
279-
280277
v1 = '''This is LuaTeX, Version 1.0.4 (TeX Live 2017)
281278
282279
Execute 'luatex --credits' for credits and version details.
@@ -301,9 +298,5 @@ def test_luatex_version():
301298
Copyright 2013 Taco Hoekwater, the LuaTeX Team.
302299
'''
303300

304-
assert _parse_lualatex_version(v1) == (1, 0, 4)
305-
assert _parse_lualatex_version(v2) == (0, 76, 0)
306-
307-
# just test if it is successful
308-
version = _get_lualatex_version()
309-
assert len(version) == 3
301+
assert re.search(mpl._version_regexes["luatex"], v1).group(1) == "1.0.4"
302+
assert re.search(mpl._version_regexes["luatex"], v2).group(1) == "0.76.0"

0 commit comments

Comments
 (0)