
    -Ph.                       d dl m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
 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 e
rd dlZd dlmZmZmZ d dlmZ dej        v r* eej        d                             d                    Znh dZddgeR Z ej         dd          Z!dHdZ"dIdZ#	 dJdddKd#Z$dLd)Z%	 dMdNd.Z&	 	 dOdPd9Z'	 	 dQdRd;Z(	 dJdSd=Z)dTd?Z*dUdBZ+dVdCZ,	 dMdWdFZ-dXdGZ.dS )Y    )annotationsN)EXTENSION_SUFFIXES)Path)TYPE_CHECKING)package_dir)LOGGER)__)FileAvoidWrite)ReSTRenderer)IterableIteratorSequence)ApidocOptionsSPHINX_APIDOC_OPTIONS,>   undoc-membersshow-inheritancemembersz.pyz.pyx	templatesapidocfilename
str | Pathreturnboolc                    t          |           j        t          fdt          t          t
          d          D                       S )z)Check *filename* is __init__ file or not.c              3  *   K   | ]}d |z   k    V  dS )__init__N ).0suffixbasenames     [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/ext/apidoc/_generate.py	<genexpr>zis_initpy.<locals>.<genexpr>*   sA         	J''         T)keyreverse)r   nameanysortedPY_SUFFIXESlen)r   r!   s    @r"   	is_initpyr,   '   sX    H~~"H    [c4@@@     r$   modnames
str | Nonestrc                 H    d                     t          d|                     S )zJoin module names with dots..N)joinfilter)r-   s    r"   module_joinr4   0   s    88F4**+++r$   r   dir_pathfilesIterable[Path | str]r6   Path | Nonec                   | dk    r"t          t          t          |                     S |4t          t          t          |                                                    S dS )z+Check given *files* contains __init__ file.r   NF)r(   mapr,   iterdir)r7   r6   s     r"   is_package_dirr=   5   sT     {{3y%(()))3y("2"2"4"4556665r$   r'   textoptsr   r   c                   t          |j        |  d|j                   }|j        r+|j        s"t          j        t          d          |           |S |j        s>|	                                r*|j        s"t          j        t          d          |           ne|j        s"t          j        t          d          |           t          |          5 }|                    |           ddd           n# 1 swxY w Y   |S )z0Write the output file for module/package <name>.r1   zWould create file %s.z!File %s already exists, skipping.zCreating file %s.N)r   dest_dirr    dry_runquietr   infor	   forceis_filer
   write)r'   r>   r?   fnamefs        r"   
write_filerJ   @   s0   4 7 7$+ 7 788E| z 	<K233U;;;: %--// z 	HK>??GGGz 	8K.//777E"" 	aGGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	Ls   C11C58C5packager!   user_template_dirstr | os.PathLike[str] | Nonec                b   t          |j        st          n|j                  }|j        r|                    d           t          | |          }|j         ||t          |          d}|
|t          g}nt          g}t          |          
                    d|          }t          |||          S )z.Build the text of the file and write the file.private-members)show_headingsr!   qualnameautomodule_optionsNzmodule.rst.jinja)setrR   OPTIONSinclude_privateaddr4   no_headingsr)   template_dirr   renderrJ   )	rK   r!   r?   rL   optionsrQ   contexttemplate_pathr>   s	            r"   create_module_filer]   R   s     !8U''d>UVVG '%&&&7H--H!--$Woo	 G $*L9%&&--.@'JJDhd+++r$   rootmaster_packagesubrootpy_files	list[str]subsis_namespaceexcludesSequence[re.Pattern[str]]
list[Path]c	           
          fd|D             }	 fd|D             }
t          t          |
                    }
fd|
D             }
t                                          }j        r|                    d           t                    }||	|
|j        j        t          |          j	         j
        d	}
