a
    1axg                     @   s  d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ ddlmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlZddlmZmZ dd	lm Z  dd
l!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/ ddlm0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z< ddl=m>Z> ddl?m@Z@ e7AeBZCG dd dZDG dd deZEeddddZFeGdddd ZHeGddd!d"ZIdIeGeGeGd$d%d&ZJG d'd( d(ZKG d)d* d*ZLee$eeG d+d,d-ZMdJeGeeeKeGeNeeNeeGeGeGd.d/d0ZOdKeeG eGeGeGe"eGeNeeNeGdd5d6d7ZPeeG eeE d8d9d:ZQdLeGeGeGeeE d;d<d=ZRdMeeG eGeGeeE d>d?d@ZSejTdAdBdCZUejVdDd feeG ddEdFdGZWeBdHkreW  dS )Na"  
    sphinx.ext.autosummary.generate
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Usable as a library or script to generate automatic RST source files for
    items referred to in autosummary:: directives.

    Each generated RST file contains a single auto*:: directive which
    extracts the docstring of the referred item.

    Example Makefile rule::

       generate:
               sphinx-autogen -o source/generated source/*.rst

    :copyright: Copyright 2007-2022 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)NullTranslations)path)	AnyDictList
NamedTupleSequenceSetTupleTypeUnion)TemplateNotFound)SandboxedEnvironment)__display_version__package_dir)Sphinx)Builder)Config)RemovedInSphinx50Warning)
Documenter)import_module)ImportExceptionGroupget_documenterimport_by_nameimport_ivar_by_name)__)ModuleAnalyzerPycodeError)SphinxComponentRegistry)loggingrstsplit_full_qualified_name)getallsafe_getattr)	ensuredir)SphinxTemplateLoaderc                   @   s0   e Zd ZdZeddddZeddddZdS )	DummyApplicationz3Dummy Application class for sphinx-autogen command.N)
translatorreturnc                 C   sx   t  | _t | _g | _d| _|| _d| _d| _d| _	| j
di dd  | j
di dd  | j
dddt | j  d S )	N/r   Fautosummary_contextTautosummary_filename_mapautosummary_ignore_module_allenv)r   configr   registryZ
messagelogsrcdirr'   	verbosityZ
_warncountZwarningiserroraddboolZinit_values)selfr'    r5   >lib/python3.9/site-packages/sphinx/ext/autosummary/generate.py__init__<   s    zDummyApplication.__init__)argsr(   c                 G   s   d S Nr5   )r4   r8   r5   r5   r6   emit_firstresultK   s    z!DummyApplication.emit_firstresult)__name__
__module____qualname____doc__r   r7   r   r:   r5   r5   r5   r6   r&   9   s   r&   c                   @   s.   e Zd ZU eed< eed< eed< eed< dS )AutosummaryEntrynamer   template	recursiveN)r;   r<   r=   str__annotations__r3   r5   r5   r5   r6   r?   O   s   
r?   )appr(   c                 C   sl   ddl m}m}m}m}m}m}m}m}m	}	m
}
m} |||||||	|
|||g}|D ]}| j|j| qRd S )Nr   )AttributeDocumenterClassDocumenterDataDocumenterDecoratorDocumenterExceptionDocumenterFunctionDocumenterMethodDocumenterModuleDocumenterNewTypeAttributeDocumenterNewTypeDataDocumenterPropertyDocumenter)sphinx.ext.autodocrF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   r/   Zadd_documenterobjtype)rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   Zdocumenters
documenterr5   r5   r6   setup_documentersV   s    4rT   )msgr(   c                 C   s   t jdtdd t|  d S )Nz_simple_info() is deprecated.   
stacklevel)warningswarnr   printrU   r5   r5   r6   _simple_infoe   s    r]   c                 C   s&   t jdtdd td|  tjd d S )Nz_simple_warn() is deprecated.rV   rW   z	WARNING: )file)rY   rZ   r   r[   sysstderrr\   r5   r5   r6   _simple_warnk   s    ra   =)titleliner(   c                 C   s$   d| v rt d| d |t|   S )N
zCan only underline single lines)
ValueErrorlen)rc   rd   r5   r5   r6   
_underlineq   s    rh   c                   @   sN   e Zd ZdZdeeef eddddZee	dddZ
eeed	d
dZdS )AutosummaryRendererzA helper class for rendering.N)rE   template_dirr(   c                 C   s   t |trtjdtdd |r.tjdtdd tjtdddg}t	|j
|jj|}t|d| _tj| jjd	< tj| jjd
< t| jjd< t |ttfr|jr| jd | j|j n.t |tr|jjr| jd | j|jj d S )NzLThe first argument for AutosummaryRenderer has been changed to Sphinx objectrV   rW   z<template_dir argument for AutosummaryRenderer is deprecated.extautosummary	templates)loaderescapee	underlinezjinja2.ext.i18n)
isinstancer   rY   rZ   r   osr   joinr   r%   r0   r.   templates_pathr   r-   r    ro   filtersrh   r   r&   r'   add_extensionZinstall_gettext_translationsrE   )r4   rE   rj   Zsystem_templates_pathrn   r5   r5   r6   r7   z   s0    

zAutosummaryRenderer.__init__)template_namer(   c                 C   s<   t jdtdd z| j| W dS  ty6   Y dS 0 dS )zCheck if template file exists.z+AutosummaryRenderer.exists() is deprecated.rV   rW   TFN)rY   rZ   r   r-   get_templater   )r4   rx   r5   r5   r6   exists   s    zAutosummaryRenderer.exists)rx   contextr(   c                 C   sb   z| j |}W nF tyV   z| j d| }W n tyP   | j d}Y n0 Y n0 ||S )zRender a template file.zautosummary/%s.rstzautosummary/base.rst)r-   ry   r   render)r4   rx   r{   rA   r5   r5   r6   r|      s    zAutosummaryRenderer.render)N)r;   r<   r=   r>   r   r   r   rC   r7   r3   rz   r   r|   r5   r5   r5   r6   ri   w   s   
ri   c                   @   sX   e Zd ZeeddddZeeedddZeeeedd	d
Zee	e dddZ
dS )ModuleScannerN)rE   objr(   c                 C   s   || _ || _d S r9   )rE   object)r4   rE   r~   r5   r5   r6   r7      s    zModuleScanner.__init__)r@   valuer(   c                 C   s   t | j|| jjS r9   )r   rE   r   rR   )r4   r@   r   r5   r5   r6   get_object_type   s    zModuleScanner.get_object_type)r@   r   rR   r(   c              
   C   sZ   z| j d|||di W S  tyT } z$tjtd||dd W Y d }~dS d }~0 0 d S Nzautodoc-skip-memberFz\autosummary: failed to determine %r to be documented, the following exception was raised:
%srl   )type)rE   r:   	Exceptionloggerwarningr   )r4   r@   r   rR   excr5   r5   r6   
is_skipped   s    

zModuleScanner.is_skipped)imported_membersr(   c              	   C   s   g }t | j| jjD ]}zt| j|}W n ty>   d }Y n0 | ||}| |||r\qz0t	|rnd}nt|d| jj
krd}nd}W n ty   d}Y n0 | jjj }|r|| q|du r|| qdt| jv r|r|| q|S )NTr<   F__all__)
members_ofr   rE   r.   r#   AttributeErrorr   r   inspectZismoduler;   r,   appenddir)r4   r   membersr@   r   rR   importedrespect_module_allr5   r5   r6   scan   s2    


zModuleScanner.scan)r;   r<   r=   r   r7   rC   r   r3   r   r   r   r5   r5   r5   r6   r}      s   
r}   )r~   confr(   c                 C   s"   |j rt| S t| pt| S dS )zGet the members of ``obj``, possibly ignoring the ``__all__`` module attribute

    Follows the ``conf.autosummary_ignore_module_all`` setting.N)r,   r   r"   )r~   r   r5   r5   r6   r      s    r   )r@   r~   parentrA   rx   r   rE   rB   r{   modnamequalnamer(   c              	      s  t  ||ttttd fddttttf dfddttttf d fddttttf dfd	d
g dfttt tt tttt tt f d fdd}tttt tt f dfdd}tttt tt f dfdd}i }|| j	dkrt
 |}|||d< ||dh|d\|d< |d< ||dh|d\|d< |d< ||dh|d\|d< |d< ||d \|d < |d!< t|d"}|r6|r6||\|d#< |d$< nlj	dkr6t||d< tt|t|j  |d%< ||d&hd'g\|d(< |d)< ||d*d+h\|d < |d!< |	d u sJd u rVt\}	j	d,v rvd-d.d/ |d< j	d0v r}nd-d.d1 }|d2< |	|d< |d3< ||d4< j	|d5< td6 |d7< |r|||S |j	|S d S )8N)r~   r@   rR   r(   c              
      sX   z  d||| di W S  tyR } z$tjtd||dd W Y d }~dS d }~0 0 d S r   )r:   r   r   r   r   )r~   r@   rR   r   rE   r5   r6   skip_member   s    

z1generate_autosummary_content.<locals>.skip_member)r~   r(   c                    s&   t jj|  gt}dd | D S )Nc                 S   s   i | ]\}}||j qS r5   )r   ).0r@   memberr5   r5   r6   
<dictcomp>      zKgenerate_autosummary_content.<locals>.get_class_members.<locals>.<dictcomp>)sphinxrk   Zautodocget_class_membersr#   items)r~   r   )r   r5   r6   r     s    z7generate_autosummary_content.<locals>.get_class_membersc              	      sD   i }t |  jD ].}zt| |||< W q ty<   Y qY q0 q|S r9   )r   r.   r#   r   )r~   r   r@   r   r5   r6   get_module_members  s    z8generate_autosummary_content.<locals>.get_module_membersc                    s(    j dkr| S  j dkr$| S i S )Nmoduleclass)rR   )r~   )docr   r   r5   r6   get_all_members  s
    

z5generate_autosummary_content.<locals>.get_all_membersT)r~   typesinclude_publicr   r(   c                    s   g }g }| }|  D ]\}}t || }	|	j|v r|sLt|dd | jkr|||	j}
|
du rdq|
du r|| || q|| ||v s|ds|| q||fS )Nr<   TF_)r   r   rR   getattrr;   r   
startswith)r~   r   r   r   r   publicZall_membersr@   r   rS   Zskipped)rE   r   r   r5   r6   get_members  s"    


z1generate_autosummary_content.<locals>.get_members)r   r(   c                    sx   g g  }}zRt  }| }|D ]6\}}|dkr"|| v r"|| |ds"|| q"W n tyn   Y n0 ||fS )z'Find module attributes with docstrings. r   )r   Z
for_moduleZfind_attr_docsr   r   r   )r   attrsr   ZanalyzerZ	attr_docs	namespaceZ	attr_namer@   r5   r6   get_module_attrs0  s    



z6generate_autosummary_content.<locals>.get_module_attrsc              	      sz   g }t | jD ]R\}}} d | }zt|}|rBt|drBW qW n tyV   Y n0 || qdd |D }||fS )N.Z__sphinx_mock__c                 S   s$   g | ]}| d d ds|qS )r   r   )splitr   )r   xr5   r5   r6   
<listcomp>K  r   zEgenerate_autosummary_content.<locals>.get_modules.<locals>.<listcomp>)pkgutiliter_modules__path__r   hasattrImportErrorr   )r~   r   r   r   Z_ispkgfullnamer   r   r   r5   r6   get_modules?  s    z1generate_autosummary_content.<locals>.get_modulesr   r   function)r   Z	functionsZall_functionsr   classesZall_classes	exception
exceptionsZall_exceptionsZ
attributesZall_attributesr   modulesZall_modulesZinherited_membersmethodr7   methodsZall_methods	attributeproperty)r   r   r   r      r   )r   r   r   Zobjnamer@   rR   rb   rq   )r   r   rC   r3   r   r	   r   r
   updaterR   r}   r   r   r   set__dict__keysr!   rsplitrg   r|   )r@   r~   r   rA   rx   r   rE   rB   r{   r   r   r   r   r   nsscanner	ispackageZ	shortnamer5   )rE   r   r   r   r   r@   r   r   r6   generate_autosummary_content   sh    
	 $$




r   .rstFTutf-8)sources
output_dirsuffix	base_pathbuilderrj   r   rE   	overwriteencodingr(   c
                    sl  |rt jdtdd |r(t jdtdd tt| }
t|
dkr^|
d d dg |
dd   }
ttd	d
	|
  |rttd|   d ur fdd| D } t
|}t| }g }|r|jj}ni }tt|tdD ]h}|jd u rq|ptj|j}t| z*t|jdd\}}}}||d d}W n ty } zz&t|j\}}}}||d d}W n ty } zv|jr|j|jg }n|j|g }ttdd |D }ttd|jd	| W Y d }~W Y d }~qW Y d }~n
d }~0 0 W Y d }~n
d }~0 0 i }|r*||jj t|||||j |||j!|||}tj	||"||| }tj#|rt$||	d}|% }W d    n1 s0    Y  ||krqnJ|rFt$|d|	d}|&| W d    n1 s0    Y  |'| qt$|d|	d}|&| W d    n1 s20    Y  |'| q|rht(||| |||||d	 d S )Nz?builder argument for generate_autosummary_docs() is deprecated.rV   rW   zDtemplate_dir argument for generate_autosummary_docs() is deprecated.   
   z...iz,[autosummary] generating autosummary for: %sz, z[autosummary] writing to %sc                    s   g | ]}t j |qS r5   )rs   r   rt   )r   filenamer   r5   r6   r     r   z-generate_autosummary_docs.<locals>.<listcomp>)keyTZgrouped_exceptionr   r   c                 s   s    | ]}d t |j|f V  qdS z* %s: %sNr   r;   r   rp   r5   r5   r6   	<genexpr>  r   z,generate_autosummary_docs.<locals>.<genexpr>z5[autosummary] failed to import %s.
Possible hints:
%sre   )r   w)r   r   r   r   rj   r   rE   r   ))rY   rZ   r   listsortedrg   r   infor   rt   ri   find_autosummary_in_filesr.   r+   r   rC   r   rs   abspathr$   r   r@   replacer   r   r   	__cause__r   r   r   r*   r   rA   rB   getisfileopenreadwriter   generate_autosummary_docs)r   r   r   r   r   rj   r   rE   r   r   Zshowed_sourcesrA   r   Z	new_filesZfilename_mapentryr   r@   r~   r   r   r   r   Zexc2r   errorsr{   Zcontentr   fZold_contentr5   r   r6   r     s    



B
(
**r   )	filenamesr(   c              	   C   s^   g }| D ]P}t |ddd.}|  }|t||d W d   q1 sN0    Y  q|S )z^Find out what items are documented in source/*.rst.

    See `find_autosummary_in_lines`.
    r   ignore)r   r   r   N)r   r   
splitlinesextendfind_autosummary_in_lines)r   
documentedr   r   linesr5   r5   r6   r     s    2r   )r@   r   r   r(   c           
   
   C   s   |rt jdtdd z2t| dd\}}}}t| }t|| |dW S  tyX   Y nn t	y } z:t
tdd |jD }	td	| d
|	f  W Y d}~n&d}~0  ty   td|   Y n0 g S )znFind out what items are documented in the given object's docstring.

    See `find_autosummary_in_lines`.
    zBmodule argument for find_autosummary_in_docstring() is deprecated.rV   rW   Tr   )r   r   c                 s   s    | ]}d t |j|f V  qdS r   r   r   r5   r5   r6   r     r   z0find_autosummary_in_docstring.<locals>.<genexpr>z'Failed to import %s.
Possible hints:
%sre   Nz_Failed to import '%s'; the module executes module level statement and it might call sys.exit().)rY   rZ   r   r   pydocZgetdocr   r   r   r   r   r   r   r[   rt   
SystemExit)
r@   r   r   Z	real_namer~   r   r   r   r   r   r5   r5   r6   find_autosummary_in_docstring  s$    *r   )r   r   r   r(   c                 C   s  t d}t d}t d}t d}t d}t d}t d}	g }
d}d	}d	}|}d}d
}| D ]}|rt||}|rd}qf||}|r|d}|rftjtj||}qf|	|}|r|d }qf| 	drqf||}|rV|d }|	dr|dd	 }|r@|	|d s@d||f }|

t|||| qf| rf|	|d rpqfd}||}|rd}|d}d}d	}d	}qf||}|r|d }|
t||d qf||}|rf|d}qfqf|
S )a  Find out what items appear in autosummary:: directives in the
    given lines.

    Returns a list of (name, toctree, template) where *name* is a name
    of an object and *toctree* the :toctree: path of the corresponding
    autosummary directive (relative to the root of the file name), and
    *template* the value of the :template: option. *toctree* and
    *template* ``None`` if the directive does not have the
    corresponding options set.
    z^(\s*)\.\.\s+autosummary::\s*z.^\s*\.\.\s+automodule::\s*([A-Za-z0-9_.]+)\s*$z4^\s*\.\.\s+(current)?module::\s*([a-zA-Z0-9_.]+)\s*$z%^\s+(~?[_a-zA-Z][a-zA-Z0-9_.]*)\s*.*?z^\s+:recursive:\s*$z^\s+:toctree:\s*(.*?)\s*$z^\s+:template:\s*(.*?)\s*$FNr   Tr   :~r   z%s.%s r   rV   )recompilematchgrouprs   r   rt   dirnamestripr   r   r?   searchr   r   )r   r   r   Zautosummary_reZautomodule_reZ	module_reZautosummary_item_reZrecursive_arg_reZtoctree_arg_reZtemplate_arg_rer   rB   ZtoctreerA   Zcurrent_moduleZin_autosummaryZbase_indentrd   mr@   r5   r5   r6   r     s    















r   )r(   c                  C   s   t jdtdtdd} | jddddt d	 | jd
dtdd | jddddtdd | jdddddtdd | jddddd tdd | jddd d!d"td#d | jd$d%d d&d"td'd | S )(Nz#%(prog)s [OPTIONS] <SOURCE_FILE>...z:For more information, visit <https://www.sphinx-doc.org/>.a  
Generate ReStructuredText using autosummary directives.

sphinx-autogen is a frontend to sphinx.ext.autosummary.generate. It generates
the reStructuredText files from the autosummary directives contained in the
given input files.

The format of the autosummary directive is documented in the
``sphinx.ext.autosummary`` Python module and can be read using::

  pydoc sphinx.ext.autosummary
)usageepilogdescriptionz	--versionversionZshow_versionz%%(prog)s %s)actiondestr  source_file+z&source files to generate rST files for)nargshelpz-oz--output-dirstorer   z directory to place all output in)r  r  r  z-sz--suffixr   r    z/default suffix for files (default: %(default)s))r  r  defaultr  z-tz--templatesrm   z0custom template directory (default: %(default)s)z-iz--imported-members
store_truer   Fz0document imported members (default: %(default)s)z-az--respect-module-allr   zPdocument exactly the members in module __all__ attribute. (default: %(default)s))argparseArgumentParserr   add_argumentr   )parserr5   r5   r6   
get_parserl  s@    



r  r   )argvr(   c                 C   s   t jtjd t jtjtdd t j	g d \}}t
|}t|tjtj t| t | }|jr|jjt|j |j |j_t|j|jd|j |j|d d S )Nr   localer   r   )r   rE   )r   r  	setlocaleLC_ALLZinit_consolers   r   rt   r   initr&   r   Zsetupr_   stdoutr`   rT   r  
parse_argsrm   r.   ru   r   r   r   r,   r   r  r   r   r   )r  r'   r   rE   r8   r5   r5   r6   main  s    
r$  __main__)rb   )NN)	Nr   NNNFNTr   )NN)NN)Xr>   r  r   r  rs   r   r   r  r_   rY   gettextr   r   typingr   r   r   r   r   r	   r
   r   r   Zjinja2r   Zjinja2.sandboxr   Zsphinx.localer   r   r   Zsphinx.applicationr   Zsphinx.buildersr   Zsphinx.configr   Zsphinx.deprecationr   rQ   r   Zsphinx.ext.autodoc.importerr   Zsphinx.ext.autosummaryr   r   r   r   r   Zsphinx.pycoder   r   Zsphinx.registryr   Zsphinx.utilr   r    r!   Zsphinx.util.inspectr"   r#   Zsphinx.util.osutilr$   Zsphinx.util.templater%   Z	getLoggerr;   r   r&   r?   rT   rC   r]   ra   rh   ri   r}   r   r3   r   r   r   r   r   r  r  r  r$  r5   r5   r5   r6   <module>   s   ,
:6       
f_."
