
    c<                        d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlmZ d dl	m
Z
 d dlZd dlmZ ddlmZmZmZmZ ddlmZ d	Z G d
 de          Z G d dee          Z G d dee          Z G d dee          ZddZdS )    N)Callable)FileSystemLoader)SandboxedEnvironment)BuiltinTemplateLoader   )NumpyDocStringFunctionDocClassDocObjDoc)	make_xrefz1\b(import +matplotlib|from +matplotlib +import)\bc                        e Zd ZddZd ZddZd ZddZd	 Zd
 Z	d Z
ddZd Zd Zd dZd Zd Z fdZd Zd Zd Zd Zd!dZ xZS )"SphinxDocStringNc                 f    |i }t          j        | ||           |                     |           d S )Nconfig)r   __init__load_config)self	docstringr   s      9lib/python3.11/site-packages/numpydoc/docscrape_sphinx.pyr   zSphinxDocString.__init__   sA     	Fi????         c                    |                     dd          | _        |                     dd          | _        |                     dd          | _        |                     dd          | _        |                     dt                                | _        |                     dt                                | _        |                     d	d           | _	        | j	        ~t          j                            t          j                            t                    d
          g}t          |          }t!          |          }|                    d          | _	        d S d S )N	use_plotsFclass_members_toctreeTattributes_as_param_listxref_param_typexref_aliasesxref_ignoretemplate	templatesloadernumpydoc_docstring.rst)getr   r   r   r   dictr   setr   r   ospathjoindirname__file__r   r   get_template)r   r   template_dirstemplate_loadertemplate_envs        r   r   zSphinxDocString.load_config   s   K77%+ZZ0G%N%N"(.

3Mt(T(T%%zz*;UCC"JJ~tvv>>!::mSUU;;

:t44= 	PW\\"'//(*C*C[QQRM.}==O/GGGL(556NOODMMM		P 	Pr   `c                     d|z   dgS )N.. rubric::   )r   namesymbols      r   _str_headerzSphinxDocString._str_header*   s    %r**r   c                     d|z   dz   gS )N:r4   r   r5   s     r   _str_field_listzSphinxDocString._str_field_list-   s    d
S !!r      c                 ,    g }|D ]}|d|z  |z   gz  }|S )N r4   )r   docindentoutlines        r   _str_indentzSphinxDocString._str_indent0   s3     	) 	)DC&L4'((CC
r   c                     dgS )Nr3   r4   r   s    r   _str_signaturezSphinxDocString._str_signature6   s	    tr   c                     | d         dgz   S )NSummaryr3   r4   rE   s    r   _str_summaryzSphinxDocString._str_summary9   s    I"%%r   c                     | d         dgz   S )NzExtended Summaryr3   r4   rE   s    r   _str_extended_summaryz%SphinxDocString._str_extended_summary<   s    &'2$..r   Returnsc                 .   d}d}g }| |         r||                      |          z  }|dgz  }| |         D ]}|j        }|r"| j        rt          || j        | j                  }|j        r6||                     ||j                                        |fz  g          z  }n.||                     ||                                z  g          z  }|j	        s||                     dgd          z  }n||                     |j	        d          z  }|dgz  }|S )Nz**%s** : %sz%sr3   ..   )
r;   typer   r   r   r   r5   rC   stripdesc)r   r5   	named_fmtunnamed_fmtrA   param
param_types          r   _str_returnszSphinxDocString._str_returns?   sU   !	: 	4''---CB4KCd  "Z
 $"6 !*"D$5t7G" "J : P4++"ej&6&6&8&8*%EEF  CC 4++[:;K;K;M;M-M,NOOOCz ;4++TFA666CC4++EJ:::Ct
