U
    Áòcc·  ã                   @   sN   d dl Z d dlZd dlZd dlmZ d dlZdejj_dd„ Zdd„ Z	dZ
dS )	é    N)ÚglobZsphinx_gallery_pngc                 K   sÄ   t j |d ¡}ttt j |d¡ƒƒ}ttt j |d¡ƒƒ}|d }tƒ }tƒ }	t||ƒD ]Z\}
}||	krZ|	t|ƒO }	t	|ƒ}t j 
|¡d d }| |¡ t ||¡ t |
|¡ qZt||d ƒS )a<  Scrape Plotly figures for galleries of examples using
    sphinx-gallery.

    Examples should use ``plotly.io.show()`` to display the figure with
    the custom sphinx_gallery renderer.

    Since the sphinx_gallery renderer generates both html and static png
    files, we simply crawl these files and give them the appropriate path.

    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' and 'svg' are supported).

    Returns
    -------
    rst : str
        The ReSTructuredText that will be rendered to HTML containing
        the images.

    Notes
    -----
    Add this function to the image scrapers
    Zsrc_filez*.pngz*.htmlÚimage_path_iteratorr   z.htmlÚsrc_dir)ÚosÚpathÚdirnameÚsortedr   ÚjoinÚlistÚsetÚzipÚnextÚsplitextÚappendÚshutilÚmoveÚ
figure_rst)ÚblockZ
block_varsZgallery_confÚkwargsZexamples_dirZpngsZhtmlsr   Zimage_namesÚseenÚhtmlZpngZthis_image_path_pngZthis_image_path_html© r   úO/var/www/html/project/venv/lib/python3.8/site-packages/plotly/io/_sg_scraper.pyÚplotly_sg_scraper   s    "
r   c                    sX   ‡ fdd„| D ƒ}d}|s|S |d }t j |¡d }t j dt j |¡¡}t| }|S )aÀ  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
        List of strings of the figures' absolute paths.
    sources_dir : str
        absolute path of Sphinx documentation sources

    Returns
    -------
    images_rst : str
        rst code to embed the images in the document
    c                    s*   g | ]"}t j |ˆ ¡ t jd ¡ d ¡‘qS )ú/)r   r   ÚrelpathÚreplaceÚsepÚlstrip)Ú.0Úfigure_path©Úsources_dirr   r   Ú
<listcomp>T   s   ÿzfigure_rst.<locals>.<listcomp>Ú r   é   Zimages)r   r   r   r	   ÚbasenameÚSINGLE_HTML)Zfigure_listr"   Zfigure_pathsZ
images_rstZfigure_nameÚextr    r   r!   r   r   A   s    
þr   z
.. raw:: html
    :file: %s
)Úinspectr   Zplotlyr   r   ÚioZ	renderersÚdefaultr   r   r'   r   r   r   r   Ú<module>   s   
4!