
    ~TiD                        d dl mZ d dl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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 d dlmZm Z  er 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)  ejT                  e+      Z, G d dejZ                        Z- G d dej\                        Z. G d de      Z/ G d de      Z0 G d de      Z1d dZ2y)!    )annotationsN)Path)TYPE_CHECKINGcast)nodes)make_id)
directives)imagestables)Meta)optional_int)__)logging)SphinxDirective_normalize_options)set_source_info)SEPrelpath)Sequence)ClassVar)Node)Sphinx)ExtensionMetadata
OptionSpecc                  $     e Zd ZdZd fdZ xZS )FigureziThe figure directive which applies `:name:` option to the figure node
    instead of the image node.
    c                   | j                   j                  dd       }t        |          }t	        |      dk(  st        |d   t        j                        r|S t	        |      dk(  sJ t        d|d         }|r || j                   d<   | j                  |       |j                  .t	        |      dk(  r t        d|d         }|j                  |_
        |gS )Nname   r      znodes.figureznodes.caption)optionspopsuperrunlen
isinstancer   system_messager   add_nameline)selfr   resultfigure_nodecaption	__class__s        L/home/agent/.local/lib/python3.12/site-packages/sphinx/directives/patches.pyr$   z
Figure.run&   s    ||-v;!z&)U5I5IJM6{a>6!95#'DLL MM+& #K(8A(=?KN;G&||K}    )returnzSequence[Node]__name__
__module____qualname____doc__r$   __classcell__r.   s   @r/   r   r   !        r0   r   c                  $     e Zd ZdZd fdZ x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.
    c                   d| j                   v r,| j                   d   j                  t        t        j                  f      r| j
                  j                  j                  j                  }t        | j                   d         }|j                         rAt        j                  t        d      |j                  j                  | j                   f       ng|j"                  | j                   d   dd  z  }|j%                  |j                  j                        j&                  }t)        ||      | j                   d<   t*        | Y         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   current_documentdocnamelinenosrcdirdoc2pathparentr   r#   r$   )r*   rF   filenameabspathdoc_dirr.   s        r/   r$   zCSVTable.run@   s    T\\!dll6&:&E&EsBFFm&T**%%..22CDLL01H 7
 "22::DKKH   **t||F';AB'??,,s';';'C'CDKK'.w'@V$w{}r0   )r1   z,Sequence[nodes.table | nodes.system_message]r2   r8   s   @r/   r;   r;   ;   r9   r0   r;   c                  v    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Zy)
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_specTc                n   | j                          t        | j                        | _        dj                  | j                        }t        j                  ||| j                  j                  dg       d| j                  v i       }| j                  |       t        | |       | j                  r| j                  d   |d<   n;| j                  j                  j                  xs | j                  j                  |d<   d| j                  v r)d|d	<   | j                  d   r| j                  d   |d
   d<   |gS )N
classesrV   )r\   rV   highlight_argsr   languagerW   Tlinenosr]   linenostart)assert_has_contentr   r!   joincontentr   literal_blockgetr(   r   	argumentsrF   rJ   highlight_languageconfig)r*   codenodes      r/   r$   zCode.rund   s   !)$,,7yy&""LL$$Y3T\\)
 	dd#>>#~~a0D ))<< 2;;11 
 T\\)"DO ||N+8<^8T%&}5vr0   Nr1   
