
    -Ph              	       <   d Z ddlZddlZddlZddlZddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZmZ ddlZdd	lmZ dd
lmZmZ ddlmZmZmZmZ ddlmZ  ddlm!Z! ddl"m#Z# ddl$m%Z%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZI dZJ G d d          ZKi d ej        ejL                  dz   ddd ejM        N                    d!d"          d#d$hd%i d&d$hd' eK            d(dd)d*d+dd,d-d.dd/d0d1 eO            d2i d3d4d5d6i d7d8d9d:d;d<d=d<d>d?d<id@i dAg dBg dCd<dD eO            dEdFdGddH ejP        dI          du dJi dKi dLd<dMdNi dOd0dPdQdRdSdTddUddVd<dWd<dXd<dYd<dZd:d[d6d\d]d^id_d:d`eJdad<dbg dcdd<d: eO            ddd<d6d<deZQejR        jS        T                    df          ZUdg ZVdh ZW	 	 	 ddjZXdk ZY	 	 ddlZZdm Z[dn Z\do Z]dp Z^ddqZ_ddrZ`ds Zadt Zbdu Zcdv Zddw Zedx ZfdyZgegdzz   Zhd{ Zid| Zjd}d~dZkd Zld Zmd Zn eoddddd          Zpd Zqd Zrd Zsd Ztd Zud Zvd Zwd Zxd ZyddZzd Z{d Z|d Z}d Z~dS )zSphinx-Gallery Generator.

Attaches Sphinx-Gallery to Sphinx in order to generate the galleries
when building the documentation.
    N)datetime	timedelta)get_close_matches)chain)Pathindent)escape	quoteattr)nodes)ConfigErrorExtensionError)blueboldpurplered   )__version__)glr_path_static)_finalize_backreferences)ImageSgMiniGalleryimagesg_addnode)embed_code_links)generate_zipfiles)SPHX_GLR_SIG_get_call_memory_and_base_get_callables_get_gallery_headergenerate_dir_rst)check_binder_confcheck_jupyterlite_confcopy_binder_filescreate_jupyterlite_contents!post_configure_jupyterlite_sphinx pre_configure_jupyterlite_sphinx)ExampleRecommender_write_recommendations)_import_matplotlib)ExplicitOrder)	_collect_gallery_files_combine_backreferences_format_toctree_has_graphviz_has_optipng_has_pypandoc
_read_json_replace_md5_write_json)
sg_galleryzsg_gallery-binderzsg_gallery-dataframezsg_gallery-rendered-htmlc                       e Zd ZdZd Zd ZdS )DefaultResetArgvz?Provides default 'reset_argv' callable that returns empty list.c                     dS )Nr6    )selfs    Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/gen_gallery.py__repr__zDefaultResetArgv.__repr__I   s    !!    c                     g S )zReturn empty list.r8   )r9   gallery_confscript_varss      r:   __call__zDefaultResetArgv.__call__L   s    	r<   N)__name__
__module____qualname____doc__r;   r@   r8   r<   r:   r6   r6   F   s8        II" " "    r<   r6   filename_patternplotignore_patternz__init__\.pyexamples_dirsz..examplesexample_extensions.pyfiletype_parsersnotebook_extensions
reset_argvsubsection_orderwithin_subsection_orderNumberOfCodeLinesSortKeyminigallery_sort_ordergallery_dirsauto_examplesbackreferences_dir
doc_moduler8   exclude_implicit_docreference_urlcapture_repr)_repr_html_r;   ignore_repr_types plot_galleryTruedownload_all_examplesTabort_on_example_errorFonly_warn_on_example_errorrecommenderenablefailing_examplespassing_examplesstale_examplesrun_stale_examplesexpected_failing_examplesthumbnail_size)i  i  min_reported_timewrite_computation_timesSOURCE_DATE_EPOCHbinderjupyterlitepromote_jupyter_magicimage_scrapers)
matplotlibcompress_imagesreset_modules)rq   seabornreset_modules_orderbeforefirst_notebook_celllast_notebook_cellnotebook_imagespypandocremove_config_commentsshow_memoryshow_signaturejunit	log_levelbackreference_missingwarninginspect_global_variablescssmatplotlib_animationsimage_srcsetdefault_thumb_filez.*__.*__)line_numbersnested_sectionsprefer_full_moduleapi_usage_ignoreshow_api_usagecopyfile_regexparallelzsphinx-galleryc                     t          | t                    r!	 t          |           } n# t          $ r Y nw xY wt	          |           S )zHEvaluate bool only configs, to allow setting via -D on the command line.)
isinstancestreval	TypeErrorbool)xs    r:   
_bool_evalr      sQ    !S 	QAA 	 	 	D	77Ns   ' 
44c                     | d         r:t          j        d                    t          | d                                       nd}|| d<   dS )zgUpdate gallery config exclude_implicit_doc.

    This is separate function for better testability.
    rW   |Fexclude_implicit_doc_regexN)recompilejoinsorted)r>   exclude_regexs     r:   )_update_gallery_conf_exclude_implicit_docr      sV     ./	
388F<0F#GHHIIJJJ 
 2?L-...r<   htmlc                 r    |                      |           |                      |           || d<   || d<   d S )N)r]   )r`   src_dirbuilder_nameupdate)sphinx_gallery_confr   r]   r`   r   s        r:   #_update_gallery_conf_builder_initedr      sO     L9996LMMM%,	"*6'''r<   c                    t          |           }t          t          |          t          |          z
            }|r|rd}|D ]j}t          ||d          }|t          |          z  }t	          |          dk    r|d|d         dz  }nt	          |          dk    r	|d|dz  }|d	z  }kt          |                                          d
S d
S )zCCheck SG config keys, optionally raising if any extra keys present.z'Unknown key(s) in sphinx_gallery_conf:
gQ?)cutoffr   z, did you mean r   ?z, did you mean one of 
N)r   setr   reprlenr   strip)r>   r   
check_keysoptions
extra_keysmsgkeys          r:   _check_extra_config_keysr      s    \""G/003w<<?@@J 
'j 
'8 	 	C'WTBBBG499C7||q  88888W!!<<<<<4KCC#))++&&&
' 
' 
' 
'r<   c                 L   | |         }t          ||          s|r#|!|rt          |t                    r|g| |<   dS dS d}t          |t                    r|f}d |D             }|rdnd}t          |          j        }	|                    ||||	          }t          |          )zFCheck config type, optionally converting str to list or allowing None.NzE'{conf_key}' config allowed types: {types}{or_none}. Got {conf_type}.c                     g | ]	}|j         
S r8   )rA   ).0ts     r:   
<listcomp>z&_check_config_type.<locals>.<listcomp>   s    ++++++r<   z or Noner\   )conf_keytypesor_none	conf_type)r   r   typerA   formatr   )
r>   r   r   str_to_list
allow_none
conf_valuer   	str_typesr   r   s
             r:   _check_config_typer      s     h'J*e$$  
8J 	*c** 6*4X&F
QC% ++U+++I&.jjBGZ  )I
**	   C c

