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,