3

T'ícaã@sÆdZddlmZmZmZmZmZddlmZddl	m
Z
mZddlm
Z
ddlmZddlZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZddlmZmZddl m!Z!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ej)e*ƒZ+Gdd„dej,ej
ƒZ-Gdd„dej.ej
ƒZ/Gdd„dee!ƒZ0Gdd„deƒZ1Gdd„de!ƒZ2Gdd„dƒZ3e&e-ddœd d!„Z4e&e-ddœd"d#„Z5e(e-ddœd$d%„Z6e(e-ddœd&d'„Z7eee8efd(œd)d*„Z9dS)+zñAllow 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.
é)ÚAnyÚDictÚListÚTupleÚcast)Únodes)ÚElementÚNode)Ú
directives)ÚBaseAdmonitionN)Úaddnodes)ÚSphinx)ÚDomain)ÚBuildEnvironment)ÚNoUri)Ú_Ú__)ÚloggingÚ	texescape)ÚSphinxDirectiveÚnew_document)Ú
OptionSpec)ÚHTMLTranslator)ÚLaTeXTranslatorc@seZdZdS)Ú	todo_nodeN)Ú__name__Ú
__module__Ú__qualname__©rrú1/tmp/pip-build-gk9425m9/sphinx/sphinx/ext/todo.pyrsrc@seZdZdS)ÚtodolistN)rrrrrrrr #sr csReZdZUdZeZdZdZdZdZ	e
je
jdœZ
e
eedœ‡fdd„Z‡ZS)	ÚTodozO
    A todo entry, displayed (if configured) in the form of an admonition.
    TrF)ÚclassÚname)Úreturncs”|jjdƒsdg|jd<tƒjƒ\}t|tjƒr6|gSt|tƒrŒ|jdtj	t
dƒdƒ|jj|d<|j
|ƒ|j|ƒ|jjj|ƒ|gSt‚dS)Nr"zadmonition-todorr!)ÚtextÚdocname)ÚoptionsÚgetÚsuperÚrunÚ
isinstancerZsystem_messagerÚinsertÚtitlerÚenvr&Zadd_nameZset_source_infoÚstateÚdocumentZnote_explicit_targetÚRuntimeError)ÚselfÚtodo)Ú	__class__rrr*6s


zTodo.run)rrrÚ__doc__rZ
node_classÚhas_contentÚrequired_argumentsÚoptional_argumentsÚfinal_argument_whitespacer
Zclass_optionZ	unchangedÚoption_specrrr	r*Ú
__classcell__rr)r4rr!'s
r!c@sneZdZdZdZeeeee	fdœdd„ƒZ
eddœdd„Zeeedd	œd
d„Ze
eejddœd
d„ZdS)Ú
TodoDomainr3)r$cCs|jjdiƒS)NÚtodos)ÚdataÚ
setdefault)r2rrrr=LszTodoDomain.todosN)r&r$cCs|jj|dƒdS)N)r=Úpop)r2r&rrrÚ	clear_docPszTodoDomain.clear_doc)ÚdocnamesÚ	otherdatar$cCs$x|D]}|d||j|<qWdS)Nr=)r=)r2rBrCr&rrrÚmerge_domaindataSs
zTodoDomain.merge_domaindata)r.r&r0r$cCsb|jj|gƒ}xN|jtƒD]@}|jjd|ƒ|j|ƒ|jjrt	j
tdƒ|djƒ|dqWdS)Nztodo-definedzTODO entry found: %sé)Úlocation)
r=r?ÚfindallrÚappÚemitÚappendÚconfigÚtodo_emit_warningsÚloggerÚwarningrÚastext)r2r.r&r0r=r3rrrÚprocess_docWs
zTodoDomain.process_doc)rrrr#ÚlabelÚpropertyrÚstrrrr=rArDrrr0rPrrrrr<Hsr<c@s<eZdZUdZdZdZdZdZiZe	e
edœdd„ZdS)ÚTodoListz%
    A list of all todo entries.
    Fr)r$cCs