r<   c                 j   t          | dt          t          fd           t                      }| d         D ]b}t	          |t
                    r|dd         dk    st          d|d          |                    t          |dd                              c|d	hz  }g t          |          | d<   dS )
z?Check `_check_image_srcset`, convert to float and removing '1'.r   Tr   Nr   z*Invalid value for image_srcset parameter: ze. Must be a list of strings with the multiplicative factor followed by an "x".  e.g. ["2.0x", "1.5x"]r   )
r   listtupler   r   r   r   addfloatr   )r>   srcset_mult_facssts      r:   _check_image_srcsetr      s    |^dE]PTUUUUuu>* - -2s## 	2333DR D D D   	U2crc7^^,,,,#>V,<%=%=#>L   r<   c                 .   t          | dt          t          t          fd           | d         t                    d}t                      }t	                    D ]I\  }}||vr@|                    d          r|                    |           4t          d| d|          Jfd|d	d	d
         D             }t                    r>t                      s0t                              dd                                         d| d<   || d<   d	S )z7Check `compress_images`, getting any command line args.rr   Tr   )images
thumbnails-z.All entries in compress_images must be one of z1 or a command-line switch starting with "-", got c                 :    g | ]}                     |          S r8   )pop)r   prr   s     r:   r   z*_check_compress_images.<locals>.<listcomp>  s'    GGGqO//22GGGr<   Nr   z8optipng binaries not found, PNG %s will not be optimizedz and r8   compress_images_args)r   r   r   r   	enumerate
startswithappendr   r   r/   loggerr   r   )r>   allowed_valuespopskikindr   rr   s         @r:   _check_compress_imagesr      sd   	eT	    ##45O?++O-N66Do.. 	 	D~%%s## B3!3 3*.3 3  	 & HGGGD2JGGG
? LNN FLL))	
 	
 	
 &5L"#+?L'(((r<   c                    | d         }t          |t                    r|f}d}t          |          dv rt          |d         x}t                    st          d|          t          |          dk    rq|d         }|gt          |t                    st          d          |dvr?|=	 |                    d	           n&# t          $ r}t          d
| d          |d}~ww xY w||f| d<   dS )z%Check `matplotlib_animations` config.r   N)r      r   zS'matplotlib_animations' must be a single bool or (enabled: bool, format: str), not r   z<'matplotlib_animations' file format must be a string or None)html5jshtmlzsphinxcontrib.videoz/'matplotlib_animations' specifies file format: z0; this requires the sphinxcontrib.video package.)r   r   r   r   r   setup_extensionr   )r>   app
animationsfmtenabledes         r:   _check_matplotlib_animationsr   "  sZ   56J*d##  ]

OOv%%*
15MWt*T*T%@1;@ @
 
 	

 :m?c3'' !R   ---?!++,ABBBB) ! ! !)Nc N N N   !!! .5cNL()))s   +C 
C$CC$c                 ,   | d         }t          | dt          t          f           |du rt                      n|| d<   t                      \  }}t	          | d         t                    r"| t
                              d           d| d<   nQt	          | d         t                    rt
                              d|           nt
                              d           t	          |t                    r!d}|D ]}||vrt          d	| d
| d          dS dS )zCheck `pypandoc` config.rz   TNzg'pypandoc' not available. Using Sphinx-Gallery to convert rst text blocks to markdown for .ipynb files.FzPUsing pandoc version: %s to convert rst text blocks to markdown for .ipynb fileszMUsing Sphinx-Gallery to convert rst text blocks to markdown for .ipynb files.)
extra_argsfiltersz2'pypandoc' only accepts the following key values: , got: .)	r   dictr   r0   r   r   r   infor   )r>   rz   has_pypandocversionaccepted_keysr   s         r:   _check_pypandoc_configr   E  sl   J'H|Z$>>>)1T)9)9tvvvxL)OOL',z*D11 
l6JD	
 	
 	
 $)Z  	L,d	3	3 

(	
 	
 	
 	
 	)	
 	
 	
 (D!! 1 	 	C-''!<,< <58< < <   ( 	 	r<   c                    t          j        t                    }t          || |           |                    |            dD ]}t          ||                   ||<   d|d<   ddi|d<   |U|j        d         r|j        d         |d<   |j        d         |d<   t          |d         t                    r|d         di|d<   t          |dt          t          fd	
           g d}|d         D ]}||vrt          d| d|           t          |dt                     t          |dt          t          f           |d         d	u r
|j        |d<   |d         dk    rd|d<   |d         r#	 ddl}n# t"          $ r t%          d          w xY wt'          |d	           dD ]!}|dk    r	||         t)          ||           "	 t+                       n# t,          t$          f$ r Y nw xY wt/          |           t1          |           t3          ||           t)          |d           t          |dt                     |d         dvrt          d|d                   d}|D ]}	t          ||	t          d	           t5          |           i |d<   t          |dt          t6          j        fd	           |d         }
t          |
t6          j                  rt          |
          |d<   t;          |d                   |d<   t=          |d          |          |d <   t          |d!t          t          fd	
           |d!         D ]?}|t>          vrt          d"|d#t>                    ||                     |d$z              @t          |d%t                     t          |d&         t                    s$|d&         d'k    rt          d(|d&                    t)          |d)d*           tC          |           |S )+zEHandle user configs, update default gallery configs and check values.)ro   rg   r\   default_rolez.rstrestructuredtextsource_suffixNrY   Tr   )r;   __str__rZ   z-All entries in 'capture_repr' must be one of r   r[   r   r   Fr   z7joblib must be importable when parallel mode is enabledr   )rp   rN   rR   rs   rR   rs   ru   )rv   afterbothz?reset_modules_order must be in['before', 'after', 'both'], got )rw   rx   )r   titlesrU   rm   rn   r   zUnknown css z, must be one of z.cssr   r   unusedzDgallery_conf["show_api_usage"] must be True, False or "unused", got rP   r   )"copydeepcopyDEFAULT_GALLERY_CONFr   r   r   configr   r   r   r   r   r   r   intr   joblib	Exception
ValueErrorr   r   r)   ImportErrorr   r   r   r   pathlibr   r!   r"   
_KNOWN_CSSadd_css_filer   )r   r   r   r>   r   supported_reprsrepr  cell_config_keysr   backrefr   s               r:   _fill_gallery_conf_defaultsr  g  s*   =!566L\+>
KKK+,,, : : '|C'899S#%L %+-?$@L!
:n% 	F+.:n+EL((+
?(C_%l?3S99 	R-9/-JD,QL) |^eT]PTUUUU<<<ON+  o%%4%4 4.14 4   & |%8#>>> |Z$===J4''#&<Z J1$$#(Z J X	XMMMM 	X 	X 	XVWWW	X l48888 * * ***|C/@/H|S))))$    %%%<((( s333 <111|%:C@@@)*2MMM; 56; ;
 
 	
 E$ I I<34HHHHH <(((L	gl	    /0G'7<(( :-0\\)* /|H/EFFL #9]## #L |UT5MtLLLLE" + +j  SSSSZSSTTT?S6\*** |%7===|$45t<<
)*h664 014 4
 
 	
 /    .l;;;s   (E- -F G G#"G#c                   	 d         d}nN                     d          }t          |t                    rt          |          d<   t	          d          \  }d t          j                  D             |rfdD             nfdD             t
          j                            |           fdD             	t          	|          }fd	fd	|D             D             S )
a  Return the list of subsections of a gallery.

    Parameters
    ----------
    srcdir : str
        absolute path to directory containing conf.py
    examples_dir : str
        path to the examples directory relative to conf.py
    gallery_conf : Dict[str, Any]
        Sphinx-Gallery configuration dictionary.
    check_for_header : bool
        only return subfolders that contain a GALLERY_HEADER file, default True

    Returns
    -------
    out : list
        sorted list of gallery subsection folder names
    rO   Nc                     g | ]}|S r8   r8   )r   	subfolders     r:   r   z#get_subsections.<locals>.<listcomp>  s    FFF	)FFFr<   c                 v    g | ]5}t          t          j                            |          d           	 3|6S )F)raise_error)r   ospathr   )r   r  examples_dirr>   s     r:   r   z#get_subsections.<locals>.<listcomp>  s]     
 
 
