U
    \Sh}                     @  s^  d dl mZ d dlZd dl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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 d dl m!Z! d dl"m#Z#m$Z$m%Z% d dl&m'Z' erd dl(m)Z) e*e+Z,G dd dej-Z-G dd dej.Z.G dd deZ/G dd deZ0ddddd Z1dS )!    )annotationsN)path)TYPE_CHECKINGAnycast)nodes)Nodemake_id)
directives)imagestables)Meta)set_classes)optional_int)
MathDomain)__)logging)SphinxDirective)set_source_info)SEPos_pathrelpath)
OptionSpec)Sphinxc                      s&   e Zd ZdZdd fddZ  ZS )FigureziThe figure directive which applies `:name:` option to the figure node
    instead of the image node.
    
list[Node]returnc                   s   | j dd }t  }t|dks4t|d tjr8|S t|dksHtt	tj
|d }|rp|| j d< | | |jd krt|dkrt	tj|d }|j|_|gS )Nname   r      )optionspopsuperrunlen
isinstancer   Zsystem_messageAssertionErrorr   figureadd_namelinecaption)selfr   resultZfigure_noder+   	__class__ L/root/rtd-docs/venv/lib/python3.8/site-packages/sphinx/directives/patches.pyr$   #   s    


z
Figure.run__name__
__module____qualname____doc__r$   __classcell__r0   r0   r.   r1   r      s   r   c                      s&   e Zd ZdZdd fddZ  ZS )CSVTablezThe csv-table directive which searches a CSV file from Sphinx project's source
    directory when an absolute path is given via :file: option.
    r   r   c                   s   d| j kr| j d ttjfr| jjjj}| j d }t	
|r\tjtd|j| jfd nBt	|jt| j d dd  }t	||j}t||| j d< t  S )Nfilez":file:" option for csv-table directive now recognizes an absolute path as a relative path from source directory. Please update your document.locationr    )r!   
startswithr   ossepstatedocumentsettingsenvr   existsloggerwarningr   docnamelinenojoinsrcdirr   dirnameZdoc2pathr   r#   r$   )r,   rB   filenameabspathZdocdirr.   r0   r1   r$   =   s     



 zCSVTable.runr2   r0   r0   r.   r1   r8   8   s   r8   c                   @  sD   e Zd ZU dZdZejejeje	dZ
ded< dZddd	d
ZdS )CodezqParse and mark up content of a code block.

    This is compatible with docutils' :rst:dir:`code` directive.
    r    )classforcer   number-linesr   option_specTr   r   c                 C  s   |    t| j d| j}tj||| jdg d| jki d}| | t	| | | j
rl| j
d |d< n| jjd| jj|d< d| jkrd	|d
< | jd r| jd |d d< |gS )N
classesrO   )rS   rO   highlight_argsr   languagehighlight_languagerP   TZlinenosrT   Zlinenostart)Zassert_has_contentr   r!   rH   contentr   Zliteral_blockgetr)   r   	argumentsrB   Z	temp_dataconfigrV   )r,   codenoder0   r0   r1   r$   \   s(    





zCode.runN)r3   r4   r5   r6   optional_argumentsr
   class_optionflag	unchangedr   rQ   __annotations__has_contentr$   r0   r0   r0   r1   rM   N   s   
rM   c                   @  sZ   e Zd ZU dZdZdZdZejejej	ej
dZded< ddd	d
ZdddddZdS )MathDirectiveTr   r    )labelr   rN   nowrapr   rQ   r   r   c              	   C  s   d | j}| jr.| jd r.| jd d | }| jd| jd}tj||| jdg | jjd |d| jkd}| 	| | 
| |g}| | |S )	NrR   r   z

rd   r   rN   re   )rS   rF   numberrd   re   )rH   rW   rY   r!   rX   r   
math_blockrB   rF   r)   r   
add_target)r,   latexrd   r\   retr0   r0   r1   r$      s     


zMathDirective.runNone)rj   r   c                 C  s   t tj|d }|d dks,| jjrL|d sL| jd}d| jj|f |d< |d sXd S t t| j	d}|j
| jj|d |d ||d |d< td	|d  }tjdd|gd
}| jj| |d| d S )Nr   rd    zsphinx.ext.math#equationsz%s:%dmathr:   rf   zequation-%s)Zids)r   r   rg   rZ   Zmath_number_allrB   Znew_serialnorF   r   Z
get_domainZnote_equationZget_equation_number_forr	   targetr?   r@   Znote_explicit_targetinsert)r,   rj   r\   seqdomainZnode_idrn   r0   r0   r1   rh      s    zMathDirective.add_targetN)r3   r4   r5   rb   Zrequired_argumentsr]   Zfinal_argument_whitespacer
   r`   r^   r_   rQ   ra   r$   rh   r0   r0   r0   r1   rc   |   s   
rc   r   zdict[str, Any])appr   c                 C  sH   t dt t dt t dt t dt t dt ddddS )	Nr(   metaz	csv-tabler[   rm   builtinT)versionZparallel_read_safeZparallel_write_safe)r
   Zregister_directiver   r   r8   rM   rc   )rr   r0   r0   r1   setup   s    rv   )2
__future__r   r=   r   typingr   r   r   Zdocutilsr   Zdocutils.nodesr   r	   Zdocutils.parsers.rstr
   Zdocutils.parsers.rst.directivesr   r   Z$docutils.parsers.rst.directives.miscr   Zdocutils.parsers.rst.rolesr   Zsphinx.directivesr   Zsphinx.domains.mathr   Zsphinx.localer   Zsphinx.utilr   Zsphinx.util.docutilsr   Zsphinx.util.nodesr   Zsphinx.util.osutilr   r   r   Zsphinx.util.typingr   Zsphinx.applicationr   	getLoggerr3   rD   r   r8   rM   rc   rv   r0   r0   r0   r1   <module>   s2   
.6