tdƒgS)NÚ)r )r2rrrr*nszTodoList.runN)
rrrr5r6r7r8r9r:rrr	r*rrrrrTcs
rTc@s\eZdZeejeddœdd„Zejeddœdd„Ze	eej
dœd	d
„Ze	eddœdd„ZdS)
ÚTodoListProcessorN)rHÚdoctreer&r$cCsF|j|_|j|_|j|_tt|jjdƒƒ|_tdƒ|_|j	||ƒdS)Nr3rU)
ÚbuilderrKr.rr<Z
get_domainÚdomainrr0Úprocess)r2rHrWr&rrrÚ__init__us
zTodoListProcessor.__init__)rWr&r$c	Cs¶t|jjjƒgƒ}xžt|jtƒƒD]Œ}|jjs<|j	j
|ƒq"|jdƒrRtj
ƒg}ng}xL|D]D}|jƒ}|djƒ|j||ƒ|j|ƒ|j||ƒ}|j|ƒq\W|j|ƒq"WdS)NÚids)ÚsumrYr=ÚvaluesÚlistrGr rKÚtodo_include_todosÚparentÚremover(rÚtargetÚdeepcopyÚclearÚresolve_referencerJÚcreate_todo_referenceZreplace_self)	r2rWr&r=ÚnodeÚcontentr3Znew_todoZtodo_refrrrrZ~s 


zTodoListProcessor.process)r3r&r$c	Csú|jjrtdƒ}ntdƒ|j|jf}|d|jdƒ…}||jdƒdd…}tjdgd}|tj||ƒ7}tj	tdƒtdƒƒ}tj
d	d	|d
d}y6|jj||dƒ|d
<|d
d|dd7<Wnt
k
rÜYnX||7}|tj||ƒ7}|S)Nz<<original entry>>z3(The <<original entry>> is located in %s, line %d.)z<<z>>éztodo-source)Úclasseszoriginal entryrUT)Zinternalr&Zrefuriú#r\r)rKÚtodo_link_onlyrÚsourceÚlineÚfindrÚ	paragraphZTextZemphasisÚ	referencerXZget_relative_urir)	r2r3r&ÚdescriptionÚprefixÚsuffixÚparaZlinktextrrrrrrg—s$
 z'TodoListProcessor.create_todo_referencecCsXx$|jtjƒD]}d|kr||d<qW|j|7_|jj|j||jƒ|jj|ƒdS)z'Resolve references in the todo content.ZrefdocN)rGrZpending_xrefr0r.Zresolve_referencesrXrb)r2r3r&rhrrrrf³sz#TodoListProcessor.resolve_reference)
rrrr
rr0rSr[rZrrqrgrfrrrrrVts	rV)r2rhr$cCs|jjr|j|ƒntj‚dS)N)rKr`Zvisit_admonitionrÚSkipNode)r2rhrrrÚvisit_todo_node¿srxcCs|j|ƒdS)N)Zdepart_admonition)r2rhrrrÚdepart_todo_nodeÆsrycCsp|jjrf|jjdƒ|jj|j|ƒƒttj|dƒ}tj	|j
ƒ|jjƒ}|jjd|ƒ|jdƒntj
‚dS)Nz 
\begin{sphinxadmonition}{note}{rz%s:})rKr`ÚbodyrJZhypertarget_torrr-rÚescaperOZlatex_enginer@rw)r2rhZ
title_noder-rrrÚlatex_visit_todo_nodeÊsr|cCs|jjdƒdS)Nz\end{sphinxadmonition}
)rzrJ)r2rhrrrÚlatex_depart_todo_node×sr})rHr$cCs¤|jdƒ|jdddƒ|jdddƒ|jdddƒ|jtƒ|jtttfttfttfttfttfd|j	dt
ƒ|j	d	tƒ|jt
ƒ|jd
tƒtjddd
œS)Nztodo-definedr`FÚhtmlrmrL)r~Zlatexr%ZmanZtexinfor3r zdoctree-resolvedrjT)ÚversionZenv_versionZparallel_read_safe)Z	add_eventZadd_config_valueÚadd_noder rrxryr|r}Z
add_directiver!rTZ
add_domainr<ÚconnectrVÚsphinxZ__display_version__)rHrrrÚsetupÛs$


rƒ):r5ÚtypingrrrrrZdocutilsrZdocutils.nodesrr	Zdocutils.parsers.rstr
Z+docutils.parsers.rst.directives.admonitionsrr‚rZsphinx.applicationr
Zsphinx.domainsrZsphinx.environmentrZ
sphinx.errorsrZ
sphinx.localerrZsphinx.utilrrZsphinx.util.docutilsrrZsphinx.util.typingrZsphinx.writers.htmlrZsphinx.writers.latexrÚ	getLoggerrrMZ
AdmonitionrZGeneralr r!r<rTrVrxryr|r}rSrƒrrrrÚ<module>s:
!K