"\955|QV      r<   c                     g | ]G}|d k    t           j                            t           j                            |                    E|HS )__pycache__)r  r  isdirr   )r   r  r  s     r:   r   z#get_subsections.<locals>.<listcomp>'  sV     
 
 
]**GMM"',,|Y"G"GHH +  +**r<   c                 P    g | ]"}t           j                            |          #S r8   r  r  r   )r   itembase_examples_dir_paths     r:   r   z#get_subsections.<locals>.<listcomp>1  s7       7;+T22  r<   r   c                      g | ]
}|         S r8   r8   )r   i
subfolderss     r:   r   z#get_subsections.<locals>.<listcomp>6  s-        	1  r<   c                 :    g | ]}                     |          S r8   )index)r   r  subfolders_with_paths     r:   r   z#get_subsections.<locals>.<listcomp>8  s(    QQQt&,,T22QQQr<   )
getr   r   r*   r   r  listdirr  relpathr   )
srcdirr  r>   check_for_headersortkeysubsec_ordersorted_subfoldersr  r#  r&  s
    ``    @@@r:   get_subsectionsr/     s{   & &'/#''(:;;lD)) 	K/<\/J/JL+,#L2DEE
FFRZ-E-EFFFJ 

 
 
 
 
'
 
 



 
 
 
'
 
 

  W__\6BB   ?I   3AAA   QQQQ?PQQQ   r<   c                    | d         }| d         }t          |t                    s|g}t          |t                    s|g}t          |          t          |          k    rt                              d           t          | d                   r<t          j                            || d                   }t          j	        |d           t          t          ||                    S )z3Creates necessary folders for sphinx_gallery files.rH   rS   z]'examples_dirs' and 'gallery_dirs' are of different lengths. Surplus entries will be ignored.rU   Texist_ok)r   r   r   r   r   r   r  r  r   makedirszip)r>   r*  rH   rS   rU   s        r:   _prepare_sphx_glr_dirsr5  <  s     1M/LmT** (&lD)) &$~
=S..../	
 	
 	

 L-.// 7W\\&,?S2TUU
&6666M<00111r<   c                 z    dd                     fd|                                 D             dgz             } | S )z0Filter out tags from `subsection_index_content`.z^\.\.(\s+)\_(.+)\:(\s*)$r   c                 >    g | ]}t          j        |          |S N)r   match)r   line	tag_regexs     r:   r   z _filter_tags.<locals>.<listcomp>X  s5     	
 	
 	
x	4((0 000r<   r\   )r   
splitlines)subsection_index_contentr;  s    @r:   _filter_tagsr>  T  sb    +I#yy	
 	
 	
 	
0;;==	
 	
 	

 $	    $#r<   c                    |r3|d         du r)t          |          dk    rt          |d          }||z  }|d         r"t          || j        j        |          }|r||z  }|r| j        j        d         r
|t          z  }t          j	        
                    |d          }t          j        |dd	
          5 }	|	                    |           ddd           n# 1 swxY w Y   t          |d           dS dS )zEAdd toctree, download and signature, if req, to index and write file.r   Tr   )includehiddenr_   r}   zindex.rst.newwutf-8encodingNr   mode)r   r-   r   builderr*  r  r   r   r  r  r   codecsopenwriter2   )
r   r>   indexstsg_root_indexsubsection_index_filesgallery_dir_abs_pathsubsections_toctreedownload_fhindexindex_rst_newfhindexs
             r:   _finish_index_rstrS  b  sr    	'*+t33&''!++-"$
 
 
 	&& +, (, #+"4l
 
  	(''G .:)*:; 	$|#G%9?KK[g>>> 	#'MM'"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#]------. .s   5CCCc           	         | d         d         r]	 ddl }n# t          $ r t          d          w xY wt          j        | d                   }|                    d           |                    dd           t          di |}g }|g|z   }|D ]}t          j        	                    ||          t          d t                                                    D             t          | d          d         	          }	|                    fd
|	D                        t          t!          j        |                    }|                    |           |D ]}
t'          ||
|            dS dS )z,Build recommender and write recommendations.rb   rc   r   Nz*gallery_conf['recommender'] requires numpyrubric_headerc                 (    g | ]}|j         d k    |S )rK   )suffix)r   fnames     r:   r   z&_build_recommender.<locals>.<listcomp>  s$    UUU5u|u?T?T?T?T?Tr<   rP   r   c                 P    g | ]"}t           j                            |          #S r8   r  )r   rX  r   s     r:   r   z&_build_recommender.<locals>.<listcomp>  s)    DDD%gu--DDDr<   r8   )numpyr  r   r   r  r   r'   r  r  r   r   r   iterdirr   r   r   r   from_iterablefitr(   )r>   rN  subsecsnprecommender_paramsrb   gallery_py_filesgallery_directoriescurrent_dirpy_filesrX  r   s              @r:   _build_recommenderre    s   M"8, E	L 	L 	L 	LJKKK	L "]<+FGGx(((555(>>+=>>34w>. 	 	Kgll#7EEG VUDMM$9$9$;$;UUU"<1JGTTUVW	  H ##DDDD8DDD      34D E EFF()))% 	E 	EE";|DDDD?E E<	E 	Es    1c                 "   t                               dd           t          | |d         d          \  }}|D ]\  }}}d| d                    |d	         d
z             }| |dz  }t                               |           Jt	          |                                d	                   }||d         k    rW||                    |d                   dz   |                    |d                   z   z  }t                               |           dS )zLog computation time.zcomputation time summary:whitecolorr   consoler   r   z    - z:   r   
   Nz	(not run)rj   r   z   r   )r   r   _format_for_writingljustr   splitrjust)	costsr>   lineslensnamer   mtextt_floats	            r:   
_log_costsrx    s   
KK+7K;;;%|I.Y  KE4  	" 	"
a####**47R<889KDKKAGGIIaL))G,':;;;Q((50177473C3CCCD!!!	" 	"r<   c           
         | j         j        }d}|d         rd|d          d}t                              d| dd           t	                      }g }t          || j        j                  }d	 |D             }t          ||d
           i }|D ]>\  }}	t          j
                            | j        j        |          }
