From 782732629ee0b13a9265db56d173611db15b2d89 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 15 Oct 2017 22:01:25 -0700 Subject: [PATCH] Minor fixes to plot_directive. 1. The `plot_directive` function was reusing the module's docstring, but the latter is not valid numpydoc. Replace by a short stub pointing to the module docstring. 2. jinja2 is a requirement of sphinx since 2008 (sphinx-doc/sphinx@eeb494c), so we can reasonably drop the code to support jinja1. --- lib/matplotlib/sphinxext/plot_directive.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/matplotlib/sphinxext/plot_directive.py b/lib/matplotlib/sphinxext/plot_directive.py index 795c39daac73..9109bc1fd496 100644 --- a/lib/matplotlib/sphinxext/plot_directive.py +++ b/lib/matplotlib/sphinxext/plot_directive.py @@ -159,15 +159,7 @@ sphinx_version = tuple([int(re.split('[^0-9]', x)[0]) for x in sphinx_version[:2]]) -try: - # Sphinx depends on either Jinja or Jinja2 - import jinja2 - def format_template(template, **kw): - return jinja2.Template(template).render(**kw) -except ImportError: - import jinja - def format_template(template, **kw): - return jinja.from_string(template, **kw) +import jinja2 # Sphinx dependency. import matplotlib import matplotlib.cbook as cbook @@ -190,8 +182,11 @@ def format_template(template, **kw): def plot_directive(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): + """Implementation of the ``.. plot::`` directive. + + See the module docstring for details. + """ return run(arguments, content, options, state_machine, state, lineno) -plot_directive.__doc__ = __doc__ def _option_boolean(arg): @@ -827,8 +822,7 @@ def run(arguments, content, options, state_machine, state, lineno): else: src_link = None - result = format_template( - config.plot_template or TEMPLATE, + result = jinja2.Template(config.plot_template or TEMPLATE).render( default_fmt=default_fmt, dest_dir=dest_dir_link, build_dir=build_dir_link,