list[Node])r3   r4   r5   r6   optional_argumentsr	   class_optionflag	unchangedr   rY   __annotations__has_contentr$    r0   r/   rT   rT   U   sF    
 (($$$	)K%  K"r0   rT   c                      e Zd ZU dZdZdZdZej                  ej                  ej                  ej                  ej                  dZded<   d
dZddZy	)MathDirectiveTr   r    )labelr   rU   no-wrapnowraprX   rY   c                   d| j                   vr*d| j                   v r| j                   d   | j                   d<   dj                  | j                        }| j                  r$| j                  d   r| j                  d   dz   |z   }| j                   j	                  d| j                   j	                  d            }t        j                  ||| j                   j	                  dg       | j                  j                  j                  d |	      }d| j                   v x|d<   |d<   | j                  |       | j                  |       |g}| j                  |       |S )
Nrw   rx   r[   r   z

rv   r   rU   )r\   rK   numberrv   )r!   rb   rc   rf   re   r   
math_blockrF   rJ   rK   r(   r   
add_target)r*   latexrv   rj   rets        r/   r$   zMathDirective.run   s%    DLL(X-E&*ll8&<DLL#		$,,'>>dnnQ/NN1%.6E  $,,*:*:6*BCLL$$Wb1HH--55
 ,5+DDY$x.dT"&
r0   c                   t        d|d         }|d   dk(  s| j                  j                  rH|d   sC| j                  j	                  d      }| j                  j
                  j                   d| |d<   |d   sy | j                  j                  j                  }|j                  | j                  j
                  j                  |d   |       |j                  |d         |d<   t        d	|d   z        }t        j                  dd|g
      }| j                  j                  j!                  |       |j#                  d|       y )Nznodes.math_blockr   rv    zsphinx.ext.math#equations:r>   rz   zequation-%s)ids)r   rh   math_number_allrF   new_serialnorJ   rK   domainsmath_domainnote_equationget_equation_number_forr   r   targetrC   rD   note_explicit_targetinsert)r*   r~   rj   seqdomainnode_idr   s          r/   r|   zMathDirective.add_target   s'   &A/ =B4;;#>#>tG}((''(CDC#xx88@@A3%HDM G} !!--HH%%--tG}t 	 	
  77WFX -$w-78b"7)4

008

1fr0   Nrk   )r~   rl   r1   None)r3   r4   r5   rr   required_argumentsrm   final_argument_whitespacer	   rp   rn   ro   rY   rq   r$   r|   rs   r0   r/   ru   ru      s[    K $%%$$((??//)K% 6r0   ru   c                  Z    e Zd ZdZdZdZdZej                  ej                  d dZ
d	dZy)
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                .    t        j                  | d      S )N)123456)r	   choice)cs    r/   <lambda>zRubric.<lambda>   s    :#4#4Q8V#W r0   )rU   r   heading-levelc                n   t        | j                        | _        | j                  d   }| j                  || j                        \  }}d| j                  v r%t        | j                  d         | j                  d<   t        j                  |dg|i | j                  }| j                  |       |g|S )Nr   )rL   r   r   )	r   r!   rf   parse_inlinerL   intr   rubricr(   )r*   rubric_text	textnodesmessagesr   s        r/   r$   z
Rubric.run   s    )$,,7nnQ'"//DKK/P	8dll*,/_0M,NDLL)k2J	JT\\Jf"""r0   N)r1   z)list[nodes.rubric | nodes.system_message])r3   r4   r5   r6   r   rm   r   r	   rn   rp   rY   r$   rs   r0   r/   r   r      s<      $(($$WK#r0   r   c                F   t        j                  dt               t        j                  dt               t        j                  dt               t        j                  dt
               t        j                  dt               t        j                  dt               dddd	S )
Nfiguremetaz	csv-tableri   mathr   builtinT)versionparallel_read_safeparallel_write_safe)r	   register_directiver   r   r;   rT   ru   r   )apps    r/   setupr      sw    !!(F3!!&$/!!+x8!!&$/!!&-8!!(F3 "# r0   )r   r   r1   r   )3
__future__r   rA   pathlibr   typingr   r   docutilsr   docutils.nodesr   docutils.parsers.rstr	   docutils.parsers.rst.directivesr
   r   $docutils.parsers.rst.directives.miscr   sphinx.directivesr   sphinx.localer   sphinx.utilr   sphinx.util.docutilsr   r   sphinx.util.nodesr   sphinx.util.osutilr   r   collections.abcr   r   r   sphinx.applicationr   sphinx.util.typingr   r   	getLoggerr3   rH   r   r;   rT   ru   r   r   rs   r0   r/   <module>r      s    " 	  &  " + : 5 *   D - +(#)@ 
		8	$V]] 4v 41? 1h?O ?D#_ #2r0   