t          j
                            | j        j        |	          }t          |
|||d          \  }}}}}t          ||           |du}||z  }t          |||           d}|r,d|z   }t          |          dk    rt!          |          }||z  }g }t#          | j        j        |
||          }|D ](}t          j
                            |
|          }t          j
                            ||          }|                    d                    d|	|dg                              t          j        d                     t          ||||          \  }}}}}t          ||           d}|r|t+          |          z  }d
}|r0|d         s(t          |          dk    rt!          |          }||z  }n|rt-          |d           ||z  }t          |||           *t/          | |||||           t1          |||           @t          |d|           |d         r+t3          t5          |d         |d         d          |           |d         durt7          | j        j                   t9          ||           |d         r-t;          ||           t=          || j        j        |           dS dS )a  Generate the Main examples gallery reStructuredText.

    Fill Sphinx-Gallery configuration and scan example directories
    (up to one level depth of sub-directory) to generate example reST files.

    Iterate through each example directory and any of its sub-directories
    (creates sub-sections) that has a header/index file.
    Generate gallery example ReST files and `index.rst` file(s).

    If `nested_sections=True` we generate `index.rst` files for all
    sub-directories, which includes toctree linking to all sub-dir examples.
    The root example directory `index.rst` file will contain, in sequence,:

    * root gallery header then thumbnails,
    * toctree linking all examples in root gallery,
    * sub-section header followed by sub-section thumbnails, for all subsections,
    * a second final toctree, at the end of the file, linking to all sub-section
      index files.

    If `nested_sections=True` we generate a single `index.rst` file per
    example directory. It will contain headers for the root gallery and
    each sub-section, with each header followed by a toctree linking to
    every example in the root gallery/sub-section.
    r\   r   z (with parallel=)zgenerating galleryz...rg  rh  c                     g | ]\  }}|S r8   r8   )r   ex_dir_s      r:   r   z(generate_gallery_rst.<locals>.<listcomp>  s    666	V666r<   T)check_filenamesF)is_subsectionNz
:orphan:

r   )r+  /z	index.rstr   r   rE  rU   r   backreferences_allr   r]   ) r  r   r   r   r   r5  rG  r*  r+   r  r  r   r    r,   rk   r   r-   r/  r   replacesepr>  r2   rS  re  r3   r   _init_api_usager   rx  write_junit_xmloutdir) r   r>   extraseen_backrefsrq  workdirsrH   backrefs_allr  gallery_direxamples_dir_abs_pathrN  r}  this_content
this_coststhis_toctree_itemsbackrefs_rootrL  rK  this_toctreerM  r^  
subsectionr   
target_dirsubsection_index_pathr=  subsection_costssubsection_toctree_filenamesbackrefs_subsechas_subsection_headersubsection_index_toctrees                                    r:   generate_gallery_rstr    s`   2 :1LEJ ?><
#;>>>
KK/U///wK???EEME%lCK4FGGH 76X666M=,MMMML%- bH bH!k "S[-? N N!w||CK,>LL ! 
 
 
	
 	 m<<< %D0.BJOOO  	($|3G%&&**./ABB<' "$!K!*	
 
 
 " '	P '	PJgll#8*EEG&:JGGJ"))"k:{CDDLLFC    !*lMRR%( , $L/BBB$)!' -<(@AAA(,% 
>$%67
> 45599+:;W+X+X(33 ' >2====%%E#L*>NOOOO 	" 	
 	
 	
 	<)=wGGGG L$666 () 
Y'12$ 
 	
 	
 	
 $%U22*+++]L999N# A5,'''ck&8%@@@@@A Ar<   z
:orphan:

.. _{0}:

z%
Computation times
=================
c           
          t          ddd          t          |           z   } d                    | j        dz  | j        z   | j        t          t          | j        dz                                } | S )z>Convert a number of seconds to a more readable representation.r   )secondsz{:02d}:{:02d}.{:03d}<   g     @@)	r   r   r   hourminutesecondr  roundmicrosecond)r   s    r:   _sec_to_readabler  v  sn     	AqIa0000A%%	ah#eAMF4J.K.K*L*L	 	A Hr<   c                 4    | d          | d          | d         fS )zCost sorting function.r   memsrc_filer8   )costs    r:   	_cost_keyr    s"     #YJed:&677r<   rst)r   c                   t                      }t          | t                    D ]}|d         }t          j                            ||          }|dv rt          j                            |d         |                              t          j        d          }|dk    r|nt          j                            |          }d	                    |t          j                            |          |          }	t          |d                   }
n|d	k    sJ |}	|d         d
d}
|d         dd}|                    |	|
|g            d t          d |D              D             }||fS )a  Provide formatted computation summary text.

    Parameters
    ----------
    costs: List[Dict]
        List of dicts of computation costs and paths, see gen_rst.py for details.
    src_dir : pathlib.Path
        The Sphinx source directory.
    kind: 'rst', 'rst-full' or 'console', default='rst'
        Format for printing to 'console' or for writing `sg_execution_times.rst' ('rst'
        for single galleries and 'rst-full' for all galleries).

    Returns
    -------
    lines: List[List[str]]
        Formatted computation text for each example, of format:
        [example_file, time_elapsed, memory_used]

    lens: List[int]
        Character length of each string in `lines`.
    r   r  )r  rst-fullr  r}  r  z!:ref:`sphx_glr_{0}_{1}` (``{2}``)r   rj  z0.2fz secr  z.1fz MBc                 ,    g | ]}t          |          S r8   )max)r   r   s     r:   r   z'_format_for_writing.<locals>.<listcomp>  s    SSSqCFFSSSr<   c                 &    g | ]}d  |D             S )c                 ,    g | ]}t          |          S r8   )r   )r   r  s     r:   r   z2_format_for_writing.<locals>.<listcomp>.<listcomp>  s    ">">">3t99">">">r<   r8   r   r  s     r:   r   z'_format_for_writing.<locals>.<listcomp>  s'    !Q!Q!Q4">">">">">!Q!Q!Qr<   )r   r   r  r  r  r)  r  r  basenamer   r  r   r4  )rq  r   r   rr  r  r  rel_pathtarget_dir_cleanparenrt  r   ru  rs  s                r:   rm  rm    sx   , FFEu),,, # #
#7??8W55&&&!wtL/A7KKSS    !%
 2 2HH8H8H8R8RE6== "'"2"28"<"<e D !c++AA9$$$$D9''''AE{####dAq\""""SSC!Q!Q5!Q!Q!QRSSSD$;r<   c                    | d         sdS t          d |D                       }|| d         }d}d}d}nM|}t          j                            || d                   }d}|                    t          j        d	           d	}d