t          g}nt          g}g }t          |                              d|          }|                    t          ||                     |
r)j        r"|                    fd|
D                        |S )	zBuild the text of the file and write the file.

    Also create submodules if necessary.

    :returns: list of written files
    c                p    g | ]2}t          t          |                    !t          |          3S r   )is_skipped_packager   r4   )r   pkgnamere   r_   r?   r^   r`   s     r"   
<listcomp>z'create_package_file.<locals>.<listcomp>   sQ       !$tW"5"5tXFFNGW55  r$   c                    g | ]K}t          t          |                    !t          |          0|                    d           d         LS )r1   r   )is_skipped_moduler   r,   split)r   subre   r?   r^   s     r"   rl   z'create_package_file.<locals>.<listcomp>   se        dC$AA KTTW..		#q  r$   c                2    g | ]}t          |          S r   )r4   )r   modnamer_   r`   s     r"   rl   z'create_package_file.<locals>.<listcomp>   s2       :ANGW55  r$   rO   )	rk   subpackages
submodulesrd   modulefirstseparatemodulesrR   rP   maxdepthNzpackage.rst.jinjac                4    g | ]}t          d |          S N)r]   )r   	submoduler?   rL   s     r"   rl   z'create_package_file.<locals>.<listcomp>   s8     
 
 
 tY6GHH
 
 
r$   )r)   rS   rT   copyrU   rV   r4   module_firstseparate_modulesrW   	max_depthrX   r   rY   appendrJ   extend)r^   r_   r`   ra   r?   rc   rd   re   rL   rs   rt   rZ   rk   r[   r\   writtenr>   s   ``` `  ``        r"   create_package_filer   m   s   $         K       J
 J((J    EO  J llnnG '%&&&.'22G" $(0$Woo!--N
 
G $*L9%G&&--.A7KKDNN:gtT22333 d+  
 
 
 
 
'
 
 
 	 	 	
 Nr$   modulesc                l   |                                   d}|                                 D ]2}|                    |dz             r|                     |           0|}3|j        |j        | d}|
|t          g}nt          g}t          |                              d|          }t          |||          S )zCreate the module's index. r1   )headerrw   docnamesNztoc.rst.jinja)
sortr{   
startswithremover   r~   rX   r   rY   rJ   )	r   r?   r'   rL   prev_modulemoduler[   r\   r>   s	            r"   create_modules_toc_filer      s     LLNNNK,,.. ! ![3.// 	!NN6"""" KK +N G $*L9%&&--owGGDdD$'''r$   dirnamec                *    t                                                     sdS t          j        t          t           d                              }t	          d |D                       }|s	|j        sdS t           fd|D                       S )%Check if we want to skip this module.Fz*.pyc              3  8   K   | ]}t          |          |V  d S ry   )r,   )r   rI   s     r"   r#   z%is_skipped_package.<locals>.<genexpr>   s-      ;;ill;!;;;;;;r$   Tc              3  T   K   | ]"}t          t          |                    V  #d S ry   )is_excludedr   )r   rI   r   re   s     r"   r#   z%is_skipped_package.<locals>.<genexpr>   s7      FF1{4++X66FFFFFFr$   )r   is_dirglobr/   r(   implicit_namespacesall)r   r?   re   r7   regular_packages   ` `  r"   rj   rj      s     ==!! uIc$w//0011E;;U;;;;;O 4#; t FFFFFFFFFFFr$   	_excludesc                    t          |           } |                                 sdS | j                            d          o|j         S )r   T_)r   existsr'   r   rU   )r   r?   r   s      r"   rn   rn      sG     H~~H?? t=##C((E1E-EEr$   	root_path*Iterator[tuple[str, list[str], list[str]]]c              #     K   t          j        | |j                  D ]W\  }}t          fd|D                       }|j        rdndt          fd|D                       |dd<   ||fV  XdS )z@Walk through the directory and list files and subdirectories up.)followlinksc              3     K   | ]>}|                     t                    t          t          |                    :|V  ?d S ry   )endswithr*   r   r   )r   rI   re   r^   s     r"   r#   zwalk.<locals>.<genexpr>   se       
 
zz+&&
 0;4a==(/S/S

 
 
 
 
 
r$   )r1   )r1   r   c              3     K   | ]9}|                               t          t          |                    5|V  :d S ry   )r   r   r   )r   rp   exclude_prefixesre   r^   s     r"   r#   zwalk.<locals>.<genexpr>  sf       
 
>>"233
  T3::	

 
 
 
 
 
r$   N)oswalkfollow_linksr)   rU   )r   re   r?   rc   r7   r   r^   s    `   @@r"   r   r      s        WYD<MNNN    dE 
 
 
 
 

 
 
 
 
  	*06) 
 
 
 
 
 

 
 
 
 
