B
    d@9                 @   s  d dl Z d dlmZmZmZmZmZ d dlm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 d d
lmZ d dlmZmZ d dlmZmZmZ d dlm Z  d dl!m"Z"m#Z# d dl$m%Z% d dl&m'Z' erd dl(m)Z) e *dZ+e,e-Z.e/e0dddZ1G dd de Z2G dd de Z3G dd deZ4G dd de Z5G dd de Z6G d d! d!e Z7G d"d# d#e Z8G d$d% d%e Z9G d&d' d'ee Zd(ee/ef d)d*d+Z:dS ),    N)TYPE_CHECKINGAnyDictListcast)nodes)ElementNode)
directives)BaseAdmonition)Class)Include)addnodes)VersionChange)___)docname_joinloggingurl_re)SphinxDirective)Matcher	patfilter)explicit_title_re)
OptionSpec)Sphinxz
.*[*?\[].*)argumentreturnc             C   s   | sdS t | S )Ni  )int)r    r   d/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sphinx/directives/other.pyint_or_nothing   s    r    c            
   @   sn   e Zd ZdZdZdZdZdZee	j
e	je	je	je	jee	je	jd	Zee dddZejee d	d
dZdS )TocTreez
    Directive to notify Sphinx about the hierarchical structure of the docs,
    and to include a table-of-contents like tree in the current document.
    Tr   F)	maxdepthnamecaptionglobhiddenincludehiddennumbered
titlesonlyreversed)r   c             C   s   t  }| jj|d< g |d< g |d< | jdd|d< | jd|d< d| jk|d< d| jk|d< d	| jk|d	< | jd
d|d
< d| jk|d< | | tjdgd}|	| | 
| | |}|	| |S )Nparententriesincludefilesr"   r$   r%   r&   r'   r(   r   r)   ztoctree-wrapper)classes)r   toctreeenvdocnameoptionsgetset_source_infor   ZcompoundappendZadd_nameparse_content)selfsubnodeZwrappernoderetr   r   r   run7   s$    




zTocTree.run)r0   r   c             C   s  t | jjd jd  }| jj}| jj |B }|	| jj
 g }t| jj}x | jD ]}|sfqZt|}|d rt|r|st|st| jj
|}	tt||	}
x@|
D ]8}||krq|	| |d d |f |d | qW |
sPtjtd||d qZ|r2|d}|d	}|}n| }}d }x.|D ]&}||rD|d t|  }P qDW t| jj
|}t|s|d
kr|d ||f qZ|| jj|B kr|| j|drtd}d}ntd}d}tj||d||d | j  qZ||kr|	| ntjtd||d |d ||f |d | qZW d| jkrtt |d |d< tt |d |d< |S )NZstdlabelsr%   r,   r-   z2toctree glob pattern %r didn't match any documents)location      r8   Fz2toctree contains reference to excluded document %rexcludedz5toctree contains reference to nonexisting document %rZnot_readableZtoc)typesubtyper=   z%duplicated entry found in toctree: %sr*   )!	frozensetr1   domainsZinitial_datakeysconfigZsource_suffixZ
found_docscopyremover2   r   Zexclude_patternscontentr   matchglob_rer   r   sortedr   r6   loggerwarningr   groupendswithlenZdoc2pathZnote_rereadr3   listr*   )r8   r0   Zgenerated_docnamessuffixesZall_docnamesr:   r@   entryexplicitZpatnameZdocnamesr2   reftitlesuffixmessagerB   r   r   r   r7   O   sn    







zTocTree.parse_contentN)__name__
__module____qualname____doc__has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   r
   Z	unchangedZunchanged_requiredflagr    option_specr   r	   r;   r   r0   r7   r   r   r   r   r!   "   s    
r!   c               @   s@   e Zd ZU dZdZdZdZdZi Ze	e
d< ee ddd	Zd
S )Authorz
    Directive to give the name of the author of the current document
    or section. Shown in the output only if the show_authors option is on.
    Fr?   r   Trc   )r   c             C   s   | j jsg S tjdd}t }||7 }| jdkr<td}n0| jdkrPtd}n| jdkrdtd}ntd	}|t|7 }| j	| j
d
 | j\}}|| |g}||7 }|S )NF)ZtranslatablesectionauthorzSection author: moduleauthorzModule author: 
codeauthorzCode author: zAuthor: r   )rF   Zshow_authorsr   	paragraphZemphasisr#   r   Textstateinline_text	argumentslinenoextend)r8   paraZemphtextinodesmessagesr:   r   r   r   r;      s$    






z
Author.runN)rZ   r[   r\   r]   r^   r_   r`   ra   rc   r   __annotations__r   r	   r;   r   r   r   r   rd      s   
rd   c               @   s   e Zd ZdZejZdS )SeeAlsozB
    An admonition mentioning things to look at as reference.
    N)rZ   r[   r\   r]   r   seealsoZ
node_classr   r   r   r   rt      s   rt   c               @   s@   e Zd ZU dZdZdZdZdZi Ze	e
d< ee ddd	Zd
S )TabularColumnszL
    Directive to give an explicit tabulary column definition to LaTeX.
    Fr?   r   Trc   )r   c             C   s&   t  }| jd |d< | | |gS )Nr   spec)r   Ztabular_col_specrl   r5   )r8   noder   r   r   r;      s    
zTabularColumns.runN)rZ   r[   r\   r]   r^   r_   r`   ra   rc   r   rs   r   r	   r;   r   r   r   r   rv      s   
rv   c               @   s@   e Zd ZU dZdZdZdZdZi Ze	e
d< ee ddd	Zd
S )Centeredz;
    Directive to create a centered line of bold text.
    Fr?   r   Trc   )r   c             C   sH   | j s