| d}t          |          dz  }	|	                                r|dk    rdS |	                    dd          5 }
|
	                    t                              |                     |
	                    dt          |           dt          |           dt          |          dk    rdnd d| d	           t          || d         |          \  }}~|
	                    d           |pg dgD ]?\  }}}|
	                    d| d| d|                    d          d          d           @	 ddd           dS # 1 swxY w Y   dS )ao  Write computation times to `sg_execution_times.rst`.

    Parameters
    ----------
    gallery_conf : Dict[str, Any]
        Sphinx-Gallery configuration dictionary.
    target_dir : str | None
        Path to directory where example python source file are.
    costs: List[Dict]
        List of dicts of computation costs and paths, see gen_rst.py for details.
    rk   Nc              3   &   K   | ]}|d          V  dS )r   Nr8   r  s     r:   	<genexpr>z*write_computation_times.<locals>.<genexpr>  s&      114T#Y111111r<   r   zall galleriesr  r\   r  r}  	sphx_glr_sg_execution_timeszsg_execution_times.rstr   rA  rB  rC  z**z** total execution time for z filer   sz **from z**:

rk  aN  .. container::

  .. raw:: html

    <style scoped>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet" />
    </style>
    <script src="https://code.jquery.com/jquery-3.7.0.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
    <script type="text/javascript" class="init">
    $(document).ready( function () {
        $('table.sg-datatable').DataTable({order: [[1, 'desc']]});
    } );
    </script>

  .. list-table::
   :header-rows: 1
   :class: table table-striped sg-datatable

   * - Example
     - Time
     - Mem (MB)
)N/Ar  r  z   * - z
     - )maxsplitr   )sumr  r  r)  r  r  r   is_filerI  rJ  SPHX_GLR_COMP_TIMESr   r  r   rm  rsplit)r>   r  rq  
total_timeout_dirwherer   	ref_extranew_refout_filefidrr  rs  exr   mbs                   r:   rk   rk     s    12 11511111Jy)		
L,CDD}}RVS11444	7)777GG}}77H jAoo	sW	-	- 1		%,,W55666		W!*-- W W5zzW W'*5zzQBW WHMW W W	
 	
 	
 * +
 
 
t
 			
 	
 	
: 9#8#8#8"9 	 	IB2II
 	  			1	a      	U1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1s   C7GGGc                 D   | j         j        d         du rdS d| j         j        vrt                      | j         j        d<   || j         j        d         vr!t                      | j         j        d         |<   | j         j        d         |                             |           dS )a  Write api entries to `_sg_api_entries` configuration.

    To connect to `autodoc-process-docstring` event.

    Parameters
    ----------
    app :
        The Sphinx application object.
    what: str
        The type of the object which the docstring belongs to. One of
        "module", "class", "exception", "function", "method", "attribute".
    name :
        The fully qualified name of the object.
    obj :
        The object itself.
    options :
        The options given to the directive: an object with attributes inherited_members,
        undoc_members, show_inheritance and no-index that are true if the flag option of
        same name was given to the auto directive.
    lines :
        The lines of the docstring, see above.
    r   FN_sg_api_entries)r  r   r   r   r   )r   whatrt  objr   rr  s         r:   write_api_entriesr    s    . z%&675@@
 >>><@FF
&'893:12CDDDBE%%
&'89$?J"#45d;??EEEEEr<   c                     t          j        t          j                            | d          dd          5  	 d d d            d S # 1 swxY w Y   d S )Nsg_api_usage.rstrA  rB  rC  )rH  rI  r  r  r   )r  s    r:   r  r  '  s    	
["455sW
 
 
   	                 s   AA	A	z	#00000080z	#98CAE180z	#FEDA8B80z	#F67E4B80z	#A5002680)edgeokaybad_1bad_2bad_3c           
      t   ddl }|                    | dddt          d         ddd	d
d          }t          |t                    rKt                      }t                      }d |D             }t          |t                    D ]t          t                    dz
            D ]^}|         |dz            f|v r|
                    |         |dz            f           |         |v r||                  n|         }	|                    |	           |dz            }
t                      }t                    dz
  |k    rd}|D ]Jt                    |dz   k    rt          fdt          |dz             D                       r|dz  }K|
d| dz  }
|
||dz            <   |dk    rd}n|dk    rd}nd}t          |         |d<    |j        |
fi | |                    |	|
t          d                    `|d                             dg           D ]k}|                    d          t          t                    dz
            D ]4}|dz            |vr%|                    |         |dz                       5lnt          |t                    sJ |                                D ]d\  }}|                    |           |D ]G}|                    |t          d                    |                    ||t          d                    He|                                 dS ) a  Make a graph of unused and used API entries.

    The used API entries themselves are documented in the list, so
    for the graph, we'll focus on the number of unused API entries
    per modules. Modules with lots of unused entries (11+) will be colored
    red, those with less (6+) will be colored orange, those with only a few
    (1-5) will be colored yellow and those with no unused entries will be
    colored blue.

    The API entries that are used are shown with one graph per module.
    That way you can see the examples that each API entry is used in
    for that module (if this was done for the whole project at once,
    the graph would get too large very large quickly).

    Parameters
    ----------
    fname: str
        Path to '*sg_api_unused.dot' file.
    entries: Dict[str, List] or List[str]
        Used (List) or unused (Dict) API entries.
    gallery_conf : Dict[str, Any]
        Sphinx-Gallery configuration dictionary.
    r   Nscalez0.5)overlappadr  filled20boxzOpen Sans,Arial)ri  stylefontsizeshapefontname)filename
graph_attr	node_attrc                 8    g | ]}|                     d           S )r   ro  r   entrys     r:   r   z_make_graph.<locals>.<listcomp>e  s$    9995;;s##999r<   r   r   r      c                 4    g | ]}|         |         k    S r8   r8   )r   level2structstruct2s     r:   r   z_make_graph.<locals>.<listcomp>{  s6       $* !(6&> A  r<   z (rz  rl  r     r  r  ri  r  rh  r  moduler   )graphvizDigraph
API_COLORSr   r   r   r   r   r   ranger   nodeallr  r'  ro  itemssave)rX  entriesr>   r  dgconnectionslutstructslevel	node_fromnode_tonode_kwargs
leaf_count	color_keyr  r"  r  refsrefr  r  s                      @@r:   _make_graphr  9  s   0 OOO			
 

  ')
 
 
 
 
B '4   6>eeff99999W#... %	F %	FFs6{{Q// $F $F5M6%!)#45DDuqy0A BCCC*0-3*>*>Cu&&F5M  	""" +"ffv;;?e++!"J#* , ,w<<51944$     .3EAI.>.>    , '!OJ1J1111G-4Cuqy)*!B$+		#a$+		$+	+5i+@K(//;///	7*V2DEEEEI$FL ##4599(BGG 	6 	6F\\#&&F3v;;?++ 6 6!a%=++GGF1Iva!e}5556	6 '4((((("==?? 	> 	>KE4GGENNN > >:g#6777s*V*<====> GGIIIIIr<   c           
      
   |pd}|dk    rdS | j         j        d         du rdS t                              d          |d<   d}|dxx         |d	z   d
t	          |          z  z   dz   z  cc<   dvsd         |dxx         dz  cc<   dS t
          j                            d         d                   }t          j	        fddD              }t	          |          dk    r|dxx         dz  cc<   dS fd}t                      }t                      }t          t          |d                    }	d         }
|D ]}t          j        d         |          |	                    |d          }||                    |           Lt                      ||<   |D ]|}t          |d         |d                                       |
          }t'          |                              t
          j        d          }||                             d|            }t-          |          D ]"}|dxx         d ||           d| dz  cc<   #|dxx         dz  cc<   t/                      }|r|r|dxx         dz  cc<   t	          |          }|t	          |          z   }|t1          |d          z  }|dxx         dt3          |dz  d           d | d!| d"z  cc<   |r;|r9t5          t
          j                            | j        j        d#          |           d         d$u r|rd%}|dxx         |d	z   d
t	          |          z  z   dz   z  cc<   t-          |          D ]Q}|dxx         d ||           d| d&z  cc<   ||         D ]}|dxx         d'| dz  cc<   |dxx         dz  cc<   R|rEd( |D             }t-          |          D ]2}|dxx         | d	d
t	          |          z  z   d)| d*| d+z   z  cc<   3|D ]}t:                              d,|           t                      }|                                D ]t\  }}|                     d-          d         |k    rP|                    dd          }d.         D ]1}|!                    |          r|t	          |          dz   d         }2ut5          t
          j                            | j        j        | d/          |           dS dS dS dS )0a  Write an html page describing which API entries are used and unused.

    To document and graph only those API entries that are used by
    autodoc, we have to wait for autodoc to finish and hook into the
    ``source-read`` event. This intercepts the text from the rst such
    that it can be modified. Since, we only touched an empty file,
    we have to add 1) a list of all the API entries that are unused
    and a graph of the number of unused API entries per module and 2)
    a list of API entries that are used in examples, each with a sub-list
    of which examples that API entry is used in, and a graph that
    connects all of the API entries in a module to the examples
    that they are used in.

    Parameters
    ----------
    app :
        The Sphinx application object.
    docname :
        Docname of the document currently being parsed.
    source :
        List whose single element is the contents of the source file
    r\   sg_api_usageNr   Fsphx_glr_sg_api_usager   zUnused API Entriesr   ^z

r  rU   z%No API entries found, not computed.

r   c                 @    g | ]}|d          v d          |         S )r  r8   )r   obj_typer>   s     r:   r   z)write_api_entry_usage.<locals>.<listcomp>  s?     

 

 

<(9::: *+H5:::r<   )classmethodfunctionz No examples run, not computed.

c                     | d                              dg           v rdS | d                              dg           v rdS | d         d         v sJ dS )Nr  r  r  methr  func)r'  )r  r>   s    r:   get_entry_typez-write_api_entry_usage.<locals>.get_entry_type  sp    L!2377DDDD7l#4599(BGGGG6L):;JGGGGG6r<   zbackreferences_all.jsonr   r   r}  r  z- :z:`z`
zY.. graphviz:: ./sg_api_unused.dot
    :alt: API unused entries graph
    :layout: neato

r   z
API entries used: d   z% (r  z)

sg_api_unused.dotTzUsed API Entriesz`

