3

T'íc’	ã@s¼dZddlmZmZmZddlmZddlmZddl	Z	ddl
mZddlm
Z
ddlmZdd	lmZGd
d„dejƒZGdd
„d
e
ƒZeejeddœdd„Zeeeefdœdd„ZdS)aÕProvides the ``ifconfig`` directive.

The ``ifconfig`` directive enables writing documentation
that is included depending on configuration variables.

Usage::

    .. ifconfig:: releaselevel in ('alpha', 'beta', 'rc')

       This stuff is only included in the built docs for unstable versions.

The argument for ``ifconfig`` is a plain Python expression, evaluated in the
namespace of the project configuration (that is, all variables from
``conf.py`` are available.)
é)ÚAnyÚDictÚList)Únodes)ÚNodeN)ÚSphinx)ÚSphinxDirective)Únested_parse_with_titles)Ú
OptionSpecc@seZdZdS)ÚifconfigN)Ú__name__Ú
__module__Ú__qualname__©rrú5/tmp/pip-build-gk9425m9/sphinx/sphinx/ext/ifconfig.pyrsrc@s8eZdZUdZdZdZdZiZee	e
dœdd„ZdS)ÚIfConfigTér)ÚreturncCs>tƒ}|jj|_|j|ƒ|jd|d<t|j|j|ƒ|gS)NrÚexpr)rÚstateÚdocumentZset_source_infoÚ	argumentsr	Úcontent)ÚselfÚnoderrrÚrun)s

zIfConfig.runN)rr
rZhas_contentZrequired_argumentsZoptional_argumentsZfinal_argument_whitespaceZoption_specr
rrrrrrrr!s
r)ÚappÚdoctreeÚdocnamerc
CsÔdd„|jDƒ}|j|jjjƒƒ|jj|d<x |jtƒD]’}yt|d|ƒ}Wn^t	k
r®}zBddl
m}dj||j
|ƒƒ}|jjd||d	}	|j|	ƒWYdd}~Xq:X|sÀ|jgƒq:|j|jƒq:WdS)
NcSsi|]}|j|j“qSr)ÚvalueÚname)Ú.0Zconfvalrrrú
<dictcomp>3sz*process_ifconfig_nodes.<locals>.<dictcomp>Úbuilderrr)Úformat_exception_onlyÚz.Exception occurred in ifconfig expression: 
%s)Z	base_node)ÚconfigÚupdateÚ__dict__Úcopyr#r ÚfindallrÚevalÚ	ExceptionÚ	tracebackr$ÚjoinÚ	__class__ZreporterÚerrorZreplace_selfÚchildren)
rrrÚnsrÚresÚerrr$ÚmsgZnewnoderrrÚprocess_ifconfig_nodes2sr6)rrcCs.|jtƒ|jdtƒ|jdtƒtjddœS)Nrzdoctree-resolvedT)ÚversionZparallel_read_safe)Úadd_noderZ
add_directiverÚconnectr6ÚsphinxZ__display_version__)rrrrÚsetupHs
r;)Ú__doc__ÚtypingrrrZdocutilsrZdocutils.nodesrr:Zsphinx.applicationrZsphinx.util.docutilsrZsphinx.util.nodesr	Zsphinx.util.typingr
ÚElementrrrÚstrr6r;rrrrÚ<module>s