o
    Ni                      @  s  d Z ddlmZ ddlZddlZddlmZmZmZm	Z	 ddl
m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 dd
lmZ ddlmZmZ ddlmZmZ ddlmZmZ erd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)m*Z* ddl+m,Z, ddl-m.Z. e/e0Z1G dd dej2ej"Z3G dd dej4ej"Z5G dd deeZ6G dd deZ7G dd deZ8G dd  d Z9d4d&d'Z:d4d(d)Z;d5d+d,Z<d5d-d.Z=d6d2d3Z>dS )7zAllow todos to be inserted into your documentation.

Inclusion of todos can be switched of by a configuration variable.
The todolist directive collects all todos of your project and lists them along
with a backlink to the original location.
    )annotationsN)TYPE_CHECKINGAnyClassVarcast)nodes)
directives)BaseAdmonition)addnodes)Domain)NoUri)___)logging	texescape)SphinxDirectivenew_document)Set)ElementNode)Sphinx)BuildEnvironment)ExtensionMetadata
OptionSpec)HTML5Translator)LaTeXTranslatorc                   @     e Zd ZdS )	todo_nodeN__name__
__module____qualname__ r"   r"   C/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/ext/todo.pyr   (       r   c                   @  r   )todolistNr   r"   r"   r"   r#   r%   ,   r$   r%   c                      sN   e Zd ZU dZeZdZdZdZdZ	e
je
jdZded< d fd
dZ  ZS )TodozO
    A todo entry, displayed (if configured) in the form of an admonition.
    Tr   F)classnameClassVar[OptionSpec]option_specreturn
list[Node]c                   s   | j dsdg| j d< t  \}t|tjr|gS t|trF|dtj	t
dd | jj|d< | | | | | jj| |gS t)Nr'   zadmonition-todor   r&   )textdocname)optionsgetsuperrun
isinstancer   system_messager   inserttitler   envr.   add_nameset_source_infostatedocumentnote_explicit_targetRuntimeError)selftodo	__class__r"   r#   r2   ?   s   


zTodo.runr+   r,   )r   r    r!   __doc__r   
node_classhas_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   class_option	unchangedr*   __annotations__r2   __classcell__r"   r"   r@   r#   r&   0   s   
 r&   c                   @  s@   e Zd ZdZdZedddZdd	d
ZdddZdddZ	dS )
TodoDomainr?   r+   dict[str, list[todo_node]]c                 C  s   | j di S Ntodos)data
setdefaultr>   r"   r"   r#   rP   U   s   zTodoDomain.todosr.   strNonec                 C  s   | j |d  d S N)rP   pop)r>   r.   r"   r"   r#   	clear_docY   s   zTodoDomain.clear_docdocnamesSet[str]	otherdatadict[str, Any]c                 C  s    |D ]}|d | | j |< qd S rO   )rP   )r>   rY   r[   r.   r"   r"   r#   merge_domaindata\   s   zTodoDomain.merge_domaindatar7   r   r;   nodes.documentc                 C  s^   | j |g }|tD ] }|jd| || |jjr,t	j
td|d  |d qd S )Ntodo-definedzTODO entry found: %s   )location)rP   rR   findallr   appemitappendconfigtodo_emit_warningsloggerwarningr   astext)r>   r7   r.   r;   rP   r?   r"   r"   r#   process_doc`   s   
zTodoDomain.process_docN)r+   rN   )r.   rT   r+   rU   )rY   rZ   r[   r\   r+   rU   )r7   r   r.   rT   r;   r^   r+   rU   )
r   r    r!   r(   labelpropertyrP   rX   r]   rk   r"   r"   r"   r#   rM   Q   s    

rM   c                   @  s8   e Zd ZU dZdZdZdZdZi Zde	d< ddd	Z
d
S )TodoListz%
    A list of all todo entries.
    Fr   r)   r*   r+   r,   c                 C  s
   t dgS )N )r%   rS   r"   r"   r#   r2   w   s   
zTodoList.runNrB   )r   r    r!   rC   rE   rF   rG   rH   r*   rK   r2   r"   r"   r"   r#   rn   l   s   
 rn   c                   @  s4   e Zd Zdd	d
