
    -PhW                        d Z ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZmZ dedeeef         fd	Zded
edefdZdedeeef         dee         fdZdedefdZ ej        e          ZdefdZdedededdfdZ	 ddedeeef         dee	ef         dede
e	e                  de	e         fdZdedeee	e         f         de	e         fdZ dedefdZ!dS )z8General helpers for the management of config parameters.    N)AnyCallableDictIterableListOptionalUnion)Node)Sphinx)loggingmatchingappreturnc                     t          | j        d          r| j        j        S t          | j        d          r| j        j        S i S )a  Return theme options for the application w/ a fallback if they don't exist.

    The "top-level" mapping (the one we should usually check first, and modify
    if desired) is ``app.builder.theme_options``. It is created by Sphinx as a
    copy of ``app.config.html_theme_options`` (containing user-configs from
    their ``conf.py``); sometimes that copy never occurs though which is why we
    check both.
    theme_optionshtml_theme_options)hasattrbuilderr   configr   )r   s    Y/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pydata_sphinx_theme/utils.pyget_theme_options_dictr      sH     s{O,, {((	1	2	2 z,,	    keyc                 f    t          fd| j        j        | j        j        fD                       S )z3Check if the user has manually provided the config.c              3       K   | ]}|v V  	d S N ).0iir   s     r   	<genexpr>z*config_provided_by_user.<locals>.<genexpr>!   s'      RRRsbyRRRRRRr   )anyr   	overrides_raw_config)r   r   s    `r   config_provided_by_userr$      s5    RRRRCJ$8#*:P#QRRRRRRr   node	conditionc                 Z    t          | d          r | j        |fi |n | j        |fi |S )zTriage node.traverse (docutils <0.18.1) vs node.findall.

    TODO: This check can be removed when the minimum supported docutils version
    for numpydoc is docutils>=0.18.1.
    findall)r   r(   traverse)r%   r&   kwargss      r   traverse_or_findallr+   $   sK     4##	0Y))&)))T]9////r   stringc                 V    t          j        d          }|                    d|           S )z=Helper function to remove ansi coloring from sphinx warnings.z(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~] )recompilesub)r,   ansi_escapes     r   escape_ansir3   3   s&    *?@@K??2v&&&r   c                     t          |           }|                    dd          }|rt          j        |g|R i | dS t          j        |g|R i | dS )z5Wraps the Sphinx logger to allow warning suppression.surface_warningsFN)r   getSPHINX_LOGGERwarninginfo)r   msgargsr*   r   should_warns         r   
maybe_warnr=   <   s{    *3//M##$6>>K 1c3D333F333333000000000r   pagenametemplatenamec                     d|v rD|d         }t          |t                    rt          ||          }t          | ||d          |d<   dS dS )zASet the secondary sidebar items to render for the given pagename.theme_secondary_sidebar_itemssecondary_sidebar_itemsN)
isinstancedict_get_matching_sidebar_items_update_and_remove_templates)r   r>   r?   contextdoctree	templatess         r   set_secondary_sidebar_itemsrJ   F   sk     ''11;<	i&& 	I3HiHHI-I+	.
 .
)*** 21r   rG   rI   sectiontemplates_skip_empty_checkc                   	 |g }t          |t                    rd |                    d          D             }g }|D ]U	t          j                            	          d         r|                    	           =|                    	 d           Vt          j        |          }|                    ||i           g }|D ]	t          	fd|D                       r|                    	           3| j
        j                            	|          }t          |                                          dk    r|                    	           |S )a  
    Update templates to include html suffix if needed; remove templates which render
    empty.

    Args:
        app: Sphinx application passed to the html page context
        context: The html page context; dictionary of values passed to the templating
            engine
        templates: A list of template names, or a string of comma separated template
            names
        section: Name of the template section where the templates are to be rendered.
            Valid section names include any of the ``sphinx`` or ``html_theme_options``
            that take templates or lists of templates as arguments, for example:
            ``theme_navbar_start``, ``theme_primary_sidebar_end``,
            ``theme_secondary_sidebar_items``, ``sidebars``, etc.
            For a complete list of valid section names, see the source for
            :py:func:`pydata_sphinx_theme.update_and_remove_templates` and
            :py:func:`pydata_sphinx_theme.utils.set_secondary_sidebar_items`,
            both of which call this function.
        templates_skip_empty_check: Names of any templates which should never be removed
            from the list of filtered templates returned by this function.
            These templates aren't checked if they render empty, which can save time if
            the template is slow to render.

    Returns:
        A list of template names (including '.html' suffix) to render into the section
    Nc                 6    g | ]}|                                 S r   )strip)r   templates     r   
<listcomp>z0_update_and_remove_templates.<locals>.<listcomp>~   s"    KKK(X^^%%KKKr   ,   z.htmlc              3   B   K   | ]}                     |          V  d S r   )endswith)r   itemrP   s     r   r    z/_update_and_remove_templates.<locals>.<genexpr>   s1      NN4x  &&NNNNNNr   r   )rC   strsplitospathsplitextappendcopyupdater!   r   rI   renderlenrO   )
r   rG   rI   rK   rL   suffixed_templatesctxfiltered_templatesrenderedrP   s
            @r   rF   rF   W   s~   D ")%'" )S!! LKKiooc6J6JKKK	  : :7H%%a( 	:%%h////%%&8&8&89999
)G

CJJ+,--- & 4 4NNNN3MNNNNN 	4%%h////{,33HcBBH8>>##$$))"))(333r   sidebarsc                     d}g }|                                 D ]\\  }}t          j        | |          rB|r<t          |          r-t          |          rt                              d| ||          f |}|}]|S )a,  Get the matching sidebar templates to render for the given pagename.

    If a page matches more than one pattern, a warning is emitted, and the templates
    for the last matching pattern are used.

    This function was adapted from
    sphinx.builders.html.StandaloneHTMLBuilder.add_sidebars.
    NzKPage %s matches two wildcard patterns in secondary_sidebar_items: %s and %s)itemsr   patmatch_has_wildcardr7   r8   )r>   re   matchedrB   patternsidebar_itemss         r   rE   rE      s     G "*.."2"2 4 4Xw// 	4 =11 mG6L6L !))e 	   G&3#""r   rk   c                 :     t           fddD                       S )zwCheck whether the pattern contains a wildcard.

    Taken from sphinx.builders.StandaloneHTMLBuilder.add_sidebars.
    c              3       K   | ]}|v V  	d S r   r   )r   charrk   s     r   r    z _has_wildcard.<locals>.<genexpr>   s'      114tw111111r   z*?[)r!   )rk   s   `r   ri   ri      s(    
 11115111111r   r   )"__doc__r]   rY   r/   typingr   r   r   r   r   r   r	   docutils.nodesr
   sphinx.applicationr   sphinx.utilr   r   rW   r   boolr$   typer+   r3   	getLogger__name__r7   r=   rJ   rF   rE   ri   r   r   r   <module>ry      s   > >  				 				 G G G G G G G G G G G G G G G G G G       % % % % % % ) ) ) ) ) ) ) ) 4S>    "S Sc Sd S S S S

 40d^   ' ' ' ' ' ' "!(++1F 1 1 1 1
	

.1
	
 
 
 
, 7;? ?	?#s(^? T3Y? 	?
 !)c 3? 
#Y? ? ? ?D##!#tCy.1#	#Y# # # #:23 24 2 2 2 2 2 2r   