
    Rtfn;                         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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y)    N)Callable)FileSystemLoader)SandboxedEnvironment)BuiltinTemplateLoader   )NumpyDocStringFunctionDocClassDocObjDoc)get_doc_object)	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 )SphinxDocStringc                 ^    |i }t        j                  | ||       | j                  |       y )N)config)r   __init__load_config)self	docstringr   s      ;/usr/lib/python3/dist-packages/numpydoc/docscrape_sphinx.pyr   zSphinxDocString.__init__   s,    >Fi?     c                 ^   |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        |j                  dd      | _        |j                  dt                     | _        |j                  dt                     | _        |j                  d	d       | _	        | j                  pt        j                  j                  t        j                  j                  t              d
      g}t        |      }t!        |      }|j#                  d      | _	        y y )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%+ZZ0G%N"(.

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

:t4== WW\\"''//(*C[QRM.}=O/GL(556NODM	 !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:r3   r   r4   s     r   _str_field_listzSphinxDocString._str_field_list.   s    d
S !!r   c                 0    g }|D ]  }|d|z  |z   gz  } |S )N r3   )r   docindentoutlines        r   _str_indentzSphinxDocString._str_indent1   s1     	)DC&L4'((C	)
r   c                     dgS )Nr2   r3   r   s    r   _str_signaturezSphinxDocString._str_signature7   s	    tr   c                     | d   dgz   S )NSummaryr2   r3   rC   s    r   _str_summaryzSphinxDocString._str_summary:   s    I"%%r   c                     | d   dgz   S )NzExtended Summaryr2   r3   rC   s    r   _str_extended_summaryz%SphinxDocString._str_extended_summary=   s    &'2$..r   c                 6   d}d}g }| |   r|| j                  |      z  }|dgz  }| |   D ]  }|j                  }|r-| j                  r!t        || j                  | j
                        }|j                  r3|| j                  ||j                  j                         |fz  g      z  }n&|| j                  ||j                         z  g      z  }|j                  s|| j                  dgd      z  }n|| j                  |j                  d      z  }|dgz  } |S )Nz**%s** : %sz%sr2   ..   )
r:   typer   r   r   r   r4   rA   stripdesc)r   r4   	named_fmtunnamed_fmtr?   param
param_types          r   _str_returnszSphinxDocString._str_returns@   s.   !	:4''--CB4KCd "ZZ
$"6"6!*"D$5$5t7G7G"J ::4++"ejj&6&6&8*%EEF C 4++[:;K;K;M-M,NOOCzz4++TFA66C4++EJJ::Ct!" 
r   c                 F    |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\*r3   r9   s     r   _escape_args_and_kwargsz'SphinxDocString._escape_args_and_kwargs[   sD    8tT!"X%%"1X_48##Kr   c                    | j                  |j                               }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	|j                         d
      d   }t        j                  ddj                  |j                                     }	|	r |	j!                  d
      j                         }n|j#                  d      d   }|j                  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.
        rW   N_namer2   .z:obj:`z <z>`z\n\s*\nr   r   z^([A-Z].*?\.)(?:\s|$)r<   
)rY   rN   getattr_objcallable
isinstancepropertyinspectisgetsetdescriptorismemberdescriptorpydocgetdocresplitsearchr)   group	partition)
r   rR   rO   fake_autosummarydisplay_param	param_objobj_docprefixlink_prefixms
             r   _process_paramzSphinxDocString._process_paramc   s]   D ,,U[[];
 UG2 $&&DIIud3	Y)X.)))4)))4I,,y)g $&&w+#HA,KK !r+ugR@88J;A>D 		2CHHTZZ\4JKAwwqz'')~~d+A.::d#Dd""r   c                    g }| |   r|| j                  |      z  }|dgz  }| |   D ]  }| j                  |j                  |j                  |      \  }}g }|r|j	                  |       |j
                  }|rJ|j
                  }| j                  r!t        || j                  | j                        }|j	                  |       || j                  dj                  |      g      z  }|sdg}|| j                  |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
        r2   z : rK   rL   )r:   rt   r4   rO   appendrM   r   r   r   r   rA   r)   )	r   r4   rm   r?   rR   rn   rO   partsrS   s	            r   _str_param_listzSphinxDocString._str_param_list   s   & :4''--CB4KCd &*&9&9JJ

