Skip to content

Minor fixes to plot_directive. #9425

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

Merged
merged 1 commit into from
Oct 20, 2017
Merged
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
18 changes: 6 additions & 12 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down