QQQ D%-   r$   c                R    t          d t          | ||          D                       S )zACheck the given directory contains child module/s (at least one).c              3  "   K   | ]
\  }}}|V  d S ry   r   )r   _root_subsr7   s       r"   r#   z#has_child_module.<locals>.<genexpr>  s)      PP,uuPPPPPPr$   )r(   r   )r   re   r?   s      r"   has_child_moduler     s-     PPY$0O0OPPPPPPr$   str | os.PathLike[str]tuple[list[Path], list[str]]c                   t          |           } t          |           s|j        r| j        }nd}g }g }t	          | ||          D ]'\  }}}	t          |	          }
|
 o|j        }|
rR|	                                D ]<}t          |          r+|	                    |           |	                    d|           =n/|t          |           k    r|j        s|
                                 |
s|r|s#t          |	          dk    st          ||          s|                    t          |                                         t          j        j                                      t          j        j        d          }|rt'          |||          rM|                    t+          ||||	|||||	  	                   |                    t/          ||                     |t          |           k    sJ |J |	D ]v}t1          t          | |          ||          sU|                    d          d         }|                    t5          ||||                     |                    |           w)||fS )z[Look for every file in the directory tree and create the corresponding
    ReST files.
    r5   Nr      r1   )r   r=   r   r'   r   r{   r,   r   insertr/   clearr+   rj   removeprefixlstripr   pathsepreplacer   r   r   r   r4   rn   ro   r]   )r   re   r?   rL   root_package	toplevelswritten_filesr^   rc   r7   is_pkgrd   rI   
subpackagepy_filer   s                   r"   recurse_treer     s    YIy))) T-E  ~ IM!)Xt<< 3- 3-dE&&!z>d&> 		ZZ\\ ' 'Q<< 'LLOOOLLA&&&' S^^##+ 

 %	-\ %	- Ls5zzA~~-?d-K-K~%%c)nn55VBGK((WRW[#..  $ L'7h'M'M L!((+ (&!  ($-
 
   $$[z%J%JKKK 3y>>))))'''  - -(i)A)A4RR -$]]3//2F!((*(&$8I   
 $$V,,,- )##r$   c                X    t          |           t          fd|D                       S )zCheck if the directory is in the exclude list.

    Note: by having trailing slashes, we avoid common prefix issues, like
          e.g. an exclude "foo" also accidentally excluding "foobar".
    c              3  B   K   | ]}|                               V  d S ry   )match)r   excluderoot_strs     r"   r#   zis_excluded.<locals>.<genexpr>d  s/      ??7w}}X&&??????r$   )r/   r(   )r^   re   r   s     @r"   r   r   ]  s3     4yyH????h??????r$   )r   r   r   r   )r-   r.   r   r/   )r   )r7   r8   r6   r9   r   r   )r'   r/   r>   r/   r?   r   r   r   ry   )
rK   r.   r!   r/   r?   r   rL   rM   r   r   )r   N)r^   r/   r_   r.   r`   r/   ra   rb   r?   r   rc   rb   rd   r   re   rf   rL   rM   r   rg   )r   N)
r   rb   r?   r   r'   r/   rL   rM   r   r   )r   r   r?   r   re   rf   r   r   )r   r   r?   r   r   rf   r   r   )r   r   re   rf   r?   r   r   r   )r   r   re   rf   r?   r   r   r   )
r   r   re   rf   r?   r   rL   rM   r   r   )r^   r   re   rf   r   r   )/
__future__r   r   r   os.pathimportlib.machineryr   pathlibr   typingr   sphinxr   sphinx.ext.apidoc._sharedr   sphinx.localer	   sphinx.util.osutilr
   sphinx.util.templater   recollections.abcr   r   r   r   environrS   ro   rT   r*   joinpathrX   r,   r4   r=   rJ   r]   r   r   rj   rn   r   r   r   r   r   r$   r"   <module>r      s   " " " " " "  				  2 2 2 2 2 2                         , , , , , ,       - - - - - - - - - - - - 8III<<<<<<<<<<777777 bj((c"*45;;C@@AAGG  G f2122#{#K::   , , , , #%AE        , 8<	, , , , ,F +-7;A A A A AN 7;	( ( ( ( (> UWG G G G G"	F 	F 	F 	F       >Q Q Q Q 8<	H$ H$ H$ H$ H$V@ @ @ @ @ @r$   