ZdddZdddZdddZdS )TodoListProcessorrc   r   doctreer^   r.   rT   r+   rU   c                 C  s@   |j | _ |j| _|j| _|jjd | _td| _| || d S )Nr?   ro   )builderrf   r7   domainsdomainr   r;   process)r>   rc   rq   r.   r"   r"   r#   __init__~   s   
zTodoListProcessor.__init__c           	      C  s   t tj| jj g }t|t	D ]D}| j
js |j| q|dr+t g}ng }|D ]"}| }|d   | || || | ||}|| q/|| qd S )Nids)	functoolsreduceoperatoriaddrt   rP   valueslistrb   r%   rf   todo_include_todosparentremover0   r   targetdeepcopyclearresolve_referencere   create_todo_referencereplace_self)	r>   rq   r.   rP   nodecontentr?   new_todotodo_refr"   r"   r#   ru      s&   

zTodoListProcessor.processr?   r   nodes.paragraphc           	      C  s   | j jr	td}n
td|j|jf }|d |d }||dd d  }tjdgd}|t|7 }t	tdtd}tj
d	d	|d
d}z| j||d |d< |d  d|d d  7  < W n	 tyl   Y nw ||7 }|t|7 }|S )Nz<<original entry>>z3(The <<original entry>> is located in %s, line %d.)z<<z>>   ztodo-source)classeszoriginal entryro   T)internalr.   refuri#rw   r   )rf   todo_link_onlyr   sourcelinefindr   	paragraphTextemphasis	referencerr   get_relative_urir   )	r>   r?   r.   descriptionprefixsuffixparalinktextr   r"   r"   r#   r      s(   

 z'TodoListProcessor.create_todo_referencec                 C  sT   | tjD ]
}d|v r||d< q|  j|7  _| j| j|| j | j| dS )z'Resolve references in the todo content.refdocN)rb   r
   pending_xrefr;   r7   resolve_referencesrr   r   )r>   r?   r.   r   r"   r"   r#   r      s   z#TodoListProcessor.resolve_referenceN)rc   r   rq   r^   r.   rT   r+   rU   )rq   r^   r.   rT   r+   rU   )r?   r   r.   rT   r+   r   )r?   r   r.   rT   r+   rU   )r   r    r!   rv   ru   r   r   r"   r"   r"   r#   rp   }   s
    

	
rp   r>   r   r   r+   rU   c                 C  s   | j jr| | d S tjrV   )rf   r~   visit_admonitionr   SkipNoder>   r   r"   r"   r#   visit_todo_node   s   r   c                 C  s   |  | d S rV   )depart_admonitionr   r"   r"   r#   depart_todo_node   s   r   r   c                 C  s   | j jrB| jd | j| | ttj|d }t	|
 | j j}| jd|  |  jd7  _| jr;d| j_|d d S tj)Nz
\begin{sphinxtodo}{r   z%s:}r`   T)rf   r~   bodyre   hypertarget_tor   r   r6   r   escaperj   latex_engineno_latex_floatstablehas_problematicrW   r   )r>   r   
title_noder6   r"   r"   r#   latex_visit_todo_node   s   r   c                 C  s   | j d |  jd8  _d S )Nz\end{sphinxtodo}
r`   )r   re   r   r   r"   r"   r#   latex_depart_todo_node   s   r   rc   r   r   c                 C  s   |  d | ddd | ddd | ddd | t | jtttfttfttfttfttfd | 	dt
 | 	d	t | t | d
t tjdddS )Nr_   r~   Fhtmlr   rg   )r   latexr-   mantexinfor?   r%   zdoctree-resolvedr   T)versionenv_versionparallel_read_safe)	add_eventadd_config_valueadd_noder%   r   r   r   r   r   add_directiver&   rn   
add_domainrM   connectrp   sphinx__display_version__)rc   r"   r"   r#   setup   s(   


r   )r>   r   r   r   r+   rU   )r>   r   r   r   r+   rU   )rc   r   r+   r   )?rC   
__future__r   rx   rz   typingr   r   r   r   docutilsr   docutils.parsers.rstr   +docutils.parsers.rst.directives.admonitionsr	   r   r
   sphinx.domainsr   sphinx.errorsr   sphinx.localer   r   sphinx.utilr   r   sphinx.util.docutilsr   r   collections.abcr   docutils.nodesr   r   sphinx.applicationr   sphinx.environmentr   sphinx.util.typingr   r   sphinx.writers.html5r   sphinx.writers.latexr   	getLoggerr   rh   
Admonitionr   Generalr%   r&   rM   rn   rp   r   r   r   r   r   r"   r"   r"   r#   <module>   sF    
!
L


