# Path: sphinx_gallery/scrapers.py
# def figure_rst(figure_list, sources_dir, fig_titles='', srcsetpaths=None):
#     """Generate RST for a list of image 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
#         List of strings of the figures' absolute paths.
#     sources_dir : str
#         absolute path of Sphinx documentation sources
#     fig_titles : str
#         Titles of figures, empty string if no titles found. Currently
#         only supported for matplotlib figures, default = ''.
#     srcsetpaths : list or None
#         List of dictionaries containing absolute paths.  If
#         empty, then srcset field is populated with the figure path.
#         (see ``image_srcset`` configuration option).  Otherwise,
#         each dict is of the form
#         {0: /images/image.png, 2.0: /images/image_2_0x.png}
#         where the key is the multiplication factor and the contents
#         the path to the image created above.
# 
#     Returns
#     -------
#     images_rst : str
#         rst code to embed the images in the document
# 
#     The rst code will have a custom ``image-sg`` directive that allows
#     multiple resolution images to be served e.g.:
#     ``:srcset: /plot_types/imgs/img_001.png,
#       /plot_types/imgs/img_2_0x.png 2.0x``
# 
#     """
# 
#     if srcsetpaths is None:
#         # this should never happen, but figure_rst is public, so
#         # this has to be a kwarg...
#         srcsetpaths = [{0: fl} for fl in figure_list]
# 
#     figure_paths = [os.path.relpath(figure_path, sources_dir)
#                     .replace(os.sep, '/').lstrip('/')
#                     for figure_path in figure_list]
# 
#     # Get alt text
#     alt = ''
#     if fig_titles:
#         alt = fig_titles
#     elif figure_list:
#         file_name = os.path.split(figure_list[0])[1]
#         # remove ext & 'sphx_glr_' from start & n#'s from end
#         file_name_noext = os.path.splitext(file_name)[0][9:-4]
#         # replace - & _ with \s
#         file_name_final = re.sub(r'[-,_]', ' ', file_name_noext)
#         alt = file_name_final
#     alt = _single_line_sanitize(alt)
# 
#     images_rst = ""
#     if len(figure_paths) == 1:
#         figure_name = figure_paths[0]
#         hinames = srcsetpaths[0]
#         srcset = _get_srcset_st(sources_dir, hinames)
#         images_rst = SG_IMAGE % (figure_name, alt, srcset)
# 
#     elif len(figure_paths) > 1:
#         images_rst = HLIST_HEADER
#         for nn, figure_name in enumerate(figure_paths):
#             hinames = srcsetpaths[nn]
#             srcset = _get_srcset_st(sources_dir, hinames)
# 
#             images_rst += (HLIST_SG_TEMPLATE %
#                            (figure_name, alt, srcset))
# 
#     return images_rst
# 
# def clean_modules(gallery_conf, fname, when):
#     """Remove, unload, or reset modules.
# 
#     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 or None
#         The example being run. Will be None when this is called entering
#         a directory of examples to be built.
#     when : str
#         Whether this module is run before or after examples.
# 
#         This parameter is only forwarded when the callables accept 3
#         parameters.
#     """
#     for reset_module in gallery_conf['reset_modules']:
# 
#         sig = inspect.signature(reset_module)
#         if len(sig.parameters) == 3:
#             third_param = list(sig.parameters.keys())[2]
#             if third_param != 'when':
#                 raise ValueError(f"3rd parameter in {reset_module.__name__} "
#                                  "function signature must be 'when', "
#                                  f"got {third_param}")
#             reset_module(gallery_conf, fname, when=when)
#         else:
#             reset_module(gallery_conf, fname)


from sphinx_gallery.sorting import ExplicitOrder
from sphinx_gallery.scrapers import figure_rst, clean_modules
"""
Testing backreferences
----------------------

This example runs after plot_future_statements.py (alphabetical ordering within
subsection) and should be unaffected by the __future__ import in
plot_future_statements.py. We should eventually update this script to actually
test this... we require Python 3 nowadays so the __future__ statements there
don't do anything. So for now let's repurpose this to look at some
backreferences. We should probably also change the filename in another PR!
"""
# sphinx_gallery_thumbnail_path = '_static_nonstandard/demo.png'


ExplicitOrder([])  # must actually be used to become a backref target!

assert 3 / 2 == 1.5
assert figure_rst([], '') == ''