r   c                 r    |d d         dk    rd|dd          z   S |d d         dk    rd|dd          z   S |S )N   **z\*\*r   *z\*r4   r:   s     r   _escape_args_and_kwargsz'SphinxDocString._escape_args_and_kwargsZ   sV    8t 	T!""X%%"1"X_ 	48##Kr   c                 D   |                      |                                          }d| d}|s||fS t          | j        |d          }t	          |          s?t          |t                    s*t          j        |          st          j	        |          sd}t          j        |          }|r|s||fS t          | dd          }|r| d}nd}d| d| | d}|rt          j        d	|                                d
          d         }t          j        dd                    |                                                    }	|	r(|	                    d
                                          }n|                    d          d         }|                    d          }||fS )a  Determine how to display a parameter

        Emulates autosummary behavior if fake_autosummary

        Parameters
        ----------
        param : str
            The name of the parameter
        desc : list of str
            The parameter description as given in the docstring. This is
            ignored when autosummary logic applies.
        fake_autosummary : bool
            If True, autosummary-style behaviour will apply for params
            that are attributes of the class and have a docstring.

        Returns
        -------
        display_param : str
            The marked up parameter name for display. This may include a link
            to the corresponding attribute's own documentation.
        desc : list of str
            A list of description lines. This may be identical to the input
            ``desc``, if ``autosum is None`` or ``param`` is not a class
            attribute, or it will be a summary of the class attribute's
            docstring.

        Notes
        -----
        This does not have the autosummary functionality to display a method's
        signature, and hence is not used to format methods.  It may be
        complicated to incorporate autosummary's signature mangling, as it
        relies on Sphinx's plugin mechanism.
        rZ   N_namer3   .z:obj:`z <z>`z\n\s*\nr   r   z^([A-Z].*?\.)(?:\s|$)r>   
)r\   rQ   getattr_objcallable
isinstancepropertyinspectisgetsetdescriptorismemberdescriptorpydocgetdocresplitsearchr)   group	partition)
r   rU   rR   fake_autosummarydisplay_param	param_objobj_docprefixlink_prefixms
             r   _process_paramzSphinxDocString._process_paramb   s   D ,,U[[]];;
 'U 	' $&&DIud33	Y	)X..	 ))44	 ))44		 I,y)) 	'g 	' $&&w++ 	#,,,KKK A@@+@u@@@ 
	$8J;;A>D 	2CHHTZZ\\4J4JKKA /wwqzz''))~~d++A.::d##Dd""r   Fc                    g }| |         r||                      |          z  }|dgz  }| |         D ]}|                     |j        |j        |          \  }}g }|r|                    |           |j        }|r>|j        }| j        rt          || j        | j	                  }|                    |           || 
                    d                    |          g          z  }|sdg}|| 
                    |d          z  }|dgz  }|S )aI  Generate RST for a listing of parameters or similar

        Parameter names are displayed as bold text, and descriptions
        are in definition lists.

        Parameters
        ----------
        name : str
            Section name (e.g. Parameters)
        fake_autosummary : bool
            When True, the parameter names may correspond to attributes of the
            object beign documented, usually ``property`` instances on a class.
            In this case, names will be linked to fuller descriptions.

        Returns
        -------
        rst : list of str
        r3   z : rN   rO   )r;   rw   r5   rR   appendrP   r   r   r   r   rC   r)   )	r   r5   rp   rA   rU   rq   rR   partsrV   s	            r   _str_param_listzSphinxDocString._str_param_list   sE   & : 	4''---CB4KCd  &*&9&9J
,<' '#t   0LL///"Z
 -!&J+ %.&(94;K& &
 LL,,,t''E):):(;<<< " 6Dt''a000t
r   c                    g }| |         r|d| dgz  }t          | dd          }|rd| d}g }g }| |         D ]}|                    |j                                                  }t          | j        |j        d          }t          |          s+t          |t                    st          j	        |          sd}|r%t          j        |          r|d| |j         gz  }|                    |           |r|d	gz  }| j        r|d
gz  }|dg|z   z  }|rt          dt          d |D                                 }d|z  dz   dz   }	d|fz  }
|dd|	gz  }|D ]v}d|j                                        z   dz   }d                    d |j        D                                                       }|j        rd|j         d| }||
||fz  gz  }w||	gz  }|dgz  }|S )zp
        Generate a member listing, autosummary:: table where possible,
        and a table where not.

        r2   r3   r^   ~r_   )r5   N   z.. autosummary::z   :toctree:   c              3   D   K   | ]}t          |j                  d z   V  dS )r<   N)lenr5   ).0ps     r   	<genexpr>z3SphinxDocString._str_member_list.<locals>.<genexpr>	  s.      %F%F!c!&kkAo%F%F%F%F%F%Fr   =z  z
