
    KcB                     `    d Z ddlmZ ddlmZ ddlmZ ddlmZ d Z	d Z
d Zd	 Zd
 ZddZdS )a  Machinery for documenting traitlets config options with Sphinx.

This includes:

- A Sphinx extension defining directives and roles for config options.
- A function to generate an rst file given an Application instance.

To make this documentation, first set this module as an extension in Sphinx's
conf.py::

    extensions = [
        # ...
        'traitlets.config.sphinxdoc',
    ]

Autogenerate the config documentation by running code like this before
Sphinx builds::

    from traitlets.config.sphinxdoc import write_doc
    from myapp import MyApplication

    writedoc('config/options.rst',    # File to write
             'MyApp config options',  # Title
             MyApplication()
            )

The generated rST syntax looks like this::

    .. configtrait:: Application.log_datefmt

        Description goes here.

    Cross reference like this: :configtrait:`Application.log_datefmt`.
    )defaultdict)dedent)	Undefined)indentc                 @    |                      ddd           ddd}|S )zRegisters the Sphinx extension.

    You shouldn't need to call this directly; configure Sphinx to use this
    module instead.
    configtraitzConfig option)objnameT)parallel_read_safeparallel_write_safe)add_object_type)appmetadatas     :lib/python3.11/site-packages/traitlets/config/sphinxdoc.pysetupr   *   s1     }oNNN&*4HHHO    c                     | 	| t           u rdS t          | t          t          t          t
          t          f          rt          |           S dS )NFT)r   
isinstancestrlisttupledictsetbool)dvs    r   interesting_default_valuer   5   sG    
 i u"sD%s344 Bxx4r   c                     g }| D ]4}t          |          dk    rdnd}|                    d| | d           5d                    |          S )N   -z--z``, )lenappendjoin)aliasesfmtedadashess       r   format_aliasesr'   =   sf    E ) )A!-'&'!'''((((99Ur   c           
      Z   g }| j         }t          |                     d                                                    D ]\  }}|j        j         }|dz   |j        z   }|d|z   dgz  }|j                                        pd}|                    t          t          |                    dz              d|v rH|                    t          d	d
                    d |j        D                       z                        n%|                    t          d|z                        t          |j                  r	 |                                }	n# t           $ r d}	Y nw xY w|	[t#          |	          dk    r|	dd         dz   }	|	                    dd          }	|                    t          d|	z                       ||         r:t'          ||                   }
|                    t          d|
z                        |                    d           d                    |          S )zoGenerate rST documentation for this class' config options.

    Excludes traits defined on parent classes.
    T)config.z.. configtrait::  zNo description
Enumz
:options: r   c              3       K   | ]	}d |z  V  
dS )z``%r``N ).0xs     r   	<genexpr>z'class_config_rst_doc.<locals>.<genexpr>X   s&      8\8\!A8\8\8\8\8\8\r   z:trait type: N@   =   z...z\nz\\nz:default: ``%s``z:CLI option: )__name__sortedclass_traitsitems	__class__namehelprstripr!   r   r   r"   valuesr   default_valuedefault_value_repr	Exceptionr    replacer'   )clstrait_aliaseslines	classname_traitttypefullnamer;   dvrfmt_aliasess              r   class_config_rst_docrL   E   s;   
 EI3++4+88>>@@AA $ $5(s?UZ/%0"55z  ""6&6VF4LL))D0111 U? 	:LLtyy8\8\u|8\8\8\/\/\ \]]^^^^LL% 788999 %U%899 
	?..00    ?s88b= +crc(U*Ckk%11V$6$<==>>> " 	@(x)@AAKLL+ =>>??? 	R99Us   ;EEEc                    t          t                    }| j                                        D ] \  }}||                             |           !| j                                        D ]\  }\  }}t          |          dk    rpt          |          d         }||         }t          |          dk    r@t          |          d         }	||	         du r!||dz   |	z                                |           |S )zBProduce a mapping of trait names to lists of command line aliases.r   r   Tr*   )r   r   r#   r8   r!   flagsr    )
r   resaliasrG   flagcfgrF   rE   cls_cfg	traitnames
             r   reverse_aliasesrU   u   s    
d

C))++ ! !uE
%     )//++ B BhsAs88q= 	BS		!I)nG7||q  B MM!,	9%- B	C)34;;DAAAJr   Nc                    t          |          }t          | d          5 }|                    |dz              |                    dt          |          z  dz              |                    d           ||                    |dz              |                                D ]:}|                    t          ||                     |                    d           ;	 ddd           dS # 1 swxY w Y   dS )a  Write a rst file documenting config options for a traitlets application.

    Parameters
    ----------
    path : str
        The file to be written
    title : str
        The human-readable title of the document
    app : traitlets.config.Application
        An instance of the application class to be documented
    preamble : str
        Extra text to add just after the title (optional)
    wr,   =Nz

)rU   openwriter    _classes_inc_parentsrL   )pathtitler   preamblerC   fcs          r   	write_docra      s4    $C((M	dC 	A		s5zz!T)***	 	'GGHv%&&&))++ 	 	AGG(M::;;;GGDMMMM		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B?C--C14C1)N)__doc__collectionsr   textwrapr   	traitletsr   traitlets.utils.textr   r   r   r'   rL   rU   ra   r/   r   r   <module>rg      s   ! !D $ # # # # #             ' ' ' ' ' '      - - -`  (     r   