# Path: sphinx_gallery/scrapers.py
# def figure_rst(figure_list, sources_dir, fig_titles='', srcsetpaths=None):
#     """Generate RST for a list of image 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
#         List of strings of the figures' absolute paths.
#     sources_dir : str
#         absolute path of Sphinx documentation sources
#     fig_titles : str
#         Titles of figures, empty string if no titles found. Currently
#         only supported for matplotlib figures, default = ''.
#     srcsetpaths : list or None
#         List of dictionaries containing absolute paths.  If
#         empty, then srcset field is populated with the figure path.
#         (see ``image_srcset`` configuration option).  Otherwise,
#         each dict is of the form
#         {0: /images/image.png, 2.0: /images/image_2_0x.png}
#         where the key is the multiplication factor and the contents
#         the path to the image created above.
# 
#     Returns
#     -------
#     images_rst : str
#         rst code to embed the images in the document
# 
#     The rst code will have a custom ``image-sg`` directive that allows
#     multiple resolution images to be served e.g.:
#     ``:srcset: /plot_types/imgs/img_001.png,
#       /plot_types/imgs/img_2_0x.png 2.0x``
# 
#     """
# 
#     if srcsetpaths is None:
#         # this should never happen, but figure_rst is public, so
#         # this has to be a kwarg...
#         srcsetpaths = [{0: fl} for fl in figure_list]
# 
#     figure_paths = [os.path.relpath(figure_path, sources_dir)
#                     .replace(os.sep, '/').lstrip('/')
#                     for figure_path in figure_list]
# 
#     # Get alt text
#     alt = ''
#     if fig_titles:
#         alt = fig_titles
#     elif figure_list:
#         file_name = os.path.split(figure_list[0])[1]
#         # remove ext & 'sphx_glr_' from start & n#'s from end
#         file_name_noext = os.path.splitext(file_name)[0][9:-4]
#         # replace - & _ with \s
#         file_name_final = re.sub(r'[-,_]', ' ', file_name_noext)
#         alt = file_name_final
#     alt = _single_line_sanitize(alt)
# 
#     images_rst = ""
#     if len(figure_paths) == 1:
#         figure_name = figure_paths[0]
#         hinames = srcsetpaths[0]
#         srcset = _get_srcset_st(sources_dir, hinames)
#         images_rst = SG_IMAGE % (figure_name, alt, srcset)
# 
#     elif len(figure_paths) > 1:
#         images_rst = HLIST_HEADER
#         for nn, figure_name in enumerate(figure_paths):
#             hinames = srcsetpaths[nn]
#             srcset = _get_srcset_st(sources_dir, hinames)
# 
#             images_rst += (HLIST_SG_TEMPLATE %
#                            (figure_name, alt, srcset))
# 
#     return images_rst
# 
# def clean_modules(gallery_conf, fname, when):
#     """Remove, unload, or reset modules.
# 
#     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 or None
#         The example being run. Will be None when this is called entering
#         a directory of examples to be built.
#     when : str
#         Whether this module is run before or after examples.
# 
#         This parameter is only forwarded when the callables accept 3
#         parameters.
#     """
#     for reset_module in gallery_conf['reset_modules']:
# 
#         sig = inspect.signature(reset_module)
#         if len(sig.parameters) == 3:
#             third_param = list(sig.parameters.keys())[2]
#             if third_param != 'when':
#                 raise ValueError(f"3rd parameter in {reset_module.__name__} "
#                                  "function signature must be 'when', "
#                                  f"got {third_param}")
#             reset_module(gallery_conf, fname, when=when)
#         else:
#             reset_module(gallery_conf, fname)


# Path: sphinx_gallery/tests/tinybuild/examples/plot_second_future_imports.py
from sphinx_gallery.sorting import ExplicitOrder
from sphinx_gallery.scrapers import figure_rst, clean_modules

"""
Testing backreferences
----------------------

This example runs after plot_future_statements.py (alphabetical ordering within
subsection) and should be unaffected by the __future__ import in
plot_future_statements.py. We should eventually update this script to actually
test this... we require Python 3 nowadays so the __future__ statements there
don't do anything. So for now let's repurpose this to look at some
backreferences. We should probably also change the filename in another PR!
"""
# sphinx_gallery_thumbnail_path = '_static_nonstandard/demo.png'


ExplicitOrder([])  # must actually be used to become a backref target!

assert 3 / 2 == 1.5
assert figure_rst([], '') == ''

assert clean_modules(dict(reset_modules=[]), '', 'before') is None