# Path: sphinx_gallery/scrapers.py
# def matplotlib_scraper(block, block_vars, gallery_conf, **kwargs):
#     """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
#     **kwargs : dict
#         Additional keyword arguments to pass to
#         :meth:`~matplotlib.figure.Figure.savefig`, e.g. ``format='svg'``.
#         The ``format`` kwarg in particular is used to set the file extension
#         of the output file (currently only 'png', 'jpg', and 'svg' are
#         supported).
# 
#     Returns
#     -------
#     rst : str
#         The ReSTructuredText that will be rendered to HTML containing
#         the images. This is often produced by :func:`figure_rst`.
#     """
#     matplotlib, plt = _import_matplotlib()
#     from matplotlib.animation import Animation
#     image_path_iterator = block_vars['image_path_iterator']
#     image_rsts = []
#     # Check for srcset hidpi images
#     srcset = gallery_conf.get('image_srcset', [])
#     srcset_mult_facs = [1]  # one is always supplied...
#     for st in srcset:
#         if (len(st) > 0) and (st[-1] == 'x'):
#             # "2x" = "2.0"
#             srcset_mult_facs += [float(st[:-1])]
#         elif st == "":
#             pass
#         else:
#             raise ExtensionError(
#                 f'Invalid value for image_srcset parameter: "{st}". '
#                 'Must be a list of strings with the multiplicative '
#                 'factor followed by an "x".  e.g. ["2.0x", "1.5x"]')
# 
#     # Check for animations
#     anims = list()
#     if gallery_conf.get('matplotlib_animations', False):
#         for ani in block_vars['example_globals'].values():
#             if isinstance(ani, Animation):
#                 anims.append(ani)
#     # Then standard images
#     for fig_num, image_path in zip(plt.get_fignums(), image_path_iterator):
#         image_path = PurePosixPath(image_path)
#         if 'format' in kwargs:
#             image_path = image_path.with_suffix('.' + kwargs['format'])
#         # Set the fig_num figure as the current figure as we can't
#         # save a figure that's not the current figure.
#         fig = plt.figure(fig_num)
#         # Deal with animations
#         cont = False
#         for anim in anims:
#             if anim._fig is fig:
#                 image_rsts.append(_anim_rst(anim,
#                                             str(image_path), gallery_conf))
#                 cont = True
#                 break
#         if cont:
#             continue
#         # get fig titles
#         fig_titles = _matplotlib_fig_titles(fig)
#         to_rgba = matplotlib.colors.colorConverter.to_rgba
#         # shallow copy should be fine here, just want to avoid changing
#         # "kwargs" for subsequent figures processed by the loop
#         these_kwargs = kwargs.copy()
#         for attr in ['facecolor', 'edgecolor']:
#             fig_attr = getattr(fig, 'get_' + attr)()
#             default_attr = matplotlib.rcParams['figure.' + attr]
#             if to_rgba(fig_attr) != to_rgba(default_attr) and \
#                     attr not in kwargs:
#                 these_kwargs[attr] = fig_attr
# 
#         # save the figures, and populate the srcsetpaths
#         try:
#             fig.savefig(image_path, **these_kwargs)
#             dpi0 = matplotlib.rcParams['savefig.dpi']
#             if dpi0 == 'figure':
#                 dpi0 = fig.dpi
#             dpi0 = these_kwargs.get('dpi', dpi0)
#             srcsetpaths = {0: image_path}
# 
#             # save other srcset paths, keyed by multiplication factor:
#             for mult in srcset_mult_facs:
#                 if not (mult == 1):
#                     multst = f'{mult}'.replace('.', '_')
#                     name = f"{image_path.stem}_{multst}x{image_path.suffix}"
#                     hipath = image_path.parent / PurePosixPath(name)
#                     hikwargs = these_kwargs.copy()
#                     hikwargs['dpi'] = mult * dpi0
#                     fig.savefig(hipath, **hikwargs)
#                     srcsetpaths[mult] = hipath
#             srcsetpaths = [srcsetpaths]
#         except Exception:
#             plt.close('all')
#             raise
# 
#         if 'images' in gallery_conf['compress_images']:
#             optipng(str(image_path), gallery_conf['compress_images_args'])
#             for hipath in srcsetpaths[0].items():
#                 optipng(str(hipath), gallery_conf['compress_images_args'])
# 
#         image_rsts.append(
#             figure_rst([image_path], gallery_conf['src_dir'], fig_titles,
#                        srcsetpaths=srcsetpaths))
# 
#     plt.close('all')
#     rst = ''
#     if len(image_rsts) == 1:
#         rst = image_rsts[0]
#     elif len(image_rsts) > 1:
#         image_rsts = [re.sub(r':class: sphx-glr-single-img',
#                              ':class: sphx-glr-multi-img',
#                              image) for image in image_rsts]
#         image_rsts = [HLIST_IMAGE_MATPLOTLIB + indent(image, u' ' * 6)
#                       for image in image_rsts]
#         rst = HLIST_HEADER + ''.join(image_rsts)
#     return rst


import os.path as op
    import matplotlib.pyplot as plt
from sphinx_gallery.scrapers import matplotlib_scraper
from sphinx_gallery.sorting import FileNameSortKey
        from matplotlib.colors import colorConverter
        from matplotlib.colors import colorConverter


class matplotlib_format_scraper(object):

    def __repr__(self):
        return self.__class__.__name__

    def __call__(self, block, block_vars, gallery_conf):
        kwargs = dict()
        if op.basename(block_vars['target_file']) == 'plot_svg.py' and \
                gallery_conf['builder_name'] != 'latex':
            kwargs['format'] = 'svg'

