8000 API: Use class-based directive in sphinxext by larsoner · Pull Request #13138 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

API: Use class-based directive in sphinxext #13138

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 4 commits into from
Jan 10, 2019
Merged
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
1 change: 0 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ per-file-ignores =
matplotlib/projections/geo.py: E203, E221, E502
matplotlib/pylab.py: E501
matplotlib/rcsetup.py: E501
matplotlib/sphinxext/plot_directive.py: E402
matplotlib/tests/test_mathtext.py: E501
matplotlib/transforms.py: E201, E202, E203, E501
matplotlib/tri/triinterpolate.py: E201, E221
Expand Down
8 changes: 8 additions & 0 deletions doc/api/next_api_changes/2019-01-09-deprecations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Deprecations
````````````

The ``matplotlib.sphinxext.plot_directive`` interface has changed from
the (Sphinx-)deprecated function-based interface to a class-based interface.
This should not affect end users, but the
``matplotlib.sphinxext.plot_directive.plot_directive`` function is now
deprecated.
55 changes: 37 additions & 18 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@
import traceback
import warnings

from docutils.parsers.rst import directives
from docutils.parsers.rst import directives, Directive
from docutils.parsers.rst.directives.images import Image
align = Image.align
import jinja2 # Sphinx dependency.

import matplotlib
Expand All @@ -165,6 +164,7 @@
else:
import matplotlib.pyplot as plt
from matplotlib import _pylab_helpers, cbook
align = Image.align

__version__ = 2

Expand All @@ -174,6 +174,7 @@
# -----------------------------------------------------------------------------


@cbook.deprecated("3.1", alternative="PlotDirective")
def plot_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
"""Implementation of the ``.. plot::`` directive.
Expand Down Expand Up @@ -241,25 +242,42 @@ def mark_plot_labels(app, document):
break


class PlotDirective(Directive):
"""Implementation of the ``.. plot::`` directive.

See the module docstring for details.
"""

has_content = True
required_arguments = 0
optional_arguments = 2
final_argument_whitespace = False
option_spec = {
'alt': directives.unchanged,
'height': directives.length_or_unitless,
'width': directives.length_or_percentage_or_unitless,
'scale': directives.nonnegative_int,
'align': _option_align,
'class': directives.class_option,
'include-source': _option_boolean,
'format': _option_format,
'context': _option_context,
'nofigs': directives.flag,
'encoding': directives.encoding,
}

def run(self):
"""Run the plot directive."""
return run(self.arguments, self.content, self.options,
self.state_machine, self.state, self.lineno)


def setup(app):
import matplotlib
setup.app = app
setup.config = app.config
setup.confdir = app.confdir

options = {'alt': directives.unchanged,
'height': directives.length_or_unitless,
'width': directives.length_or_percentage_or_unitless,
'scale': directives.nonnegative_int,
'align': _option_align,
'class': directives.class_option,
'include-source': _option_boolean,
'format': _option_format,
'context': _option_context,
'nofigs': directives.flag,
'encoding': directives.encoding
}

app.add_directive('plot', plot_directive, True, (0, 2, False), **options)
app.add_directive('plot', PlotDirective)
app.add_config_value('plot_pre_code', None, True)
app.add_config_value('plot_include_source', False, True)
app.add_config_value('plot_html_show_source_link', True, True)
Expand All @@ -273,7 +291,8 @@ def setup(app):

app.connect('doctree-read', mark_plot_labels)

metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
metadata = {'parallel_read_safe': True, 'parallel_write_safe': True,
'version': matplotlib.__version__}
return metadata


Expand Down
0