prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Error when using two image scrappers together
  ### Introduction to the problem 
  I am trying to move the current Jupyter Notebook examples of the [poliastro project](https://github.com/poliastro/poliastro) to an [Sphinx-Gallery](https://github.com/sphinx-gallery/sphinx-gallery) set. Since we are making use of **plotly figures** we need to **capture them** as output figures and therefore, make use of the **plotly image scrapper**. We also need to capture `matplotlib` figures, so this image scrapper must be also added to the `conf.py` file.
  
  #### How to reproduce this issue :beetle: 
  
  If you download the [official example repository](https://github.com/plotly/plotly-sphinx-gallery)  from @emmanuelle for achieving this task and you add the following [simple Python file](https://gist.github.com/jorgepiloto/db807a7ee3a0bcfbaea38fc9cd7ac95e) in the `examples/` directory for plotting a sinusoidal wave with `matplotlib` and error is raised:
  
  ```bash
  generating gallery...
  generating gallery for auto_examples... [ 25%] plot_sin.py                                                                                                                                       
  Exception occurred:
    File "/home/lobo/anaconda3/envs/poliastro/lib/python3.7/site-packages/plotly/io/_sg_scraper.py", line 91, in figure_rst
      figure_name = figure_paths[0]
  IndexError: list index out of range
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `packages/python/plotly/plotly/io/_sg_scraper.py`
  Content:
  ```
  1 # This module defines an image scraper for sphinx-gallery
  2 # https://sphinx-gallery.github.io/
  3 # which can be used by projects using plotly in their documentation.
  4 import inspect, os
  5 
  6 import plotly
  7 from glob import glob
  8 import shutil
  9 
  10 plotly.io.renderers.default = "sphinx_gallery"
  11 
  12 
  13 def plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs):
  14     """Scrape Plotly figures for galleries of examples using
  15     sphinx-gallery.
  16 
  17     Examples should use ``plotly.io.show()`` to display the figure with
  18     the custom sphinx_gallery renderer.
  19 
  20     Since the sphinx_gallery renderer generates both html and static png
  21     files, we simply crawl these files and give them the appropriate path.
  22 
  23     Parameters
  24     ----------
  25     block : tuple
  26         A tuple containing the (label, content, line_number) of the block.
  27     block_vars : dict
  28         Dict of block variables.
  29     gallery_conf : dict
  30         Contains the configuration of Sphinx-Gallery
  31     **kwargs : dict
  32         Additional keyword arguments to pass to
  33         :meth:`~matplotlib.figure.Figure.savefig`, e.g. ``format='svg'``.
  34         The ``format`` kwarg in particular is used to set the file extension
  35         of the output file (currently only 'png' and 'svg' are supported).
  36 
  37     Returns
  38     -------
  39     rst : str
  40         The ReSTructuredText that will be rendered to HTML containing
  41         the images.
  42 
  43     Notes
  44     -----
  45     Add this function to the image scrapers 
  46     """
  47     examples_dirs = gallery_conf["examples_dirs"]
  48     if isinstance(examples_dirs, (list, tuple)):
  49         examples_dirs = examples_dirs[0]
  50     pngs = sorted(glob(os.path.join(examples_dirs, "*.png")))
  51     htmls = sorted(glob(os.path.join(examples_dirs, "*.html")))
  52     image_path_iterator = block_vars["image_path_iterator"]
  53     image_names = list()
  54     seen = set()
  55     for html, png in zip(htmls, pngs):
  56         if png not in seen:
  57             seen |= set(png)
  58             this_image_path_png = next(image_path_iterator)
  59             this_image_path_html = os.path.splitext(this_image_path_png)[0] + ".html"
  60             image_names.append(this_image_path_html)
  61             shutil.move(png, this_image_path_png)
  62             shutil.move(html, this_image_path_html)
  63     # Use the `figure_rst` helper function to generate rST for image files
  64     return figure_rst(image_names, gallery_conf["src_dir"])
  65 
  66 
  67 def figure_rst(figure_list, sources_dir):
  68     """Generate RST for a list of PNG filenames.
  69 
  70     Depending on whether we have one or more figures, we use a
  71     single rst call to 'image' or a horizontal list.
  72 
  73     Parameters
  74     ----------
  75     figure_list : list
  76         List of strings of the figures' absolute paths.
  77     sources_dir : str
  78         absolute path of Sphinx documentation sources
  79 
  80     Returns
  81     -------
  82     images_rst : str
  83         rst code to embed the images in the document
  84     """
  85 
  86     figure_paths = [
  87         os.path.relpath(figure_path, sources_dir).replace(os.sep, "/").lstrip("/")
  88         for figure_path in figure_list
  89     ]
  90     images_rst = ""
  91     figure_name = figure_paths[0]
  92     ext = os.path.splitext(figure_name)[1]
  93     figure_path = os.path.join("images", os.path.basename(figure_name))
  94     images_rst = SINGLE_HTML % figure_path
  95     return images_rst
  96 
  97 
  98 SINGLE_HTML = """
  99 .. raw:: html
  100     :file: %s
  101 """
  102
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/packages/python/plotly/plotly/io/_sg_scraper.py b/packages/python/plotly/plotly/io/_sg_scraper.py
  --- a/packages/python/plotly/plotly/io/_sg_scraper.py
  +++ b/packages/python/plotly/plotly/io/_sg_scraper.py
  @@ -88,6 +88,8 @@
           for figure_path in figure_list
       ]
       images_rst = ""
  +    if not figure_paths:
  +        return images_rst
       figure_name = figure_paths[0]
       ext = os.path.splitext(figure_name)[1]
       figure_path = os.path.join("images", os.path.basename(figure_name))
  
