148
148
import traceback
149
149
import warnings
150
150
151
- from docutils import nodes
152
151
from docutils .parsers .rst import directives , Directive
153
152
from docutils .parsers .rst .directives .images import Image
154
- align = Image .align
155
153
import jinja2 # Sphinx dependency.
156
154
157
155
import matplotlib
166
164
else :
167
165
import matplotlib .pyplot as plt
168
166
from matplotlib import _pylab_helpers , cbook
167
+ align = Image .align
169
168
170
169
__version__ = 2
171
170
175
174
# -----------------------------------------------------------------------------
176
175
177
176
177
+ @cbook .deprecated ("3.1" , alternative = "PlotDirective" )
178
178
def plot_directive (name , arguments , options , content , lineno ,
179
179
content_offset , block_text , state , state_machine ):
180
- """Deprecated function-based implementation of the ``.. plot::`` directive.
180
+ """Implementation of the ``.. plot::`` directive.
181
181
182
- Use PlotDirective instead.
183
- See the module docstring for details on configuration.
182
+ See the module docstring for details.
184
183
"""
185
184
return run (arguments , content , options , state_machine , state , lineno )
186
185
@@ -270,17 +269,14 @@ class PlotDirective(Directive):
270
269
def run (self ):
271
270
"""Run the plot directive."""
272
271
return run (self .arguments , self .content , self .options ,
273
- self .state_machine , self .state , self .lineno ,
274
- function = False )
272
+ self .state_machine , self .state , self .lineno )
275
273
276
274
277
275
def setup (app ):
276
+ import matplotlib
278
277
setup .app = app
279
278
setup .config = app .config
280
279
setup .confdir = app .confdir
281
- # Old, function-based method was equivalent to:
282
- # app.add_directive('plot', plot_directive, True, (0, 2, False),
283
- # **PlotDirective.option_spec)
284
280
app .add_directive ('plot' , PlotDirective )
285
281
app .add_config_value ('plot_pre_code' , None , True )
286
282
app .add_config_value ('plot_include_source' , False , True )
@@ -296,7 +292,7 @@ def setup(app):
296
292
app .connect ('doctree-read' , mark_plot_labels )
297
293
298
294
metadata = {'parallel_read_safe' : True , 'parallel_write_safe' : True ,
299
- 'version' : 0.2 }
295
+ 'version' : matplotlib . __version__ }
300
296
return metadata
301
297
302
298
@@ -653,8 +649,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
653
649
return results
654
650
655
651
656
- def run (arguments , content , options , state_machine , state , lineno ,
657
- function = True ):
652
+ def run (arguments , content , options , state_machine , state , lineno ):
658
653
document = state_machine .document
659
654
config = document .settings .env .config
660
655
nofigs = 'nofigs' in options
@@ -824,6 +819,9 @@ def run(arguments, content, options, state_machine, state, lineno,
824
819
total_lines .extend (result .split ("\n " ))
825
820
total_lines .extend ("\n " )
826
821
822
+ if total_lines :
823
+ state_machine .insert_input (total_lines , source = source_file_name )
824
+
827
825
# copy image files to builder's output directory, if necessary
828
826
Path (dest_dir ).mkdir (parents = True , exist_ok = True )
829
827
@@ -839,14 +837,4 @@ def run(arguments, content, options, state_machine, state, lineno,
839
837
unescape_doctest (code ) if source_file_name == rst_file else code ,
840
838
encoding = 'utf-8' )
841
839
842
- if function :
843
- if total_lines :
844
- state_machine .insert_input (total_lines , source = source_file_name )
845
- out = errors
846
- else :
847
- if len (errors ):
848
- out = errors
849
- else :
850
- out = [nodes .raw ('\n ' .join (total_lines ))] if total_lines else []
851
-
852
- return out
840
+ return errors
0 commit comments