
    -Ph                         d Z ddlZddlZddlmZ ddlmZ ddlmZ  G d d          Z	 G d	 d
          Z
 G d de
          Z G d de
          Z G d de
          Z G d de
          Z G d d          ZdS )zsSorters for Sphinx-Gallery (sub)sections.

Sorting key functions for gallery subsection folders and section files.
    N)ConfigError   )extract_intro_and_title)split_code_and_text_blocksc                   $    e Zd ZdZd Zd Zd ZdS )ExplicitOrdera  Sorting key for all gallery subsections.

    All subsections folders must be listed, otherwise an exception is raised.
    However, you can add '*' as a placeholder to the list. All not-listed
    subsection folders will be inserted at the given position and no
    exception is raised.

    Parameters
    ----------
    ordered_list : list, tuple, or :term:`python:generator`
        Hold the paths of each galleries' subsections.

    Raises
    ------
    ValueError
        Wrong input type or Subgallery path missing.
    c                 z   t          |t          t          t          j        f          st          d          d |D             | _        	 |                    d          }d| _        | j        d |         | _	        | j        |dz   d          | _
        d S # t          $ r d| _        g | _	        | j        | _
        Y d S w xY w)NziExplicitOrder sorting key takes a list, tuple or Generator, which holdthe paths of each gallery subfolderc                 \    g | ])}|d k    rd nt           j                            |          *S )*)ospathnormpath).0r   s     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx_gallery/sorting.py
<listcomp>z*ExplicitOrder.__init__.<locals>.<listcomp>.   sA     
 
 
?C43;;CCBG$4$4T$:$:
 
 
    r   Tr   F)
isinstancelisttupletypesGeneratorTyper   ordered_listindexhas_wildcardordered_list_startordered_list_end
ValueError)selfr   is      r   __init__zExplicitOrder.__init__&   s    ,ue6I(JKK 	6  
 
GS
 
 
	6""3''A $D&*&7&;D#$($5a!egg$>D!!! 	6 	6 	6 %D&(D#$($5D!!!!	6s   	AB $B:9B:c                    || j         v r/| j                             |          t          | j                   z
  S || j        v r| j                            |          dz   S | j        rdS t          d                    |                    )a  
        Return an integer suited for ordering the items.

        If the ordered_list contains a wildcard "*", items before "*" will return
        negative numbers, items after "*" will have positive numbers, and
        not-listed items will return 0.

        If there is no wildcard, all items with return positive numbers, and
        not-listed items will raise a ConfigError.
        r   r   zThe subsection folder {!r} was not found in the 'subsection_order' config. If you use an explicit 'subsection_order', you must specify all subsection folders or add '*' as a wildcard to collect all not-listed subsection folders.)r   r   lenr   r   r   format)r   items     r   __call__zExplicitOrder.__call__;   s     4****0066T=T9U9UUUT***(..t44q88  	q!  &vd||  r   c                 2    d| j         j         d| j         dS )N<z : >)	__class____name__r   r   s    r   __repr__zExplicitOrder.__repr__V   s#    C4>*CCt/@CCCCr   N)r*   
__module____qualname____doc__r    r%   r,    r   r   r   r      sP         $6 6 6*  6D D D D Dr   r   c                       e Zd ZdZd Zd ZdS )_SortKeyz)Base class for section order key classes.c                     || _         d S N)src_dir)r   r5   s     r   r    z_SortKey.__init__]   s    r   c                 "    d| j         j         dS )Nr'   r(   )r)   r*   r+   s    r   r,   z_SortKey.__repr__`   s    -4>*----r   N)r*   r-   r.   r/   r    r,   r0   r   r   r2   r2   Z   s8        33  . . . . .r   r2   c                       e Zd ZdZd ZdS )NumberOfCodeLinesSortKeyzSort examples in src_dir by the number of code lines.

    Parameters
    ----------
    src_dir : str
        The source directory.
    c                     t           j                            t           j                            | j        |                    }t          |          \  }}t          d |D                       }|S )z*Return number of code lines in `filename`.c              3   T   K   | ]#}|j         d k    t          |j                  V  $dS )codeN)typer"   content)r   blocks     r   	<genexpr>z4NumberOfCodeLinesSortKey.__call__.<locals>.<genexpr>q   sA       
 
#(UZ6=Q=QC=Q=Q=Q=Q
 
r   )r   r   r   joinr5   r   sum)r   filenamesrc_file	file_confscript_blocksamount_of_codes         r   r%   z!NumberOfCodeLinesSortKey.__call__m   sn    7##BGLLx$H$HII#=h#G#G 	= 
 
,9
 
 
 
 
 r   Nr*   r-   r.   r/   r%   r0   r   r   r8   r8   d   s-             r   r8   c                       e Zd ZdZd ZdS )FileSizeSortKeyzzSort examples in src_dir by file size.

    Parameters
    ----------
    src_dir : str
        The source directory.
    c                     t           j                            t           j                            | j        |                    }t          t          j        |          j                  S )zReturn file size.)r   r   r   r@   r5   intstatst_size)r   rB   rC   s      r   r%   zFileSizeSortKey.__call__   sD    7##BGLLx$H$HII278$$,---r   NrG   r0   r   r   rI   rI   w   s-         . . . . .r   rI   c                       e Zd ZdZd ZdS )FileNameSortKeyzzSort examples in src_dir by file name.

    Parameters
    ----------
    src_dir : str
        The source directory.
    c                     |S )zReturn `filename`.r0   )r   rB   s     r   r%   zFileNameSortKey.__call__   s    r   NrG   r0   r   r   rO   rO      s-             r   rO   c                       e Zd ZdZd ZdS )ExampleTitleSortKeyz~Sort examples in src_dir by example title.

    Parameters
    ----------
    src_dir : str
        The source directory.
    c                     t           j                            t           j                            | j        |                    }t          |          \  }}t          ||d         j                  \  }}|S )zReturn title of example.r   )r   r   r   r@   r5   r   r   r=   )r   rB   rC   _rE   titles         r   r%   zExampleTitleSortKey.__call__   s[    7##BGLLx$H$HII5h??=*8]15E5MNN5r   NrG   r0   r   r   rR   rR      s-             r   rR   c                   &    e Zd ZdZddZd Zd ZdS )FunctionSortKeya@  Sort examples using a function passed through to :py:func:`sorted`.

    Parameters
    ----------
    func : :external+python:term:`callable`
           sorting key function,
           can only take one argument, i.e. lambda func = arg: arg[0] * arg[1]
    r : str, None
        printable representation of object
    Nc                 "    || _         || _        d S r4   )fr)r   funcrZ   s      r   r    zFunctionSortKey.__init__   s    r   c                 "    | j         r| j         ndS )NrW   )rZ   r+   s    r   r,   zFunctionSortKey.__repr__   s    6tvv%66r   c                 ,    |                      |          S )zReturn func(arg).)rY   )r   args     r   r%   zFunctionSortKey.__call__   s    vvc{{r   r4   )r*   r-   r.   r/   r    r,   r%   r0   r   r   rW   rW      sP        	 	   7 7 7    r   rW   )r/   r   r   sphinx.errorsr   gen_rstr   py_source_parserr   r   r2   r8   rI   rO   rR   rW   r0   r   r   <module>rb      s    
			  % % % % % % , , , , , , 8 8 8 8 8 8DD DD DD DD DD DD DD DDN. . . . . . . .    x   &. . . . .h . . .    h       (   "         r   