# Path: sphinx_gallery/scrapers.py
# def matplotlib_scraper(block, block_vars, gallery_conf, **kwargs):
#     """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
#     **kwargs : dict
#         Additional keyword arguments to pass to
#         :meth:`~matplotlib.figure.Figure.savefig`, e.g. ``format='svg'``.
#         The ``format`` kwarg in particular is used to set the file extension
#         of the output file (currently only 'png', 'jpg', and 'svg' are
#         supported).
# 
#     Returns
#     -------
#     rst : str
#         The ReSTructuredText that will be rendered to HTML containing
#         the images. This is often produced by :func:`figure_rst`.
#     """
#     matplotlib, plt = _import_matplotlib()
#     from matplotlib.animation import Animation
#     image_path_iterator = block_vars['image_path_iterator']
#     image_rsts = []
#     # Check for srcset hidpi images
#     srcset = gallery_conf.get('image_srcset', [])
#     srcset_mult_facs = [1]  # one is always supplied...
#     for st in srcset:
#         if (len(st) > 0) and (st[-1] == 'x'):
#             # "2x" = "2.0"
#             srcset_mult_facs += [float(st[:-1])]
#         elif st == "":
#             pass
#         else:
#             raise ExtensionError(
#                 f'Invalid value for image_srcset parameter: "{st}". '
#                 'Must be a list of strings with the multiplicative '
#                 'factor followed by an "x".  e.g. ["2.0x", "1.5x"]')
# 
#     # Check for animations
#     anims = list()
#     if gallery_conf.get('matplotlib_animations', False):
#         for ani in block_vars['example_globals'].values():
#             if isinstance(ani, Animation):
#                 anims.append(ani)
#     # Then standard images
#     for fig_num, image_path in zip(plt.get_fignums(), image_path_iterator):
#         image_path = PurePosixPath(image_path)
#         if 'format' in kwargs:
#             image_path = image_path.with_suffix('.' + kwargs['format'])
#         # Set the fig_num figure as the current figure as we can't
#         # save a figure that's not the current figure.
#         fig = plt.figure(fig_num)
#         # Deal with animations
#         cont = False
#         for anim in anims:
#             if anim._fig is fig:
#                 image_rsts.append(_anim_rst(anim,
#                                             str(image_path), gallery_conf))
#                 cont = True
#                 break
#         if cont:
#             continue
#         # get fig titles
#         fig_titles = _matplotlib_fig_titles(fig)
#         to_rgba = matplotlib.colors.colorConverter.to_rgba
#         # shallow copy should be fine here, just want to avoid changing
#         # "kwargs" for subsequent figures processed by the loop
#         these_kwargs = kwargs.copy()
#         for attr in ['facecolor', 'edgecolor']:
#             fig_attr = getattr(fig, 'get_' + attr)()
#             default_attr = matplotlib.rcParams['figure.' + attr]
#             if to_rgba(fig_attr) != to_rgba(default_attr) and \
#                     attr not in kwargs:
#                 these_kwargs[attr] = fig_attr
# 
#         # save the figures, and populate the srcsetpaths
#         try:
#             fig.savefig(image_path, **these_kwargs)
#             dpi0 = matplotlib.rcParams['savefig.dpi']
#             if dpi0 == 'figure':
#                 dpi0 = fig.dpi
#             dpi0 = these_kwargs.get('dpi', dpi0)
#             srcsetpaths = {0: image_path}
# 
#             # save other srcset paths, keyed by multiplication factor:
#             for mult in srcset_mult_facs:
#                 if not (mult == 1):
#                     multst = f'{mult}'.replace('.', '_')
#                     name = f"{image_path.stem}_{multst}x{image_path.suffix}"
#                     hipath = image_path.parent / PurePosixPath(name)
#                     hikwargs = these_kwargs.copy()
#                     hikwargs['dpi'] = mult * dpi0
#                     fig.savefig(hipath, **hikwargs)
#                     srcsetpaths[mult] = hipath
#             srcsetpaths = [srcsetpaths]
#         except Exception:
#             plt.close('all')
#             raise
# 
#         if 'images' in gallery_conf['compress_images']:
#             optipng(str(image_path), gallery_conf['compress_images_args'])
#             for hipath in srcsetpaths[0].items():
#                 optipng(str(hipath), gallery_conf['compress_images_args'])
# 
#         image_rsts.append(
#             figure_rst([image_path], gallery_conf['src_dir'], fig_titles,
#                        srcsetpaths=srcsetpaths))
# 
#     plt.close('all')
#     rst = ''
#     if len(image_rsts) == 1:
#         rst = image_rsts[0]
#     elif len(image_rsts) > 1:
#         image_rsts = [re.sub(r':class: sphx-glr-single-img',
#                              ':class: sphx-glr-multi-img',
#                              image) for image in image_rsts]
#         image_rsts = [HLIST_IMAGE_MATPLOTLIB + indent(image, u' ' * 6)
#                       for image in image_rsts]
#         rst = HLIST_HEADER + ''.join(image_rsts)
#     return rst


# Path: sphinx_gallery/tests/tinybuild/conf.py
import os.path as op
    import matplotlib.pyplot as plt
from sphinx_gallery.scrapers import matplotlib_scraper
from sphinx_gallery.sorting import FileNameSortKey
        from matplotlib.colors import colorConverter
        from matplotlib.colors import colorConverter



class matplotlib_format_scraper(object):

    def __repr__(self):
        return self.__class__.__name__

    def __call__(self, block, block_vars, gallery_conf):
        kwargs = dict()
        if op.basename(block_vars['target_file']) == 'plot_svg.py' and \
                gallery_conf['builder_name'] != 'latex':
            kwargs['format'] = 'svg'

        return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)