,<'#t  LL/"ZZ
!&J++%.&(9(94;K;K&
 LL,t''E):(;<< 6Dt''a00t+. 
r   c                    g }| |   r|d| dgz  }t        | dd      }|rd| d}g }g }| |   D ]  }|j                  |j                  j                               }t        | j                  |j                  d      }t        |      s't        |t              st        j                  |      sd}|r+t        j                  |      r|d| |j                   gz  }|j                  |        |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 ]{  }d|j                  j                         z   dz   }dj                  d |j                   D              j                         }|j"                  rd|j"                   d| }||
||fz  gz  }} ||	gz  }|dgz  }|S )zp
        Generate a member listing, autosummary:: table where possible,
        and a table where not.

        r1   r2   r[   ~r\   )r4   N   z.. autosummary::z   :toctree:   c              3   L   K   | ]  }t        |j                        d z     yw)   N)lenr4   ).0ps     r   	<genexpr>z3SphinxDocString._str_member_list.<locals>.<genexpr>
  s     %F!c!&&kAo%Fs   "$=z  z
==========z%%%ds  %%s  rW   r<   c              3   <   K   | ]  }|j                           y wN)rN   )r   xs     r   r   z3SphinxDocString._str_member_list.<locals>.<genexpr>  s     #B!AGGI#Bs   (z) )r^   _replacer4   rN   r_   r`   ra   rb   rc   isdatadescriptorrf   rg   rv   r   maxr)   rO   rM   )r   r4   r?   rq   autosumothersrR   ro   maxlen_0hdrfmtrO   s               r   _str_member_listz SphinxDocString._str_member_list   s    :l4&)2..CT7B/FVHAGFd )EJJ,<,<,>? $DIIuzz4@	Y'!)X6//	: $Ii!8#fXejj\ :;;GMM%(!)$ *++--N++Ctg~%q#%Fv%F"FGHnt+h6${2B}$# 0E%**"2"2"44t;D88#Buzz#BBHHJDzz!"5::,b7C4,.//C0 uB4KC
r   c                     g }| |   rU|| j                  |      z  }t        j                  dj                  | |               j	                  d      }||z  }|dgz  }|S )Nr]   r2   )r6   textwrapdedentr)   ri   )r   r4   r?   contents       r   _str_sectionzSphinxDocString._str_section  sb    :4##D))CoodiiT
&;<BB4HG7NCB4KC
r   c                 j    g }| d   r*t         |   |      }ddg}|| j                  |dd        z  }|S )NzSee Alsoz.. seealso::r2   rV   )super_str_see_alsorA   )r   	func_roler?   see_also	__class__s       r   r   zSphinxDocString._str_see_also!  sI    
w,Y7H!2&C4##HQRL11C
r   c                 V    g }| d   r!ddg}|| j                  | d         z  }|dgz  }|S )NWarningsz.. warning::r2   )rA   )r   r?   s     r   _str_warningszSphinxDocString._str_warnings)  sC    
!2&C4##D$455CB4KC
r   c                     | d   }g }t        |      dk(  r|S |d|j                  dd       gz  }|j                         D ]D  \  }}|dk(  r|dk(  r|ddj                  |       gz  }*|d	| d
dj                  |       gz  }F |dgz  }|S )Nindexr   z.. index:: defaultr2   refguidez   single: , r{   z: ,)r   r$   itemsr)   )r   idxr?   section
referencess        r   
_str_indexzSphinxDocString._str_index1  s    7ms8q=J+cggi45677#&99; 	AGZ)#J&+dii
&;%<=>>#gYb*)=(>?@@	A 	t
r   c           
         g }| d   r|| j                  d      z  }t        | d   t              r	| d   g| d<   |j                  | d          |dgz  }|ddgz  }g }| d   D ]J  }t	        j
                  d|t        j                        }|s+|j                  |j                  d             L |ddj                  |D cg c]  }d| d	
 c}      z   dgz  }|S c c}w )