z
  - :ref:`c                 D    h | ]}|                     d           d         S )r   r   r  r  s     r:   	<setcomp>z(write_api_entry_usage.<locals>.<setcomp>  s)    NNNEEKK,,Q/NNNr<   z

.. graphviz:: ./z_sg_api_used.dot
    :alt: z! usage graph
    :layout: neato

zMaking API usage graph for %sr   rS   z_sg_api_used.dot)"r  r   SPHX_GLR_ORPHANr   r   r  r  r   r   unionr   r   r1   r   r   r9  r'  r   relative_tor   r  r  r   r.   r  r  r  rG  r*  r   r   r  ro  r   )r   docnamesourcetitlerU   example_filesr  unused_api_entriesused_api_entriesr  r   r  backref_entrybrexample_pathref_namehas_graphviz
used_counttotal_countused_percentager  used_modulesr  r  r  r>   s                            @r:   write_api_entry_usager(    s   . mG.  :1L$%..  &&'>??F1I E
1IIIc%jj 00699III--,-5q			>>			Y.B!C  I

 

 

 

;

 

 

M =Qq			99			     vv#D);=V$W$WXX9%G G G8L!34e<<H*..ud;; %%e,,,,&*ffU## G G#BqE2a511==gFF|,,44RVSAA '../E8/E/EFFFF	G *++ ? ?q			>>>%00>>E>>>>				
1IIIIII ??L 
* 
q			%	
			 %&&Js#5666K 3{A#6#66O
1III	,3&**	, 	,	, 	,$	, 	, 	,III  
* 
GLL+-@AA	
 	
 	
 $%--2B-"q			UT\C#e**$44v==			,-- 	  	 E1IIID~~e44DDDDDDIII'. 3 3q			2#2222				1IIIIIII 	NN=MNNNL ..  q			MMMC#f++$55 9-'-9- 9-!'9- 9- 9- -				 '  ;VDDD&&"2"8"8":": E EJE3{{3''*f44 %k2 > >*6~*F E EJ$//
;; E(-c*oo.A.C.C(DGLL!35P5P5PQQ    = .---	 	 r<   c                    t           j                            t           j                            | j        j        d                    r<t          j        t           j                            | j        j        d                     t           j                            t           j                            | j        j        d                    r<t          j        t           j                            | j        j        d                     t          j        | j        j                  D ]B}d|v r<t          j        t           j                            | j        j        |                     CdS )zLRemove api usage .dot files.

    To connect to 'build-finished' event.
    r  r  zsg_api_used.dotN)r  r  isfiler   rG  r*  remover(  )r   	exceptionfiles      r:   clean_api_usage_filesr.  6  s   
 
w~~bgll3;#57IJJKK H
	"',,s{13EFFGGG	w~~bgll3;#57JKKLL I
	"',,s{13FGGHHH
3;-.. > >$$Ibgll3;#5t<<===> >r<   c                 B   | d         r| d         sdS t          |           \  }}}d}d}d}d}	| d         }
d}|D ]}|d         |d	         c}t          fd
| d         |||fD                       s:| d                  }|d                    t          t          j                            t          j                                                d                   t          t          j                            |
                    t          |          |          z  }|v r|dz  }|dz  }n|v s|v rw|v r| d                  }nd}|dz  }|d                    t          |	                                d         
                                          t          |                    z  }|dz  }|dz  }|	|z  }	|dz  }d                    ||||	          |z   }t          j                            t          j                            || d                             t          j                                      }t	          j        |d           t!          j        dd          5 }|                    |           ddd           dS # 1 swxY w Y   dS )ay  Write JUnit XML file of example run times, successes, and failures.

    Parameters
    ----------
    gallery_conf : Dict[str, Any]
        Sphinx-Gallery configuration dictionary.
    target_dir : Union[str, pathlib.Path]
        Build directory.
    costs: List[Tuple[Tuple[float], str]]
        List of dicts of computation costs and paths, see gen_rst.py for details.
    r~   r]   Nr   g        r   r\   r   r  c              3       K   | ]}|v V  	d S r8  r8   )r   r   rX  s     r:   r  z"write_junit_xml.<locals>.<genexpr>]  s;       
 
 QJ
 
 
 
 
 
r<   re   r   zB<testcase classname={!s} file={!s} line="1" name={!s} time="{!r}">z6<skipped message="expected example failure"></skipped>r   rd   z(Passed even though it was marked to failz$<failure message={!s}>{!s}</failure>r   z</testcase>z</testsuite>z<?xml version="1.0" encoding="utf-8"?><testsuite errors="0" failures="{}" name="sphinx-gallery" skipped="{}" tests="{}" time="{}">Tr1  rA  rB  rC  )_parse_failuresanyr   r   r  r  splitextr  r)  r<  r   r
   normpathr   dirnamer3  rH  rI  rJ  )r>   r  rq  failing_as_expectedfailing_unexpectedlypassing_unexpectedlyn_tests
n_failuresn_skipselapsedr   outputr  r   r  	traceback	junit_dirr  rX  s                     @r:   r  r  D  sH      ^(D FUG GC-/C GJGG9%GF # #9d:.5 
 
 
 
 /0$#$	
 
 
 
 
 		 X&u-PWW"'**27+;+;E+B+BCCAFGG"'//%99::%  	 	
 '''NNFqLGG***e7K.K.K,,,();<UC		F	!OJ<CC)..004::<<==vi?P?P  F 	-11
nF	--3V'.
 .
 	F GRW\\*l76KLLMME&&IK	D))))	UC'	2	2	2 c		&                 s   1JJJc                 @   t          | j        j        d                   sdS t          j                            | j        | j        j        d         | d          }t          j                            |          s$t          |d          	                                 dS dS )zGenerate empty back-reference example files.

    This avoids inclusion errors/warnings if there are no gallery
    examples for a class / module that is being parsed by autodoc.
    rU   Nz	.examplesrA  )
r   r  r   r  r  r   r*  existsrI  close)r   r  rt  r  r   rr  examples_paths          r:   touch_empty_backreferencesrD    s     
./CDEE GLL

&';< M 7>>-(( )]C  &&((((() )r<   c                 ,      fd d         D             S )Nc                     h | ]E}t           j                            t           j                            d          |                    FS r   )r  r  r4  r   )r   r  r>   s     r:   r  z-_expected_failing_examples.<locals>.<setcomp>  sN        	l9&=tDDEE  r<   rh   r8   )r>   s   `r:   _expected_failing_examplesrG    s4        !<=   r<   c                 
    t           d                   }t                     }|                    |          }|                    |          }|                    |          }t           fd|D                       }|||fS )zSplit the failures.rd   c              3   R   K   | ]!}t          j        d          |          |V  "dS )rE   N)r   search)r   r  r>   s     r:   r  z"_parse_failures.<locals>.<genexpr>  sO        9\"45x@@     r<   )r   rG  intersection
