
    Fe
                        d Z ddlmZ ddlmZmZ ddlmZ ddlZddl	m
Z
 ddlmZ erddlmZ dd	lmZ dd
lmZ  G d dej&                        Z G d de
      ZddZddZy)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.)
    )annotations)TYPE_CHECKINGAny)nodesN)SphinxDirective)nested_parse_with_titles)Node)Sphinx)
OptionSpecc                      e Zd Zy)ifconfigN)__name__
__module____qualname__     5/usr/lib/python3/dist-packages/sphinx/ext/ifconfig.pyr   r   "   s    r   r   c                  4    e Zd ZU dZdZdZdZi Zded<   ddZ	y)	IfConfigT   r   r   option_specc                    t               }| j                  j                  |_        | j                  |       | j                  d   |d<   t        | j                  | j                  || j                         |gS )Nr   expr)r   statedocumentset_source_info	argumentsr   contentcontent_offset)selfnodes     r   runzIfConfig.run.   s]    z

++T"~~a(V T\\4ATATUvr   N)returnz
list[Node])
r   r   r   has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   __annotations__r"   r   r   r   r   r   &   s(    K $ K r   r   c                   | j                   D ci c]  }|j                  |j                   }}|j                  | j                   j                  j                                | j                  j                  |d<   t        |j                  t                    D ]A  }	 t        |d   |      }|s|j                  g        '|j                  |j                         C y c c}w # t        $ rc}ddlm} dj!                   ||j"                  |            }	|j$                  j'                  d|	z  |      }
|j                  |
       Y d }~d }~ww xY w)Nbuilderr   r   )format_exception_only z.Exception occurred in ifconfig expression: 
%s)	base_node)confignamevalueupdate__dict__copyr*   listfindallr   evalreplace_selfchildren	Exception	tracebackr+   join	__class__reportererror)appdoctreedocnameconfvalnsr!   reserrr+   msgnewnodes              r   process_ifconfig_nodesrH   7   s$   58ZZ	@'',,
%	@B	@IIcjj!!&&()KK$$ByMW__X./ 1	1tF|R(C !!"%!!$--01 
A  	'7''/sCDC&&,, .I-0.1<@ - BG g&&	's   CC##	E,AE

Ec                    | j                  t               | j                  dt               | j	                  dt
               t        j                  ddS )Nr   zdoctree-resolvedT)versionparallel_read_safe)add_noder   add_directiver   connectrH   sphinx__display_version__)r?   s    r   setuprQ   M   s?    LLj(+KK"$:;11NNr   )r?   r
   r@   znodes.documentrA   strr#   None)r?   r
   r#   zdict[str, Any])__doc__
__future__r   typingr   r   docutilsr   rO   sphinx.util.docutilsr   sphinx.util.nodesr   docutils.nodesr	   sphinx.applicationr
   sphinx.util.typingr   Elementr   r   rH   rQ   r   r   r   <module>r^      sQ     # %   0 6#)-	u}} 	 "1,Or   