sphinx_gallery.scrapers

Scrapers for embedding images

Collect images that have been produced by code blocks.

Functions

sphinx_gallery.scrapers.clean_modules(gallery_conf, fname)

Remove, unload, or reset modules after running each example.

After a script is executed it can load a variety of settings that one does not want to influence in other examples in the gallery.

Parameters:
  • gallery_conf (dict) – The gallery configuration.
  • fname (str | None) – The example being run. Will be None when this is called entering a directory of examples to be built.
sphinx_gallery.scrapers.figure_rst(figure_list, sources_dir)

Generate RST for a list of PNG filenames.

Depending on whether we have one or more figures, we use a single rst call to ‘image’ or a horizontal list.

Parameters:
  • figure_list (list of str) – Strings are the figures’ absolute paths
  • sources_dir (str) – absolute path of Sphinx documentation sources
Returns:

images_rst – rst code to embed the images in the document

Return type:

str

sphinx_gallery.scrapers.matplotlib_scraper(block, block_vars, gallery_conf)

Scrape Matplotlib images.

Parameters:
  • block (tuple) – A tuple containing the (label, content, line_number) of the block.
  • block_vars (dict) – Dict of block variables.
  • gallery_conf (dict) – Contains the configuration of Sphinx-Gallery
Returns:

rst – The ReSTructuredText that will be rendered to HTML containing the images. This is often produced by sphinx_gallery.gen_rst.figure_rst().

Return type:

str

sphinx_gallery.scrapers.mayavi_scraper(block, block_vars, gallery_conf)

Scrape Mayavi images.

Parameters:
  • block (tuple) – A tuple containing the (label, content, line_number) of the block.
  • block_vars (dict) – Dict of block variables.
  • gallery_conf (dict) – Contains the configuration of Sphinx-Gallery
Returns:

rst – The ReSTructuredText that will be rendered to HTML containing the images. This is often produced by sphinx_gallery.gen_rst.figure_rst().

Return type:

str

sphinx_gallery.scrapers.save_figures(block, block_vars, gallery_conf)

Save all open figures of the example code-block.

Parameters:
  • block (tuple) – A tuple containing the (label, content, line_number) of the block.
  • block_vars (dict) – Dict of block variables.
  • gallery_conf (dict) – Contains the configuration of Sphinx-Gallery
Returns:

images_rst – rst code to embed the images in the document.

Return type:

str

Classes

class sphinx_gallery.scrapers.ImagePathIterator(image_path)

Iterate over image paths for a given example.

Parameters:image_path (str) – The template image path.