@@ -271,15 +271,17 @@ def _import_matplotlib():
271271_import_matplotlib ()
272272
273273
274- def matplotlib_scraper (image_path_iterator , gallery_conf ):
274+ def matplotlib_scraper (block , block_vars , gallery_conf ):
275275 """Scrape Matplotlib images.
276276
277277 Parameters
278278 ----------
279- image_path_iterator : iterable of str
280- Iterator to get destination paths for images.
279+ block : tuple
280+ A tuple containing the (label, content, line_number) of the block.
281+ block_vars : dict
282+ Dict of block variables.
281283 gallery_conf : dict
282- The gallery configuration values.
284+ Contains the configuration of Sphinx-Gallery
283285
284286 Returns
285287 -------
@@ -289,6 +291,7 @@ def matplotlib_scraper(image_path_iterator, gallery_conf):
289291 :func:`sphinx_gallery.gen_rst.figure_rst`.
290292 """
291293 matplotlib , plt = _import_matplotlib ()
294+ image_path_iterator = block_vars ['image_path_iterator' ]
292295 image_paths = list ()
293296 for fig_num , image_path in zip (plt .get_fignums (), image_path_iterator ):
294297 # Set the fig_num figure as the current figure as we can't
@@ -307,15 +310,17 @@ def matplotlib_scraper(image_path_iterator, gallery_conf):
307310 return figure_rst (image_paths , gallery_conf ['src_dir' ])
308311
309312
310- def mayavi_scraper (image_path_iterator , gallery_conf ):
313+ def mayavi_scraper (block , block_vars , gallery_conf ):
311314 """Scrape Mayavi images.
312315
313316 Parameters
314317 ----------
315- image_path_iterator : iterable of str
316- Iterator to get destination paths for images.
318+ block : tuple
319+ A tuple containing the (label, content, line_number) of the block.
320+ block_vars : dict
321+ Dict of block variables.
317322 gallery_conf : dict
318- The gallery configuration values.
323+ Contains the configuration of Sphinx-Gallery
319324
320325 Returns
321326 -------
@@ -325,6 +330,7 @@ def mayavi_scraper(image_path_iterator, gallery_conf):
325330 :func:`sphinx_gallery.gen_rst.figure_rst`.
326331 """
327332 from mayavi import mlab
333+ image_path_iterator = block_vars ['image_path_iterator' ]
328334 image_paths = list ()
329335 e = mlab .get_engine ()
330336 for scene , image_path in zip (e .scenes , image_path_iterator ):
@@ -378,13 +384,15 @@ def __next__(self):
378384 return path
379385
380386
381- def save_figures (image_path_iterator , gallery_conf ):
387+ def save_figures (block , block_vars , gallery_conf ):
382388 """Save all open figures of the example code-block.
383389
384390 Parameters
385391 ----------
386- image_path_iterator : iterable of str
387- Iterator to get destination paths for images.
392+ block : tuple
393+ A tuple containing the (label, content, line_number) of the block.
394+ block_vars : dict
395+ Dict of block variables.
388396 gallery_conf : dict
389397 Contains the configuration of Sphinx-Gallery
390398
@@ -395,10 +403,11 @@ def save_figures(image_path_iterator, gallery_conf):
395403 fig_num : int
396404 number of figures saved
397405 """
406+ image_path_iterator = block_vars ['image_path_iterator' ]
398407 all_rst = u''
399408 prev_count = len (image_path_iterator )
400409 for scraper in gallery_conf ['image_scrapers' ]:
401- rst = scraper (image_path_iterator , gallery_conf )
410+ rst = scraper (block , block_vars , gallery_conf )
402411 if not isinstance (rst , basestring ):
403412 raise TypeError ('rst from scraper %r was not a string, '
404413 'got type %s:\n %r'
@@ -659,7 +668,7 @@ def execute_code_block(compiler, block, example_globals,
659668 code_output = u"\n {0}\n \n \n \n " .format (except_rst )
660669 # still call this even though we won't use the images so that
661670 # figures are closed
662- save_figures (block_vars [ 'image_path_iterator' ] , gallery_conf )
671+ save_figures (block , block_vars , gallery_conf )
663672 else :
664673 sys .stdout .flush ()
665674 sys .stdout = orig_stdout
@@ -670,8 +679,7 @@ def execute_code_block(compiler, block, example_globals,
670679 stdout = CODE_OUTPUT .format (indent (my_stdout , u' ' * 4 ))
671680 else :
672681 stdout = ''
673- images_rst = save_figures (
674- block_vars ['image_path_iterator' ], gallery_conf )
682+ images_rst = save_figures (block , block_vars , gallery_conf )
675683 code_output = u"\n {0}\n \n {1}\n \n " .format (images_rst , stdout )
676684
677685 finally :
0 commit comments