verification_info: {"golden_diff": "diff --git a/packages/python/plotly/plotly/io/_sg_scraper.py b/packages/python/plotly/plotly/io/_sg_scraper.py\n--- a/packages/python/plotly/plotly/io/_sg_scraper.py\n+++ b/packages/python/plotly/plotly/io/_sg_scraper.py\n@@ -88,6 +88,8 @@\n         for figure_path in figure_list\n     ]\n     images_rst = \"\"\n+    if not figure_paths:\n+        return images_rst\n     figure_name = figure_paths[0]\n     ext = os.path.splitext(figure_name)[1]\n     figure_path = os.path.join(\"images\", os.path.basename(figure_name))\n", "issue": "Error when using two image scrappers together\n### Introduction to the problem \r\nI am trying to move the current Jupyter Notebook examples of the [poliastro project](https://github.com/poliastro/poliastro) to an [Sphinx-Gallery](https://github.com/sphinx-gallery/sphinx-gallery) set. Since we are making use of **plotly figures** we need to **capture them** as output figures and therefore, make use of the **plotly image scrapper**. We also need to capture `matplotlib` figures, so this image scrapper must be also added to the `conf.py` file.\r\n\r\n#### How to reproduce this issue :beetle: \r\n\r\nIf you download the [official example repository](https://github.com/plotly/plotly-sphinx-gallery)  from @emmanuelle for achieving this task and you add the following [simple Python file](https://gist.github.com/jorgepiloto/db807a7ee3a0bcfbaea38fc9cd7ac95e) in the `examples/` directory for plotting a sinusoidal wave with `matplotlib` and error is raised:\r\n\r\n```bash\r\ngenerating gallery...\r\ngenerating gallery for auto_examples... [ 25%] plot_sin.py                                                                                                                                       \r\nException occurred:\r\n  File \"/home/lobo/anaconda3/envs/poliastro/lib/python3.7/site-packages/plotly/io/_sg_scraper.py\", line 91, in figure_rst\r\n    figure_name = figure_paths[0]\r\nIndexError: list index out of range\r\n```\n", "before_files": [{"content": "# This module defines an image scraper for sphinx-gallery\n# https://sphinx-gallery.github.io/\n# which can be used by projects using plotly in their documentation.\nimport inspect, os\n\nimport plotly\nfrom glob import glob\nimport shutil\n\nplotly.io.renderers.default = \"sphinx_gallery\"\n\n\ndef plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs):\n    \"\"\"Scrape Plotly figures for galleries of examples using\n    sphinx-gallery.\n\n    Examples should use ``plotly.io.show()`` to display the figure with\n    the custom sphinx_gallery renderer.\n\n    Since the sphinx_gallery renderer generates both html and static png\n    files, we simply crawl these files and give them the appropriate path.\n\n    Parameters\n    ----------\n    block : tuple\n        A tuple containing the (label, content, line_number) of the block.\n    block_vars : dict\n        Dict of block variables.\n    gallery_conf : dict\n        Contains the configuration of Sphinx-Gallery\n    **kwargs : dict\n        Additional keyword arguments to pass to\n        :meth:`~matplotlib.figure.Figure.savefig`, e.g. ``format='svg'``.\n        The ``format`` kwarg in particular is used to set the file extension\n        of the output file (currently only 'png' and 'svg' are supported).\n\n    Returns\n    -------\n    rst : str\n        The ReSTructuredText that will be rendered to HTML containing\n        the images.\n\n    Notes\n    -----\n    Add this function to the image scrapers \n    \"\"\"\n    examples_dirs = gallery_conf[\"examples_dirs\"]\n    if isinstance(examples_dirs, (list, tuple)):\n        examples_dirs = examples_dirs[0]\n    pngs = sorted(glob(os.path.join(examples_dirs, \"*.png\")))\n    htmls = sorted(glob(os.path.join(examples_dirs, \"*.html\")))\n    image_path_iterator = block_vars[\"image_path_iterator\"]\n    image_names = list()\n    seen = set()\n    for html, png in zip(htmls, pngs):\n        if png not in seen:\n            seen |= set(png)\n            this_image_path_png = next(image_path_iterator)\n            this_image_path_html = os.path.splitext(this_image_path_png)[0] + \".html\"\n            image_names.append(this_image_path_html)\n            shutil.move(png, this_image_path_png)\n            shutil.move(html, this_image_path_html)\n    # Use the `figure_rst` helper function to generate rST for image files\n    return figure_rst(image_names, gallery_conf[\"src_dir\"])\n\n\ndef figure_rst(figure_list, sources_dir):\n    \"\"\"Generate RST for a list of PNG filenames.\n\n    Depending on whether we have one or more figures, we use a\n    single rst call to 'image' or a horizontal list.\n\n    Parameters\n    ----------\n    figure_list : list\n        List of strings of the figures' absolute paths.\n    sources_dir : str\n        absolute path of Sphinx documentation sources\n\n    Returns\n    -------\n    images_rst : str\n        rst code to embed the images in the document\n    \"\"\"\n\n    figure_paths = [\n        os.path.relpath(figure_path, sources_dir).replace(os.sep, \"/\").lstrip(\"/\")\n        for figure_path in figure_list\n    ]\n    images_rst = \"\"\n    figure_name = figure_paths[0]\n    ext = os.path.splitext(figure_name)[1]\n    figure_path = os.path.join(\"images\", os.path.basename(figure_name))\n    images_rst = SINGLE_HTML % figure_path\n    return images_rst\n\n\nSINGLE_HTML = \"\"\"\n.. raw:: html\n    :file: %s\n\"\"\"\n", "path": "packages/python/plotly/plotly/io/_sg_scraper.py"}], "after_files": [{"content": "# This module defines an image scraper for sphinx-gallery\n# https://sphinx-gallery.github.io/\n# which can be used by projects using plotly in their documentation.\nimport inspect, os\n\nimport plotly\nfrom glob import glob\nimport shutil\n\nplotly.io.renderers.default = \"sphinx_gallery\"\n\n\ndef plotly_sg_scraper(block, block_vars, gallery_conf, **kwargs):\n    \"\"\"Scrape Plotly figures for galleries of examples using\n    sphinx-gallery.\n\n    Examples should use ``plotly.io.show()`` to display the figure with\n    the custom sphinx_gallery renderer.\n\n    Since the sphinx_gallery renderer generates both html and static png\n    files, we simply crawl these files and give them the appropriate path.\n\n    Parameters\n    ----------\n    block : tuple\n        A tuple containing the (label, content, line_number) of the block.\n    block_vars : dict\n        Dict of block variables.\n    gallery_conf : dict\n        Contains the configuration of Sphinx-Gallery\n    **kwargs : dict\n        Additional keyword arguments to pass to\n        :meth:`~matplotlib.figure.Figure.savefig`, e.g. ``format='svg'``.\n        The ``format`` kwarg in particular is used to set the file extension\n        of the output file (currently only 'png' and 'svg' are supported).\n\n    Returns\n    -------\n    rst : str\n        The ReSTructuredText that will be rendered to HTML containing\n        the images.\n\n    Notes\n    -----\n    Add this function to the image scrapers \n    \"\"\"\n    examples_dirs = gallery_conf[\"examples_dirs\"]\n    if isinstance(examples_dirs, (list, tuple)):\n        examples_dirs = examples_dirs[0]\n    pngs = sorted(glob(os.path.join(examples_dirs, \"*.png\")))\n    htmls = sorted(glob(os.path.join(examples_dirs, \"*.html\")))\n    image_path_iterator = block_vars[\"image_path_iterator\"]\n    image_names = list()\n    seen = set()\n    for html, png in zip(htmls, pngs):\n        if png not in seen:\n            seen |= set(png)\n            this_image_path_png = next(image_path_iterator)\n            this_image_path_html = os.path.splitext(this_image_path_png)[0] + \".html\"\n            image_names.append(this_image_path_html)\n            shutil.move(png, this_image_path_png)\n            shutil.move(html, this_image_path_html)\n    # Use the `figure_rst` helper function to generate rST for image files\n    return figure_rst(image_names, gallery_conf[\"src_dir\"])\n\n\ndef figure_rst(figure_list, sources_dir):\n    \"\"\"Generate RST for a list of PNG filenames.\n\n    Depending on whether we have one or more figures, we use a\n    single rst call to 'image' or a horizontal list.\n\n    Parameters\n    ----------\n    figure_list : list\n        List of strings of the figures' absolute paths.\n    sources_dir : str\n        absolute path of Sphinx documentation sources\n\n    Returns\n    -------\n    images_rst : str\n        rst code to embed the images in the document\n    \"\"\"\n\n    figure_paths = [\n        os.path.relpath(figure_path, sources_dir).replace(os.sep, \"/\").lstrip(\"/\")\n        for figure_path in figure_list\n    ]\n    images_rst = \"\"\n    if not figure_paths:\n        return images_rst\n    figure_name = figure_paths[0]\n    ext = os.path.splitext(figure_name)[1]\n    figure_path = os.path.join(\"images\", os.path.basename(figure_name))\n    images_rst = SINGLE_HTML % figure_path\n    return images_rst\n\n\nSINGLE_HTML = \"\"\"\n.. raw:: html\n    :file: %s\n\"\"\"\n", "path": "packages/python/plotly/plotly/io/_sg_scraper.py"}]}