difference)r>   rd   rh   r6  r7  r8  s   `     r:   r1  r1    s    <(:;<< :< H H*778QRR+667PQQ4??@PQQ    ,    
  46JJJr<   c                    |dS | j         j        d         st                              dd           dS | j         j        t	                    \  }}}d|rt                              t          t          dt          |           d                               |D ]{}t          j	        
                    |d	                   }t                              t          t          |                     d
t          d         |                               |g }|r|                    t          t          dt          |           d                               |D ]w}t          j	        
                    |d	                   }|                    dt          t          |                     d
t          d         |                               x|rfd|D             }|                    t          t          dt          |           d                    t          d                    fd|D                                 z   dz   dz   dz              t          d                   }	t          d                   |	z   }
t          d                   }t                              d|	|
|
dk    rdndd         d         ||dk    rdndd	  	         |rkt          t          dd                    |          z   dz   dz                       }d          rt                              |           dS t#          |          dS )!zCollects the list of falling examples and prints them with a traceback.

    Raises ValueError if there where failing examples.
    Nr]   zTSphinx-Gallery gallery_conf["plot_gallery"] was False, so no examples were executed.brownrh  z    zExamples failing as expected (z):r   z failed leaving traceback:

rd   zUnexpected failing examples (z):
c                 \    g | ](}t           j                            |d                    )S r   )r  r  r)  )r   r   r>   s     r:   r   z.summarize_failing_examples.<locals>.<listcomp>  s;     
 
 
<=BGOOA|I677
 
 
r<   z,Examples expected to fail, but not failing (z):

r   c              3   8   K   | ]}t          |          V  d S r8  r   )r   r   idts     r:   r  z-summarize_failing_examples.<locals>.<genexpr>  s+      ::qF1cNN::::::r<   z$

Please remove these examples from z1sphinx_gallery_conf['expected_failing_examples'] zin your conf.py file.re   rf   z
Sphinx-Gallery successfully executed %d out of %d file%s subselected by:

    gallery_conf["filename_pattern"] = %r
    gallery_conf["ignore_pattern"]   = %r

after excluding %d file%s that had previously been run (based on MD5).
r   r  r\   rE   rG   zJHere is a summary of the problems encountered when running the examples:

zO-------------------------------------------------------------------------------ra   )r  r   r   r   r1  r   r   r   r  r  r)  r	   r   r   r   r   r   r   )r   r,  r6  r7  r8  fail_exampler  	fail_msgspathsn_goodn_totn_stalefail_messager>   rQ  s                @@r:   summarize_failing_examplesrY    s   
  :).9 3 	 	
 	
 	

 	:1LFUG GC-/C C 	Ss;N7O7OSSSTTUU	
 	
 	
 0 	 	L7??<i1HIIDKKT

## Q Q,'9:<H#NNQ Q   
 I 	TS9M5N5NTTTUUVV	
 	
 	
 1 	 	L7??<i1HIIDQtCII Q Q,'9:<H#NNQ Q   
  


 
 
 
AU
 
 
 	VCJJVVVWWXX$))::::E:::::;;<67 BB &	&	
 	
 	
 0122F/011F:E,/011G
KK	 	zzr'(%&!||    "  /1))I&&'  	 
 
 45 	/NN<((((( .../ /r<   c                       fd}|S )z#Get default configuration function.c                 R    | d                              t                             S )Nr   )r'  r  )confr   s    r:   default_getterz0get_default_config_value.<locals>.default_getter  s%    )*..s4H4MNNNr<   r8   )r   r]  s   ` r:   get_default_config_valuer^    s)    O O O O O r<   c                    t          |j        | |          }||_        |j                            t	                                 |j                            t          t          t                    j	        dz                       dS )a  Check the sphinx-gallery config and set its defaults.

    This is called early at config-inited, so that all the rest of the code can
    do things like ``sphinx_gallery_conf['binder']['use_jupyter_lab']``, even
    if the keys have not been set explicitly in conf.py.
    )r   r   
componentsN)
r  r   html_static_pathr   r   templates_pathr   r   __file__parent)r   r  r   new_sphinx_gallery_confs       r:   fill_gallery_conf_defaultsrf  "  s     :"
   "9F
