
    Ri	                        d 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	 erddlm
Z
 ddlmZ dd	lmZ dd
lmZ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)nodesN)SphinxDirective)ClassVar)Node)Sphinx)ExtensionMetadata
OptionSpecc                      e Zd Zy)ifconfigN)__name__
__module____qualname__     K/home/agent/.friday_env/lib/python3.12/site-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   zClassVar[OptionSpec]option_specc                    t               }| j                  j                  |_        | j                  |       | j                  d   |d<   || j                  d      z  }|gS )Nr   exprT)allow_section_headings)r   statedocumentset_source_info	argumentsparse_content_to_nodes)selfnodes     r   runzIfConfig.run.   sY    z

++T"~~a(V++4+HH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|	 |      }
|j                  |
       Y d }~d }~ww xY w)Nbuilderr   r   )format_exception_only z,Exception occurred in ifconfig expression: 
)	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&&,,?uEQU - 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   N   sD    LLj(+KK"$:;--" r   )r?   r	   r@   znodes.documentrA   strr#   None)r?   r	   r#   r
   )__doc__
__future__r   typingr   docutilsr   rO   sphinx.util.docutilsr   r   docutils.nodesr   sphinx.applicationr	   sphinx.util.typingr
   r   Elementr   r   rH   rQ   r   r   r   <module>r]      sP     #     0#)@	u}} 	  1.r   