8000 Deprecate checkdep_usetex. by anntzer · Pull Request #14455 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deprecate checkdep_usetex. #14455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ Flags containing "U" passed to `.cbook.to_filehandle` and `.cbook.open_file_cm`
Please remove "U" from flags passed to `.cbook.to_filehandle` and
`.cbook.open_file_cm`. This is consistent with their removal from `open` in
Python 3.9.

``matplotlib.checkdep_usetex``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``matplotlib.checkdep_usetex`` is deprecated (it checks for the presence of
tex, dvipng, and ghostscript, even though ghostscript is not needed for raster
output and dvipng is not needed for vector output). The
``matplotlib.testing.decorators.needs_usetex`` is a partial replacement to
decorate tests that depend on usetex mode.
2 changes: 2 additions & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ def checkdep_ps_distiller(s):
return s


@cbook.deprecated(
"3.3", alternative="matplotlib.testing.decorators.needs_usetex")
def checkdep_usetex(s):
if not s:
return False
Expand Down
25 changes: 25 additions & 0 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,28 @@ def backend_switcher(*args, **kwargs):
return backend_switcher

return switch_backend_decorator


def needs_usetex(func):
"""
Decorate *func* with `unittest.skipIf` to skip the test if usetex
dependencies are missing.
"""
has_tex = shutil.which("tex")
try:
mpl._get_executable_info("dvipng")
except FileNotFoundError:
has_dvipng = False
else:
has_dvipng = True
try:
mpl._get_executable_info("gs")
except FileNotFoundError:
has_gs = False
else:
has_gs = True
return (
unittest.skipIf(not has_tex, "usetex requires TeX.")(
unittest.skipIf(not has_dvipng, "usetex requires dvipng.")(
unittest.skipIf(not has_gs, "usetex requires ghostscript.")(
func))))
7 changes: 1 addition & 6 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
from matplotlib import dviread, pyplot as plt, checkdep_usetex, rcParams
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.testing.compare import compare_images
from matplotlib.testing.decorators import image_comparison


needs_usetex = pytest.mark.skipif(
not checkdep_usetex(True),
reason="This test needs a TeX installation")
from matplotlib.testing.decorators import image_comparison, needs_usetex


@image_comparison(['pdf_use14corefonts.pdf'])
Expand Down
10 changes: 3 additions & 7 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib import cbook, patheffects
from matplotlib.testing.decorators import image_comparison
from matplotlib.testing.decorators import image_comparison, needs_usetex


needs_ghostscript = pytest.mark.skipif(
"eps" not in mpl.testing.compare.converter,
reason="This test needs a ghostscript installation")
needs_usetex = pytest.mark.skipif(
not mpl.checkdep_usetex(True),
reason="This test needs a TeX installation")


# This tests tends to hit a TeX cache lock on AppVeyor.
Expand All @@ -26,11 +23,11 @@
pytest.param('ps', False, {'ps.usedistiller': 'ghostscript'},
marks=needs_ghostscript),
pytest.param('ps', False, {'text.usetex': True},
marks=[needs_ghostscript, needs_usetex]),
marks=needs_usetex),
('eps', False, {}),
('eps', True, {'ps.useafm': True}),
pytest.param('eps', False, {'text.usetex': True},
marks=[needs_ghostscript, needs_usetex]),
marks=needs_usetex),
], ids=[
'ps',
'ps with distiller',
Expand Down Expand Up @@ -75,7 +72,6 @@ def test_patheffects():


@needs_usetex
@needs_ghostscript
def tes E29B t_tilde_in_tempfilename(tmpdir):
# Tilde ~ in the tempdir path (e.g. TMPDIR, TMP or TEMP on windows
# when the username is very long and windows uses a short name) breaks
Expand Down
7 changes: 1 addition & 6 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
from matplotlib import dviread
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison


needs_usetex = pytest.mark.skipif(
not mpl.checkdep_usetex(True),
reason="This test needs a TeX installation")
from matplotlib.testing.decorators import image_comparison, needs_usetex


def test_visibility():
Expand Down
7 changes: 1 addition & 6 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
from matplotlib.backend_bases import MouseEvent
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import check_figures_equal, image_comparison


needs_usetex = pytest.mark.skipif(
not matplotlib.checkdep_usetex(True),
reason="This test needs a TeX installation")
from matplotlib.testing.decorators import image_comparison, needs_usetex


@image_comparison(['font_styles'])
Expand Down
18 changes: 7 additions & 11 deletions lib/matplotlib/tests/test_usetex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
import platform

import matplotlib as mpl
from matplotlib.testing.decorators import check_figures_equal, image_comparison
from matplotlib.testing.decorators import (
check_figures_equal, image_comparison, needs_usetex)
import matplotlib.pyplot as plt


@pytest.fixture(autouse=True) # All tests in this module use usetex.
def usetex():
if not mpl.checkdep_usetex(True):
pytest.skip('Missing TeX of Ghostscript or dvipng')
mpl.rcParams['text.usetex'] = True


@needs_usetex
@image_comparison(baseline_images=['test_usetex'],
extensions=['pdf', 'png'],
tol={'aarch64': 2.868}.get(platform.machine(), 0.3))
Expand All @@ -25,12 +20,13 @@ def test_usetex():
# \sqrt and \frac draw horizontal rules, \mathrm changes the font
r'\LaTeX\ $\left[\int\limits_e^{2e}'
r'\sqrt\frac{\log^3 x}{x}\,\mathrm{d}x \right\}$',
fontsize=24)
usetex=True, fontsize=24)
ax.set_xticks([])
ax.set_yticks([])


@needs_usetex
@check_figures_equal()
def test_unicode_minus(fig_test, fig_ref):
fig_test.text(.5, .5, "$-$")
fig_ref.text(.5, .5, "\N{MINUS SIGN}")
fig_test.text(.5, .5, "$-$", usetex=True)
fig_ref.text(.5, .5, "\N{MINUS SIGN}", usetex=True)
0