""?#4#4555
   T(^^%:\%I!J!JKKKKKr<   c                     t          | j        j        j                  }| j        j        }t          | j        j        j                  }t          | j        j        |||| j        j                   dS )z7Update the the sphinx-gallery config at builder-inited.)r]   r`   r   N)	r   rG  r  r]   r*  r`   r   r   rt  )r   r]   r   r`   s       r:   "update_gallery_conf_builder_initedrh  5  sq    ck0=>>Lk G'(:(QRR'
&!5[%     r<   c                 <    fdfd}fd}||d<   ||d<   dS )zSet up the getters for download and launcher links.

    The getters are added to the sphinx context so as to be used in templates.
    c                 X     t          g           S                      fd          S )Nc                 r    t          | t          j                  o| j                            dg           v S )Nclasses)r   r   	container
attributesr'  )r   
class_names    r:   <lambda>zRsetup_template_link_getters.<locals>._find_containers_with_class.<locals>.<lambda>N  s5    jEO44 >al..y"=== r<   )iterfindall)ro  doctrees   `r:   _find_containers_with_classz@setup_template_link_getters.<locals>._find_containers_with_classI  s>    ?88O> > > >
 
 	
r<   c                     i } dD ]x\  }} d|           }t          |d          x}rS|j        d         j        d         j        }|                    d          x}rd| ||                    d          d| |<   y| S )	a[  Get the download links for the example.

        This function relies on `_find_containers_with_class` which in turn relies on
        `doctree` provided in the `html-page-context` event. This function will then
        be added to the context of the page and can be accessed in the template.

        This returns a dictionary with keys in ["python", "jupyter", "zip"], depending
        on their availability. The values contain:
        - link: The relative path to the download file
        - label: The "Download {label}" text
        - title: The title to show when hovering over the link
        ))pythonzsource code)jupyterzJupyter notebook)r4  zippedzsphx-glr-download-Nr   r  z_downloads/	reftarget)linklabelr  nextchildrenrn  r'  )linksr   r{  
containersrm  attrsrz  rt  s          r:   get_download_linksz7setup_template_link_getters.<locals>.get_download_linksR  s     
 	 	JC
 545O#5O5OPPJ T222y !*1-6q9D 99Z0004  4d 4 4!&!&;!7!7" "E#J
 r<   c                  4   i } dD ]} | d          }t          |d          x}ro|j        d         }|j        d         }|j                            d          x}r9||j                            d          |j                            d          d| |<   | S )	aZ  Get the launcher links for the example.

        This function relies on `_find_containers_with_class` which in turn relies on
        `doctree` provided in the `html-page-context` event. This function will then
        be added to the context of the page and can be accessed in the template.

        This returns a dictionary with keys in ["lite", "binder"], depending on their
        availability. The values contain:
        - link: The URL to Binder or JupyterLite link of the example
        - img_alt: The alt text for the link badge
        - img_src: The source URL of the link badge
        )literm   z-badgeNr   refurialturi)rz  img_altimg_srcr|  )r  r   r  rm  anchorimagerz  rt  s          r:   get_launcher_linksz7setup_template_link_getters.<locals>.get_launcher_linksp  s     % 
	 
	C44^^^DDJ T222y "+A.*!,00:::4  $#(#3#7#7#>#>#(#3#7#7#>#>" "E#J
 r<   r  r  Nr8   )r   pagenametemplatenamecontextrs  r  r  rt  s       `  @r:   setup_template_link_gettersr  C  sm    
 
 
 
 
    <    6 %7G !$6G !!!r<   c                 F   |                      dt          d           dD ]&}|                      |t          |          d           '|                     dt          d           |                     dt
          d           |                     dt          d           d	| j        v rQ|                     d
t                     |                     d
t                     |                     dt                     |                     dt                     |                     dt                     t          |            |                     dt          d           |                     dt                      |                     dt"                     |                     dt$                     |                     dt&                     |                     dt(                     |                     dt*                     |                     dt,                     ddt.          d}|S )z&Setup Sphinx-Gallery sphinx extension.r   r   )r]   r`   zconfig-initedrl  )priorityr  i  zsphinx.ext.autodoczautodoc-process-docstringzsource-readminigalleryzimage-sgzbuilder-initedzbuild-finishedzhtml-page-contextT)parallel_read_safeparallel_write_safer   )add_config_valuer  r^  connectrf  r&   r%   
extensionsrD  r  r(  add_directiver   r   r   rh  r  r#   r$   rY  r   r.  r  _sg_version)r   r   metadatas      r:   setupr    s    .0DfMMM9 I IS":3"?"?HHHH KK!;bKIII KK!ACKPPP KK!BSKQQQs~--/1KLLL/1BCCCM#8999 m[111j'***C KK "DrKRRRKK "6777KK "3444KK "=>>>KK "<===KK "2333KK "7888KK#%@AAA ## H
 Or<   c                      dS )z-Hack to stop nosetests running setup() above.Nr8   r8   r<   r:   setup_moduler    s    Dr<   )TFr   )FF)NT)T)rD   rH  r   r  r	  r   r   r   difflibr   	itertoolsr   r   textwrapr	   xml.sax.saxutilsr
   r   sphinx.utilsphinxdocutilsr   sphinx.errorsr   r   sphinx.util.consoler   r   r   r   r\   r   r  r   backreferencesr   
directivesr   r   r   docs_resolvr   	downloadsr   gen_rstr   r   r   r   r    interactive_exampler!   r"   r#   r$   r%   r&   rb   r'   r(   scrapersr)   sortingr*   utilsr+   r,   r-   r.   r/   r0   r1   r2   r3   r
  r6   r  r  r   r   getenvr  utillogging	getLoggerr   r   r   r   r   r   r   r   r   r   r  r/  r5  r>  rS  re  rx  r  r  r  r  r  rm  rk   r  r  r   r  r  r(  r.  r  rD  rG  r1  rY  r^  rf  rh  r  r  r  r8   r<   r:   <module>r     sz	      				  				 ( ( ( ( ( ( ( ( % % % % % %                   . . . . . . . .           5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7 7 7 7 7 ( ( ( ( ( (       4 4 4 4 4 4 = = = = = = = = = = ) ) ) ) ) ) ( ( ( ( ( (                             D C C C C C C C ( ( ( ( ( ( " " " " " "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

       @		"&))F2@o@ RW\\$
33@ 5'	@
 @ E7@ ""$$@ @ 9@ d@ O@ $@ "@ CCEE@ R@  /!@" #@ @. F/@0 T1@2 e3@4 !%5@6 He$7@8 9@: ;@< b=@> %?@@  A@B jC@D E@F yry)<==EG@H bI@J 2K@L UM@N oO@ @ @P rQ@R .S@T 8U@V 4W@X $Y@Z u[@\ ]@^ e_@` 5a@b dc@d Re@f )95g@h i@j 
:k@l Um@n Bo@p $q@ @r #%%"@ @ @ D 
		&	&'7	8	8  ? ? ?&  7 7 7 7' ' '*    @? ? ?"@ @ @D ;  ;  ;F  DV V V Vr9 9 9 9x2 2 20$ $ $$. $. $.N!E !E !EH" " "$dA dA dAN  
 
 
8 8 8 16 * * * * *ZN N NbF F F@   T		


  
` ` `FW W Wt> > >H H HV) ) )(  K K K \/ \/ \/~  L L L L&  I7 I7 I7X+ + +\	 	 	 	 	r<   