==========z%%%ds  %%s  rZ   r>   c              3   >   K   | ]}|                                 V  d S N)rQ   )r   xs     r   r   z3SphinxDocString._str_member_list.<locals>.<genexpr>  s*      #B#B!AGGII#B#B#B#B#B#Br   (z) )ra   _replacer5   rQ   rb   rc   rd   re   rf   isdatadescriptorri   rj   ry   r   maxr)   rR   rP   )r   r5   rA   rt   autosumothersrU   rr   maxlen_0hdrfmtrR   s               r   _str_member_listz SphinxDocString._str_member_list   s|    : -	)4))2..CT7B//F '&VGFd ) )EJ,<,<,>,>?? $DIuz4@@	Y''%!)X66% /	::%
 !%I )i!8!8 ) :f :ej : :;;GGMM%(((( &*++- ,N++Ctg~% q#%F%Fv%F%F%F"F"FGGHnt+h6${2B}$# 0 0E%*"2"2"4"44t;D88#B#Buz#B#B#BBBHHJJDz 875:7777C4,.//CCuB4KC
r   c                     g }| |         rc||                      |          z  }t          j        d                    | |                                                 d          }||z  }|dgz  }|S )Nr`   r3   )r7   textwrapdedentr)   rl   )r   r5   rA   contents       r   _str_sectionzSphinxDocString._str_section  sq    : 	4##D)))CodiiT
&;&;<<BB4HHG7NCB4KC
r   c                     g }| d         rEt                                          |          }ddg}||                     |dd                    z  }|S )NzSee Alsoz.. seealso::r3   rY   )super_str_see_alsorC   )r   	func_rolerA   see_also	__class__s       r   r   zSphinxDocString._str_see_also   s[    
 	2ww,,Y77H!2&C4##HQRRL111C
r   c                 j    g }| d         r(ddg}||                      | d                   z  }|dgz  }|S )NWarningsz.. warning::r3   )rC   )r   rA   s     r   _str_warningszSphinxDocString._str_warnings(  sK    
 	!2&C4##D$4555CB4KC
r   c                 P   | d         }g }t          |          dk    r|S |d|                    dd           gz  }|                                D ]N\  }}|dk    r|dk    r|dd                    |           gz  }/|d	| d
d                    |           gz  }O|dgz  }|S )Nindexr   z.. index:: defaultr3   refguidez   single: , r~   z: ,)r   r$   itemsr)   )r   idxrA   section
referencess        r   
_str_indexzSphinxDocString._str_index0  s    7ms88q= 	J6cggi446677#&99;; 	A 	AGZ)# AJ& A=dii
&;&;==>>?g??*)=)=??@@t
r   c                    g }| d         r||                      d          z  }t          | d         t                    r| d         g| d<   |                    | d                    |dgz  }|ddgz  }g }| d         D ]L}t	          j        d|t          j                  }|r(|                    |                    d                     M|dd	                    d |D                       z   dgz  }|S )	N
Referencesr3   z.. only:: latexz.. \[([a-z0-9._-]+)\]r   r~   r   c                     g | ]}d | d	S )[z]_r4   )r   items     r   
<listcomp>z3SphinxDocString._str_references.<locals>.<listcomp>Q  s     &F&F&F|4|||&F&F&Fr   )
r7   rd   strextendrk   matchIry   rn   r)   )r   rA   r   rB   rv   s        r   _str_referenceszSphinxDocString._str_referencesA  s    	M4##L111C$|,c22 :&*<&8%9\"JJtL)***B4KC %r**CE\* - -H5tRTBB -LL,,,EDII&F&F&F&F&FGGGLLC
r   c                 :   d                     | d                   }| j        ret          j        t          |          rKd|vrGg }||                     d          z  }|ddgz  }||                     | d                   z  }|dgz  }|S |                     d          S )Nr`   Exampleszplot::z	.. plot::r3   )r)   r   rk   rm   IMPORT_MATPLOTLIB_REr7   rC   r   )r   examples_strrA   s      r   _str_exampleszSphinxDocString._str_examplesT  s    yyj!122 N	1	.==	1 ,	1
 C4##J///CK$$C4##D$4555CB4KCJ$$Z000r   r   objc                 &   i d|                                  d|                                 d|                                 d|                                 d|                     d          d|                     d          d	|                     d
          d|                     d          d|                     d          d|                     d          d|                     d          d|                                 d|                     |          d|                     d          d| 	                                d| 
                                d| j        r|                     dd          n|                     d          d|                     d          i}d |                                D             } | j        j        d!i |}d                     |                     |                    d           |                    S )"N	signaturer   summaryextended_summary