g S t }| j| j d | j\}}|| |g}||7 }|S )Nr   )rl   r   centeredrj   rk   rm   rn   )r8   r9   rq   rr   r:   r   r   r   r;      s    
zCentered.runN)rZ   r[   r\   r]   r^   r_   r`   ra   rc   r   rs   r   r	   r;   r   r   r   r   ry      s   
ry   c               @   s@   e Zd ZU dZdZdZdZdZi Ze	e
d< ee dddZd	S )
Acksz(
    Directive for a list of names.
    Tr   Frc   )r   c             C   sl   t  }| jj|_| j| j| j| t|jdksFt	|jd t
jsftjtd| jj| jfd g S |gS )Nr?   r   z.. acks content is not a list)r=   )r   acksrj   documentnested_parserI   content_offsetrQ   children
isinstancer   bullet_listrM   rN   r   r1   r2   rm   )r8   rx   r   r   r   r;      s    

zAcks.runN)rZ   r[   r\   r]   r^   r_   r`   ra   rc   r   rs   r   r	   r;   r   r   r   r   r{      s   
r{   c               @   sD   e Zd ZU dZdZdZdZdZdeiZ	e
ed< ee ddd	Zd
S )HListz@
    Directive for a list that gets compacted horizontally.
    Tr   Fcolumnsrc   )r   c             C   s  | j dd}t }| jj|_| j| j| j| t	|j
dksTt|j
d tjsttjtd| jj| jfd g S |j
d }tt	||\}}d}t }t||d< xVt|D ]J}|||k r|d n| }	t }
|
|j
||	 7 }
|td|
7 }|	}qW |gS )	Nr   r>   r?   r   z.. hlist content is not a list)r=   ncolumns )r3   r4   r   rh   rj   r}   r~   rI   r   rQ   r   r   r   rM   rN   r   r1   r2   rm   divmodr   hliststrrangeZhlistcol)r8   r   rx   ZfulllistZnpercolZnmoreindexZnewnodecolumnZendindexr   r   r   r   r;     s*    


z	HList.runN)rZ   r[   r\   r]   r^   r_   r`   ra   r   rc   r   rs   r   r	   r;   r   r   r   r   r      s   
r   c               @   s@   e Zd ZU dZdZdZdZdZi Ze	e
d< ee dddZd	S )
OnlyzI
    Directive to only include text if the given tag(s) are enabled.
    Tr?   r   rc   )r   c             C   s8  t  }| jj|_| | | jd |d< | jj}|j}|j}g |_d|_z| jj	| j
| j|dd |j}|r|r|d |ks| jjs|gS d}| jj}x|r|d7 }|j}qW |d8 }|d }t|}	||kr||}	||	 d }
ttj| jj}x t|
D ]}|jr |j}q W || g S ||_||_X d S )Nr   exprT)Zmatch_titlesr?   r>   )r   onlyrj   r}   r5   rl   memotitle_stylesZsection_levelr~   rI   r   r+   rQ   r   r   r   r   r   r6   )r8   rx   r   Zsurrounding_title_stylesZsurrounding_section_levelr   Zcurrent_depthr+   title_styleZnested_depthZn_sects_to_raiseZ_ir   r   r   r;   /  sJ    





zOnly.runN)rZ   r[   r\   r]   r^   r_   r`   ra   rc   r   rs   r   r	   r;   r   r   r   r   r   %  s   
r   c                   s*   e Zd ZdZee d fddZ  ZS )r   z
    Like the standard "Include" directive, but interprets absolute paths
    "correctly", i.e. relative to source directory.
    )r   c                s`   | j d dr*| j d dr*t  S | j| j d \}}|| j d< | j| t  S )Nr   <>)rl   
startswithrP   superr;   r1   Z
relfn2pathZnote_included)r8   Zrel_filenamefilename)	__class__r   r   r;   e  s    

zInclude.run)rZ   r[   r\   r]   r   r	   r;   __classcell__r   r   )r   r   r   _  s   r   r   )appr   c             C   s   t dt t dt t dt t dt t dt t dt t dt t dt t d	t t d
t	 t dt
 t dt t dt ddddS )Nr0   re   rf   rg   ru   Ztabularcolumnsrz   r|   r   r   includeZcssclassz	rst-classbuiltinT)versionZparallel_read_safeZparallel_write_safe)r
   Zregister_directiver!   rd   rt   rv   ry   r{   r   r   r   r   )r   r   r   r   setupp  s     r   );retypingr   r   r   r   r   Zdocutilsr   Zdocutils.nodesr   r	   Zdocutils.parsers.rstr
   Z+docutils.parsers.rst.directives.admonitionsr   Z$docutils.parsers.rst.directives.miscr   r   ZBaseIncludeZsphinxr   Zsphinx.domains.changesetr   Zsphinx.localer   r   Zsphinx.utilr   r   r   Zsphinx.util.docutilsr   Zsphinx.util.matchingr   r   Zsphinx.util.nodesr   Zsphinx.util.typingr   Zsphinx.applicationr   compilerK   	getLoggerrZ   rM   r   r   r    r!   rd   rt   rv   ry   r{   r   r   r   r   r   r   r   <module>   s<   

x"%: