o
    Ni	                     @  s   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
 er6ddlmZ ddlmZ dd	lmZmZ G d
d dejZG dd de
ZdddZdddZdS )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ClassVar)nodesN)SphinxDirective)Node)Sphinx)ExtensionMetadata
OptionSpecc                   @  s   e Zd ZdS )ifconfigN)__name__
__module____qualname__ r   r   G/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/ext/ifconfig.pyr   !   s    r   c                   @  s4   e Zd ZU dZdZdZdZi Zded< ddd	Z	d
S )IfConfigT   r   zClassVar[OptionSpec]option_specreturn
list[Node]c                 C  s>   t  }| jj|_| | | jd |d< || jdd7 }|gS )Nr   exprT)allow_section_headings)r   statedocumentset_source_info	argumentsparse_content_to_nodes)selfnoder   r   r   run-   s   

zIfConfig.runN)r   r   )
r   r   r   has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   __annotations__r   r   r   r   r   r   %   s   
 r   appr   doctreenodes.documentdocnamestrr   Nonec           
      C  s   dd | j D }|| j j  | jj|d< t|tD ]J}z	t	|d |}W n0 t
yY } z$ddlm} d||j|}|jjd| |d	}	||	 W Y d }~qd }~ww |sb|g  q||j qd S )
Nc                 S  s   i | ]}|j |jqS r   )namevalue).0confvalr   r   r   
<dictcomp>7   s    z*process_ifconfig_nodes.<locals>.<dictcomp>builderr   r   )format_exception_only z.Exception occurred in ifconfig expression: 
%s)	base_node)configupdate__dict__copyr0   r+   listfindallr   eval	Exception	tracebackr1   join	__class__reportererrorreplace_selfchildren)
r%   r&   r(   nsr   reserrr1   msgnewnoder   r   r   process_ifconfig_nodes6   s*   	rH   r	   c                 C  s.   |  t | dt | dt tjddS )Nr   zdoctree-resolvedT)versionparallel_read_safe)add_noder   add_directiver   connectrH   sphinx__display_version__)r%   r   r   r   setupL   s   
rP   )r%   r   r&   r'   r(   r)   r   r*   )r%   r   r   r	   )__doc__
__future__r   typingr   r   docutilsr   rN   sphinx.util.docutilsr   docutils.nodesr   sphinx.applicationr   sphinx.util.typingr	   r
   Elementr   r   rH   rP   r   r   r   r   <module>   s    