N
Referencesr2   z.. only:: latexz.. \[([a-z0-9._-]+)\]r   r{   r   [z]_)
r6   ra   strextendrh   matchIrv   rk   r)   )r   r?   r   r@   rs   items         r   _str_referenceszSphinxDocString._str_referencesB  s    4##L11C$|,c2&*<&8%9\"JJtL)*B4KC %r**CE\* -HH5tRTTBLL,- EDII&F4&|&FGGLLC
 'Gs   >Cc                    dj                  | d         }| j                  rZt        j                  t        |      r@d|vr<g }|| j                  d      z  }|ddgz  }|| j                  | d         z  }|dgz  }|S | j                  d      S )Nr]   Exampleszplot::z	.. plot::r2   )r)   r   rh   rj   IMPORT_MATPLOTLIB_REr6   rA   r   )r   examples_strr?   s      r   _str_exampleszSphinxDocString._str_examplesU  s    yyj!12 NN		.=,C4##J//CK$$C4##D$455CB4KCJ$$Z00r   c                    i d| j                         d| j                         d| j                         d| j                         d| j	                  d      d| j                  d      d	| j                  d
      d| j                  d      d| j	                  d      d| j                  d      d| j                  d      d| j                         d| j                  |      d| j                  d      d| j                         d| j                         d| j                  r| j	                  dd      n| j                  d      d| j                  d      i}|j                         D ci c]  \  }}|dj                  |       }}} | j                  j                   d i |}dj                  | j#                  |j%                  d      |            S c c}}w )!N	signaturer   summaryextended_summary
parameters
ParametersreturnsReturnsyieldsYieldsreceivesReceivesother_parameterszOther ParametersraisesRaiseswarnsWarnswarningsr   notesNotesr   examples
attributes
AttributesT)rm   methodsMethodsr]   r3   )rD   r   rG   rI   rx   rT   r   r   r   r   r   r   r   r   r)   r   renderrA   ri   )r   r>   r   nskvrendereds          r   __str__zSphinxDocString.__str__f  s!   
,,.
T__&
 t((*
  : : <	

 $..|<
 t((3
 d''1
 ))*5
  4 45G H
 d''1
 T&&w/
 **,
 **95
 T&&w/
 $..0
  **,!
" ,, ..|d.S&&|4'
( t,,Y7)
, +-((*5$!Qa1o55'4==''-"-yy))(..*>GHH 6s   3Gr   )`)r~   )r   )F)r   obj)__name__
__module____qualname__r   r   r6   r:   rA   rD   rG   rI   rT   rY   rt   rx   r   r   r   r   r   r   r   r   __classcell__)r   s   @r   r   r      sm    !P+"&/6L#\.`5n"&1"Ir   r   c                       e Zd ZddZy)SphinxFunctionDocNc                 `    |i }| j                  |       t        j                  | |||       y N)r=   r   )r   r	   r   r   r   r=   r   s       r   r   zSphinxFunctionDoc.__init__  s.    >F T3C?r   NNr   r   r   r   r3   r   r   r   r     s    @r   r   c                       e Zd ZddZy)SphinxClassDocNc                 b    |i }| j                  |       t        j                  | ||d |       y )N)r=   func_docr   )r   r
   r   )r   r   r=   r   r   s        r   r   zSphinxClassDoc.__init__  s0    >F $tFKr   )NNNr   r3   r   r   r   r     s    Lr   r   c                       e Zd ZddZy)SphinxObjDocNc                 `    |i }| j                  |       t        j                  | |||       y r   )r   r   r   r   s       r   r   zSphinxObjDoc.__init__  s,    >F cs6:r   r   r   r3   r   r   r   r     s    ;r   r   c           	      `   |i }t         j                  j                  t         j                  j                  t              d      g}|t               }|j                  ||       nt        |      }t        |      }|j                  d      |d<   t        | |||t        t        t              S )Nr    )dirsr!   r#   r   )whatr=   r   	class_docr   rp   )r'   r(   r)   r*   r+   r   initr   r   r,   get_doc_object_origr   r   r   )r   r   r=   r   builderr-   r.   r/   s           r   r   r     s    ~WW\\"''//(";[IJM/1W=9*=9'?L%223KLF: " r   )NNNN)rh   rc   r   rf   collections.abcr   r'   jinja2r   jinja2.sandboxr   sphinxsphinx.jinja2gluer   	docscraper   r	   r
   r   r   r   xrefr   r   r   r   r   r   r3   r   r   <module>r      s|    	    $ 	 # /  3 D D <  L kIn kI\@ @L_h L;?F ;r   