parameters
ParametersreturnsrL   yieldsYieldsreceivesReceivesother_parameterszOther ParametersraisesRaiseswarnsWarnswarningsr   notesNotesr   examples
attributes
AttributesT)rp   methodsMethodsc                 @    i | ]\  }}|d                      |          S )r`   )r)   )r   kvs      r   
<dictcomp>z+SphinxDocString.__str__.<locals>.<dictcomp>|  s(    555$!Qa1555r   r`   r4   )rF   r   rI   rK   r{   rW   r   r   r   r   r   r   r   r   r   renderr)   rC   rl   )r   r@   r   nsrendereds        r   __str__zSphinxDocString.__str__e  sX   
,,..
T__&&
 t((**
  : : < <	

 $..|<<
 t((33
 d''11
 ))*55
  4 45G H H
 d''11
 T&&w//
 **,,
 **955
 T&&w//
 $..00
  **,,!
" ,5$..|d.SSS&&|44'
( t,,Y77)
 
, 65"((**555'4='--"--yy))(..*>*>GGHHHr   r   )r0   )r<   )rL   )F)r   r   )__name__
__module____qualname__r   r   r7   r;   rC   rF   rI   rK   rW   r\   rw   r{   r   r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r      s       ! ! ! !P P P+ + + +" " "     & & &/ / /   6  L# L# L#\. . . .`5 5 5n          "  &1 1 1"I I I I I I I Ir   r   c                       e Zd ZddZdS )SphinxFunctionDocNc                 h    |i }|                      |           t          j        | |||           d S Nr?   r   )r   r	   r   r   r   r?   r   s       r   r   zSphinxFunctionDoc.__init__  sC     	F   T3C??????r   NNr   r   r   r   r4   r   r   r   r     s.        @ @ @ @ @ @r   r   c                       e Zd ZddZdS )SphinxClassDocNc                 j    |i }|                      |           t          j        | ||d |           d S )N)r?   func_docr   )r   r
   r   )r   r   r?   r   r   s        r   r   zSphinxClassDoc.__init__  sE     	F   $tFKKKKKKr   )NNNr   r4   r   r   r   r     s.        L L L L L Lr   r   c                       e Zd ZddZdS )SphinxObjDocNc                 h    |i }|                      |           t          j        | |||           d S r   )r   r   r   r   s       r   r   zSphinxObjDoc.__init__  sB     	F   cs6::::::r   r   r   r4   r   r   r   r     s(        ; ; ; ; ; ;r   r   c                    |Ht          j        |           rd}n1t          j        |           rd}nt          | t                    rd}nd}|i }t
          j                            t
          j                            t                    d          g}|&t                      }|                    ||           nt          |          }t          |          }|                    d          |d	<   |dk    rt          | t           ||
          S |dv rt!          | ||          S |t#          j        |           }t'          | ||          S )Nclassmodulefunctionobjectr    )dirsr!   r#   r   )r   r?   r   )r   methodr   r   )rf   isclassismodulerd   r   r'   r(   r)   r*   r+   r   initr   r   r,   r   r   ri   rj   r   )r   whatr?   r   builderr-   r.   r/   s           r   get_doc_objectr     sf    ?3 	DDc"" 	DDX&& 	DDD W\\"'//(";";[IIJM :/11W=9999*=99'???L%223KLLF:w 5c,=3vVVVV	'	' 5 #f==== 	$,s##CCV4444r   )NNNN)rk   rf   r   ri   collections.abcr   r'   jinja2r   jinja2.sandboxr   sphinxsphinx.jinja2gluer   	docscraper   r	   r
   r   xrefr   r   r   r   r   r   r   r4   r   r   <module>r     s   				    $ $ $ $ $ $ 				 # # # # # # / / / / / /  3 3 3 3 3 3 D D D D D D D D D D D D       L kI kI kI kI kIn kI kI kI\@ @ @ @ @ @ @ @L L L L L_h L L L; ; ; ; ;?F ; ; ;5 5 5 5 5 5r   