
    Mh                        d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlmZ d"dZd#dZd$dZd%dZd&dZd'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`.
    )annotationsN)defaultdict)dedent)	HasTraits	Undefined)Application)indentappt.Anyreturndict[str, t.Any]c                <    |                      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)r
   s    Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/traitlets/config/sphinxdoc.pysetupr   .   s-     }oNNN"&tDDD    dvboolc                    | 	| t           u rdS t          | t          t          t          t
          t          f          rt          |           S dS )NFT)r   
isinstancestrlisttupledictsetr   )r   s    r   interesting_default_valuer    8   sA    

iu"sD%s344 Bxx4r   aliases	list[str]r   c                    g }| D ]4}t          |          dk    rdnd}|                    d| | d           5d                    |          S )N   -z--z``, )lenappendjoin)r!   fmtedadashess       r   format_aliasesr-   @   se    E ) )A!'&'!'''((((99Ur   clstype[HasTraits]trait_aliasesc           
     ^   g }| j         }t          |                     d                                                    D ]\  }}|j        j         }|dz   |j        pd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>[   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-   )r.   r0   lines	classname_traitttypefullnamerD   dvrfmt_aliasess              r   class_config_rst_docrS   H   s7   
 EI3++4+88>>@@AA $ $5(s?ej&6B7%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!r   dict[str, list[str]]c                   t          t                    }| j                                        D ] \  }}||                             |           !| j                                        D ]\  }\  }}t          |          dk    r~t          t          |                    }||         }t          |          dk    rGt          t          |                    }	||	         du r!||dz   |	z                                |           |S )zBProduce a mapping of trait names to lists of command line aliases.r$   Tr3   )	r   r   r!   rA   r(   flagsr'   nextiter)
r
   resaliasrN   flagcfgrM   rL   cls_cfg	traitnames
             r   reverse_aliasesr_   x   s    
d

C))++ ! !uE
%     )//++ B BhsAs88q==T#YYI)nG7||q   g//	9%--	C)34;;DAAAJr   pathtitlepreamble
str | NoneNonec                   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)
    wr5   =Nz

)r_   openwriter'   _classes_inc_parentsrS   )r`   ra   r
   rb   r0   fcs          r   	write_docrm      s2    $C((M	dC 	A		s5zz!T)***	GGHv%&&&))++ 	 	AGG(M::;;;GGDMMMM		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   B?C--C14C1)r
   r   r   r   )r   r   r   r   )r!   r"   r   r   )r.   r/   r0   r   r   r   )r
   r   r   rT   )N)
r`   r   ra   r   r
   r   rb   rc   r   rd   )__doc__
__future__r   typingtcollectionsr   textwrapr   	traitletsr   r   traitlets.config.applicationr   traitlets.utils.textr	   r   r    r-   rS   r_   rm   r8   r   r   <module>rw      s  ! !D # " " " " "     # # # # # #       * * * * * * * * 4 4 4 4 4 4 ' ' ' ' ' 'E E E E      - - - -`   (      r   