o
    Ni                     @  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!m"Z"m#Z# erzd dl$m%Z% d dl&m'Z'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Z/G dd deZ0d#d!d"Z1dS )$    )annotationsN)path)TYPE_CHECKINGClassVarcast)nodes)Nodemake_id)
directives)imagestables)Meta)set_classes)optional_int)__)logging)SphinxDirective)set_source_info)SEPos_pathrelpath)Sphinx)ExtensionMetadata
OptionSpecc                      "   e Zd ZdZd fddZ  ZS )FigureziThe figure directive which applies `:name:` option to the figure node
    instead of the image node.
    return
list[Node]c                   s   | j dd }t  }t|dkst|d tjr|S t|dks$J ttj	|d }|r8|| j d< | 
| |jd u rOt|dkrOttj|d }|j|_|gS )Nname   r      )optionspopsuperrunlen
isinstancer   system_messager   figureadd_namelinecaption)selfr   resultfigure_noder+   	__class__ M/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/directives/patches.pyr$   "   s   


z
Figure.runr   r   __name__
__module____qualname____doc__r$   __classcell__r1   r1   r/   r2   r          r   c                      r   )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 v rO| j d ttjfrO| jjjj}| j d }t	
|r.tjtd|j| jfd n!t	|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   dirnamedoc2pathr   r#   r$   )r,   rE   filenameabspathdocdirr/   r1   r2   r$   <   s    


 	
zCSVTable.runr3   r4   r1   r1   r/   r2   r;   7   r:   r;   c                   @  s@   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
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-linesClassVar[OptionSpec]option_specTr   r   c                 C  s   |    t| j d| j}tj||| jdg d| jv i d}| | t	| | | j
r6| j
d |d< n| jjd| jj|d< d| jv rYd	|d
< | jd rY| jd |d d< |gS )N
classesrT   )rY   rT   highlight_argsr   languagehighlight_languagerU   TlinenosrZ   linenostart)assert_has_contentr   r!   rK   contentr   literal_blockgetr)   r   	argumentsrE   	temp_dataconfigr\   )r,   codenoder1   r1   r2   r$   `   s,   




zCode.runNr3   )r5   r6   r7   r8   optional_argumentsr
   class_optionflag	unchangedr   rW   __annotations__has_contentr$   r1   r1   r1   r2   rR   Q   s   
 rR   c                   @  sP   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
ZdddZdS )MathDirectiveTr   r    )labelr   rS   nowraprV   rW   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v d}| 	| | 
| |g}| | |S )	NrX   r   z

ro   r   rS   rp   )rY   rI   numberro   rp   )rK   r`   rc   r!   rb   r   
math_blockrE   rI   r)   r   
add_target)r,   latexro   rg   retr1   r1   r2   r$      s$   
	

zMathDirective.runru   Nonec                 C  s   t tj|d }|d dks| jjr'|d s'| jd}| jj d| |d< |d s-d S | jjj	}|j
| jj|d |d ||d |d< td|d  }tjdd|gd	}| jj| |d| d S )
Nr   ro    zsphinx.ext.math#equations:r=   rq   zequation-%s)ids)r   r   rr   re   math_number_allrE   new_serialnorI   domainsmath_domainnote_equationget_equation_number_forr	   targetrB   rC   note_explicit_targetinsert)r,   ru   rg   seqdomainnode_idr   r1   r1   r2   rs      s   
zMathDirective.add_targetNr3   )ru   r   r   rv   )r5   r6   r7   rm   required_argumentsrh   final_argument_whitespacer
   rk   ri   rj   rW   rl   r$   rs   r1   r1   r1   r2   rn      s   
 
rn   c                   @  s:   e Zd ZdZdZdZdZejej	dd dZ
dd
dZdS )RubriczA patch of the docutils' :rst:dir:`rubric` directive,
    which adds a level option to specify the heading level of the rubric.
    r    r   Tc                 C  s   t | dS )N)123456)r
   choice)cr1   r1   r2   <lambda>   s    zRubric.<lambda>)rS   r   heading-levelr   )list[nodes.rubric | nodes.system_message]c                 C  sv   t | j | jd }| j|| jd\}}d| jv r#t| jd | jd< tj|dg|R i | j}| | |g|S )Nr   )rJ   r   rw   )	r   r!   rc   parse_inlinerJ   intr   rubricr)   )r,   rubric_text	textnodesmessagesr   r1   r1   r2   r$      s   




z
Rubric.runN)r   r   )r5   r6   r7   r8   r   rh   r   r
   ri   rk   rW   r$   r1   r1   r1   r2   r      s    r   appr   r   r   c                 C  sT   t dt t dt t dt t dt t dt t dt dddd	S )
Nr(   metaz	csv-tablerf   mathr   builtinT)versionparallel_read_safeparallel_write_safe)r
   register_directiver   r   r;   rR   rn   r   )r   r1   r1   r2   setup   s   r   )r   r   r   r   )2
__future__r   r@   r   typingr   r   r   docutilsr   docutils.nodesr   r	   docutils.parsers.rstr
   docutils.parsers.rst.directivesr   r   $docutils.parsers.rst.directives.miscr   docutils.parsers.rst.rolesr   sphinx.directivesr   sphinx.localer   sphinx.utilr   sphinx.util.docutilsr   sphinx.util.nodesr   sphinx.util.osutilr   r   r   sphinx.applicationr   sphinx.util.typingr   r   	getLoggerr5   rG   r   r;   rR   rn   r   r   r1   r1   r1   r2   <module>   s4    
39