
    -PhW                    p   d Z ddlm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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mZmZmZmZ ddlmZm Z m!Z! ddl"m#Z# ddl$m%Z%  ej&        e'          Z(d9d:dZ)d;dZ*d<dZ+d=d#Z,d>d'Z-d?d,Z.d@d2Z/ G d3 d4e          Z0dAd8Z1dS )BzCheck Python modules and C API for coverage.

Mostly written by Josip Dzolonga for the Google Highly Open Participation
contest.
    )annotationsN)import_module)TYPE_CHECKING)red)Builder)__)logging)safe_getattr)IterableIteratorSequenceSet)IOAnyTextIO)Sphinx)ExtensionMetadata-fIO[str]textstrcharreturnNonec                    |                      |dz              |                      |t          |          z  dz              d S )N
z

)writelen)r   r   r   s      S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/ext/coverage.pywrite_headerr!   %   s@    GGD4KGGD3t99v%&&&&&    nameexpslist[re.Pattern[str]]c                    g }|D ]c}	 |                     t          j        |                     +# t          $ r, t                              t          d          ||            Y `w xY w|S )Nzinvalid regex %r in %s)appendrecompile	Exceptionloggerwarningr   )r#   r$   lstexps       r    compile_regex_listr/   *   s    
C D D	DJJrz#'''' 	D 	D 	DNN2677dCCCCC	DJs   '03A&%A&tablelist[list[str]]Iterator[str]c              #     K    fdt          t           d                             D             }t          |d          V  t          | d         d          E d {V   dd          D ]}t          ||d          E d {V  d S )Nc                N    g | ] t          fd D                       dz   !S )c              3  B   K   | ]}t          |                   V  d S N)r   ).0xcolumns     r    	<genexpr>z*_write_table.<locals>.<listcomp>.<genexpr>5   s-      //AQvY//////r"      )max)r7   r9   r0   s    @r    
<listcomp>z _write_table.<locals>.<listcomp>5   s<    WWWS/////////!3WWWr"   r   r   =r;   )ranger   	_add_line_add_row)r0   sizesrows   `  r    _write_tablerD   4   s      WWWW%ERSHBVBVWWWE
E3

uQx---------QRRy - -E3,,,,,,,,,,- -r"   rB   	list[int]	separatorc                L    dd                     fd| D                       z   S )N+ c              3  .   K   | ]}|d z   z  dz   V  dS )r;   rH   N )r7   sizerF   s     r    r:   z_add_line.<locals>.<genexpr>?   s1      JJD)tax0C7JJJJJJr"   )join)rB   rF   s    `r    r@   r@   >   s/    JJJJEJJJJJJJr"   
col_widthscolumns	list[str]c              #      K   d                      fdt          |          D                       }| dV  t           |          V  d S )NrI   c              3  <   K   | ]\  }}d |d|          V  dS )z| z <NrK   )r7   ir9   rN   s      r    r:   z_add_row.<locals>.<genexpr>E   s?      VVia1v1A1111VVVVVVr"   |)rM   	enumerater@   )rN   rO   rF   rC   s   `   r    rA   rA   B   sb       ''VVVV9WCUCUVVV
V
VC)))OOO
J	
*
******r"   mod_nameignored_module_expsIterable[re.Pattern[str]]Set[str]c                    t           fd|D                       rt                      S t                     } h}|j        |S |j        j        }t          j        |          D ]^\  }}dk    r|r|t            d |          z  }(t          fd|D                       rD|                      d            _|S )am  Recursively load all submodules.

    :param mod_name: The name of a module to load submodules for.
    :param ignored_module_exps: A list of regexes for modules to ignore.
    :returns: A set of modules names including the provided module name,
        ``mod_name``
    :raises ImportError: If the module indicated by ``mod_name`` could not be
        loaded.
    c              3  B   K   | ]}|                               V  d S r6   match)r7   r.   rV   s     r    r:   z _load_modules.<locals>.<genexpr>V   s/      
>
>3399X
>
>
>
>
>
>r"   N__main__.c              3  B   K   | ]}|                               V  d S r6   r\   )r7   r.   sub_mod_names     r    r:   z _load_modules.<locals>.<genexpr>g   s/      JJs399\**JJJJJJr"   )	anysetr   __spec__submodule_search_locationspkgutiliter_modules_load_modulesadd)rV   rW   modmodulessearch_locations_sub_mod_ispkgra   s   `      @r    rh   rh   J   s    
>
>
>
>*=
>
>
>>> uu 
!
!CjG
||>*1*>?O*P*P 	6 	6&<:%% 	6}%A%A<%A%ACVWWWGGJJJJ6IJJJJJ KK844l445555Nr"   coverage_modulesSequence[str]seen_modulespy_undocdict[str, dict[str, Any]]c                &   | st          |          S t                      }| D ]]}	 |t          ||          z  }# t          $ r:}t                              t          d          ||           d|i||<   Y d}~Vd}~ww xY w||z
  x}r;t                              t          d          d                    |                     ||z
  x}r;t                              t          d          d                    |                     t          |          S )a3  Return a sorted list of modules to check for coverage.

    Figure out which of the two operating modes to use:

    - If 'coverage_modules' is not specified, we check coverage for all modules
      seen in the documentation tree. Any objects found in these modules that are
      not documented will be noted. This will therefore only identify missing
      objects, but it requires no additional configuration.

    - If 'coverage_modules' is specified, we check coverage for all modules
      specified in this configuration value. Any objects found in these modules
      that are not documented will be noted. In addition, any objects from other
      modules that are documented will be noted. This will therefore identify both
      missing modules and missing objects, but it requires manual configuration.
    #module %s could not be imported: %serrorNzSthe following modules are documented but were not specified in coverage_modules: %sz, zOthe following modules are specified in coverage_modules but were not documented)sortedrc   rh   ImportErrorr+   r,   r   rM   )	ro   rq   rW   rr   rk   rV   erradditional_modulesmissing_moduless	            r    _determine_py_coverage_modulesr|   n   sP   *  $l###G$  	}X/BCCCGG 	 	 	NN2CDDhPSTTT")3HXHHHH		 *G33 
*  II())	
 	
 	
 "L00 
*  IIo&&	
 	
 	
 '??s   9
A=0A88A=c                      e Zd ZdZdZ ed                              ej        j	                  Z
ddZdd	ZddZddZddZddZddZddZddZddZdS )CoverageBuilderz0Evaluates coverage of code in the documentation.coveragez^Testing of coverage in the sources finished, look at the results in %(outdir)s{sep}python.txt.)sepr   r   c                .   g | _         | j        j        D ]E}| j        |z  }| j                             t          j        t          |                               Fg | _        | j        j        	                                D ]l\  }}	 | j        
                    |t          j        |          f           5# t          $ r+ t                              t!          d          |           Y iw xY wd | j        j        	                                D             | _        t'          d| j        j                  | _        t'          d| j        j                  | _        t'          d| j        j                  | _        t'          d| j        j                  | _        d S )Nz&invalid regex %r in coverage_c_regexesc                6    i | ]\  }}|t          d |          S )coverage_ignore_c_items)r/   )r7   r#   r$   s      r    
<dictcomp>z(CoverageBuilder.init.<locals>.<dictcomp>   s:     >
 >
 >
d $%>EE>
 >
 >
r"   coverage_ignore_modulescoverage_ignore_classescoverage_ignore_functionscoverage_ignore_pyobjects)c_sourcefilesconfigcoverage_c_pathsrcdirextendglobr   	c_regexescoverage_c_regexesitemsr'   r(   r)   r*   r+   r,   r   r   c_ignorexpsr/   r   mod_ignorexpsr   cls_ignorexpsr   fun_ignorexpsr   py_ignorexps)selfpatternr#   r.   s       r    initzCoverageBuilder.init   s   (*{2 	? 	?GkG+G%%diG&=&=>>>><>7==?? 	R 	RID#R%%tRZ__&=>>>> R R Rr"JKKSQQQQQR>
 >
"kAGGII>
 >
 >
 0%t{'J
 
 0%t{'J
 
 0')N
 
 /')N
 
s   .B442C)(C)r   c                    dS )Nzcoverage overviewrK   )r   s    r    get_outdated_docsz!CoverageBuilder.get_outdated_docs   s    ""r"   	_docnamesrY   c                    i | _         i | _        i | _        |                                  |                                  i | _        |                                  |                                  d S r6   )rr   py_undocumentedpy_documentedbuild_py_coveragewrite_py_coveragec_undocbuild_c_coveragewrite_c_coverage)r   r   s     r    write_documentszCoverageBuilder.write_documents   sn    354624      8:r"   c                   i }| j         j        j                                        D ]}|d         ||d         <   | j        D ]}t                      }t          |d          5 }|D ]}| j        D ]\  }}|                    |          }	|	r|		                                d         }
||vr|
                    ||
f           R|
||         vrL| j                            |d          D ]}|                    |
          r n|
                    ||
f           	 d d d            n# 1 swxY w Y   |r
|| j        |<   d S )Nr;      utf-8encodingr   rK   )envdomainsc_domainget_objectsr   rc   openr   r]   groupsri   r   getr   )r   	c_objectsobjfilenameundocr   linekeyregexr]   r#   r.   s               r    r   z CoverageBuilder.build_c_coverage   s   	8#,88:: 	' 	'C #AIc!f* 	/ 	/H*-%%Eh111 %Q % %D&*n % %
U %D 1 1  %#(<<>>!#4D")33 %		3+ 6 6 6 (#9S>99+/+;+?+?R+H+H !; !;C'*yy %.(-%. %*IIsDk$:$:$:$%%%% % % % % % % % % % % % % % %"  /).X&)	/ 	/s   "B7D&&D*	-D*	c                   | j         dz  }t          |dd          5 }| j        j        rt	          |dd           |                    d           | j                                        D ]\  }}t	          ||           t          |          D ]\  }}|                    d|d	d
|dd           | j        j	        r| j
        j        r+t                              t          d          |||           ft                              t!          d          d| d
|dddz   t!          d          z   |z              |                    d           	 d d d            d S # 1 swxY w Y   d S )Nzc.txtwr   r   zUndocumented C API elementsr>   r    * z<50z [z>9z]
z&undocumented c api: %s [%s] in file %sundocumented  zc   api       ]<30z - in file )outdirr   r   coverage_write_headliner!   r   r   r   rw   coverage_show_missing_itemsappquietr+   r,   r   infor   )r   output_fileopr   r   typr#   s          r    r   z CoverageBuilder.write_c_coverage   s   kG++sW555 	{2 ER!>DDDHHTNNN#'<#5#5#7#7  %R***!'  ICHH:4:::s::::;;;{> 8> "NN "#K L L $ # (	    #KK #$4 5 5"Md3G3Gc3G3G3G3G"M"M"M!N"%m"4"4!5 #+!+   '	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   D5E  E$'E$	full_nameboolc                D    t          fd| j        D                       S )Nc              3  B   K   | ]}|                               V  d S r6   )search)r7   r.   r   s     r    r:   z/CoverageBuilder.ignore_pyobj.<locals>.<genexpr>  s/      FFS3::i((FFFFFFr"   )rb   r   )r   r   s    `r    ignore_pyobjzCoverageBuilder.ignore_pyobj  s)    FFFFD4EFFFFFFr"   c                   t          | j        j        d         d                   }t          | j        j        d         d                   }| j        j        }t          | j        j        || j        | j                  }|D ]}d}| j        D ]}|	                    |          rd} n|s| 
                    |          r@	 t          |          }nL# t          $ r?}	t                              t          d          ||	           d|	i| j        |<   Y d }	~	d }	~	ww xY wt!                      }
t!                      }g }i }t#          j        |          D ]\  }}|d         d	k    rt'          |d
          s$|j        |k    r0| d| }| 
                    |          rMt#          j        |          rp||vrV| j        D ]}|	                    |          r n5|r|j        s|                    |           |                    |           |
                    |           t#          j        |          r| j        D ]}|	                    |          r n||vr|r	|j        sg ||<   g }t9          |          D ]}||j        vr	 t=          ||          }n# t>          $ r Y *w xY wt#          j         |          st#          j        |          sW|d         d	k    rd|r|j        sn| d| }| 
                    |          r||vr+|                    |           |                    |           |
                    |           |r|||<   ||d| j        |<   || j!        |<   |
| j"        |<   d S )Npyobjectsrk   FTru   rv   r   rm   
__module__r_   )funcsclasses)#	frozensetr   
domaindatar   coverage_skip_undoc_in_sourcer|   ro   r   rr   r]   r   r   rx   r+   r,   r   rc   inspect
getmembershasattrr   
isfunctionr   __doc__r'   ri   isclassr   dir__dict__r
   AttributeErrorismethodr   r   )r   seen_objectsrq   
skip_undocrk   rV   ignorer.   rj   ry   documented_objectsundocumented_objectsr   r   r#   r   r   attrs	attr_nameattrfull_attr_names                        r    r   z!CoverageBuilder.build_py_coverage  sn    !4T!:9!EFF !4T!:9!EFF[>
0K(M	
 
   ^	> ^	>HF)  99X&& !FE  **844 #H--   r"GHH(TWXXX+2C.h'
 ,/55-0UU E,.G$/44 D2 D2	c7c>>sL11 >X--'00$00	$$Y// %c** 42 44#'#5 @ @C"yy & %&  * )#+ ) (!LL...044Y???*..y9999_S)) (2#1 '2 '299T?? "!E" %L88) )#+ ) (,.GDM$+-),S G GI(<< ()'3C'C'C#1 ) ) ) ()$+$4T$:$: )g>PQU>V>V ) ((|s22 () )$, ) (09-G-GI-G-GN#00@@ ) (-\AA %Y 7 7 7 4 8 8 H H H H 2 6 6~ F F F F  2,1GDM05'&J&JDM(#-AD *+=Dx((}^	> ^	>s*    C
D5DDJ
J)	(J)	r   r   c                   t          | j                                        | j                                        z            }t	                      }t	                      }|D ]0}|| j        |         | j        |         z  z  }|| j        |         z  }1g dg}t          |          D ]}| j        |         | j        |         z  }t          |          r.dt          | j        |                   z  t          |          z  }nd}|                    ||ddt          t          | j        |                             g           |r[|                    ddt          |          z  t          |          z  ddt          |          t          |          z
   g           n|                    g d           |	                    d t          |          D                        d	S )
zOutputs the table of ``op``.)ModuleCoverageUndocumentedg      Y@z.2f%TOTALd   )r   1000c              3      K   | ]	}| d V  
dS )r   NrK   )r7   r   s     r    r:   z7CoverageBuilder._write_py_statistics.<locals>.<genexpr>  s(      BBdkkkBBBBBBr"   N)r   r   keysr   rc   rw   r   r'   r   
writelinesrD   )	r   r   all_modulesall_objectsall_documented_objectsmoduler0   module_objectsvalues	            r    _write_py_statisticsz$CoverageBuilder._write_py_statistics  s    2 7 7 9 9D<P<U<U<W<W WXX #+.55! 	A 	AF4-f58LV8TTTK"d&8&@@"" 8778[)) 	 	F!/7$:Nv:VVN>"" D$6v$> ? ??#nBUBUULLC,V45566      	0LL3444s;7G7GGNNNN{##c*@&A&AAC     LL...///
BBl5.A.ABBBBBBBBr"   c                f   | j         dz  }g }t          |dd          5 }| j        j        rt	          |dd           | j        j        r|                     t          j                   | j        j	        r:t	          |d           |                     |           |
                    d           t          | j                                                  }|D ]}| j        |         }d	|v r|                    ||d	         f           2|d
         s	|d         sCt	          ||           |d         r|
                    d           |                    d |d         D                        | j        j        r| j        j        r5|d         D ]+}t&                              t+          d          ||           ,nL|d         D ]C}t&                              t/          d          d|dz   t/          d          z   |z              D|
                    d           |d
         r|
                    d           t          |d
                                                   D ]q\  }}	|	s|
                    d| d           | j        j        rw| j        j        r*t&                              t+          d          ||           ct&                              t/          d          d|dz   t/          d          z   |z              |
                    d| d           |                    d |	D                        | j        j        r| j        j        r1|	D ],}
t&                              t+          d          |||
           -&|	D ]H}
t&                              t/          d          d| d|
 dz   t/          d          z   |z              Is|
                    d           |r/t	          |d           |                    d |D                        d d d            d S # 1 swxY w Y   d S )Nz
python.txtr   r   r   zUndocumented Python objectsr>   
Statisticsr   rv   r   r   zFunctions:
c              3  "   K   | ]
}d | dV  dS )r   r   NrK   r7   r8   s     r    r:   z4CoverageBuilder.write_py_coverage.<locals>.<genexpr>  s*      %J%JakAkkk%J%J%J%J%J%Jr"   z&undocumented python function: %s :: %sr   zpy  function  r   z - in module z	Classes:
r   z#undocumented python class: %s :: %szpy  class     z -- missing methods:

c              3  "   K   | ]
}d | dV  dS )z   - r   NrK   r   s     r    r:   z4CoverageBuilder.write_py_coverage.<locals>.<genexpr>  s*      -M-Mmammm-M-M-M-M-M-Mr"   z*undocumented python method: %s :: %s :: %szpy  method    r_   zModules that failed to importc              3  .   K   | ]\  }}d | d| dV  dS )r   z -- r   NrK   )r7   r#   ry   s      r    r:   z4CoverageBuilder.write_py_coverage.<locals>.<genexpr>  s:      NN)$5D55c555NNNNNNr"   )r   r   r   r   r!   coverage_statistics_to_stdoutr   sysstdoutcoverage_statistics_to_reportr   rw   rr   r   r'   r   r   r   r   r+   r,   r   r   r   r   )r   r   failedr   r   r#   r   func
class_namemethodsmeths              r    r   z!CoverageBuilder.write_py_coverage  sS   kL0+sW555 X	O{2 ER!>DDD{8 6))#*555{8 R...))"---$-,,..//D G' G'd+e##MM4w"89999 + !E'N !  T***W~ '000%J%J5>%J%J%JJJJ;B &#x~ &,1'N !& !&D$*NN(*+S(T(T(,(,%& %& %& %&!& -2'N !& !&D$*KK(+,<(=(=*E4*E*E*E)F*-o*>*>)? +/)/%& %& %& %& Y' *'...39%	:J:P:P:R:R3S3S '. './J#* &. ")=z)=)=)= > > >#';#J !*'+x~ %*(.,./T,U,U,0,6)* )* )* )* )/,/0@,A,A.Oz.O.O.O-P.1/.B.B-C /3-3)* )* )* !#)Sz)S)S)S T T T "-M-MW-M-M-M M M M#';#J !.'+x~ %.4; 	). 	).D,2NN025F12 12 150:04-. -. -. -.	). 5< ). ).D,2KK034D0E0E2_jCYCYSWCYCY2_2_2_1`25o2F2F1G 3717-. -. -. -.  OR!@AAANNvNNNNNNqX	O X	O X	O X	O X	O X	O X	O X	O X	O X	O X	O X	O X	O X	O X	O X	O X	O X	Os   O:P&&P*-P*c                    | j         dz  }t          |d          5 }t          j        | j        | j        | j        | j        f|           d d d            d S # 1 swxY w Y   d S )Nzundoc.picklewb)r   r   pickledumprr   r   r   r   )r   
picklepathdumpfiles      r    finishzCoverageBuilder.finish  s    [>1
*d## 	xKd.BDDVW  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   .AAAN)r   r   )r   r   )r   rY   r   r   )r   r   r   r   )r   r   r   r   )__name__r   __qualname__r   r#   r   formatospathr   epilogr   r   r   r   r   r   r   r   r   r  rK   r"   r    r~   r~      s,       ::DR	0  ff 

 
 
 
<# # # #	  	  	  	 / / / /4   8G G G Gj> j> j> j>X!C !C !C !CF[O [O [O [Oz     r"   r~   r   r   r   c           	        |                      t                     |                     dddt          t          t
          h                     |                     dg dt          t          t
          h                     |                     dg dt          t          t
          h                     |                     dg dt          t          t
          h                     |                     dg dt          t          t
          h                     |                     d	g dt          t          t
          h                     |                     d
i dt          t          h                     |                     di dt          t          h                     |                     dddt          t          h                     |                     dddt          t          h                     |                     dddt          t          h                     |                     dddt          t          h                     |                     dddt          t          h                     t          j	        ddS )Nro   rK   rI   )typesr   r   r   r   r   r   r   r   Tr  r  r   Fr   )versionparallel_read_safe)
add_builderr~   add_config_valuer   listtupledictr   sphinx__display_version__)r   s    r    setupr$    s   OOO$$$+R9dE];S;STTT!2rD%=1I1I     #R9dE]3K3K     !2rD%=1I1I     #R9dE]3K3K     *B)T5M:R:RSSS-r2Yv=N=NOOO2B)TFBSBSTTT2D"ItfDUDUVVV'rD69J9J     'rD69J9J     ')TF:K:K     %ub	4&8I8I     -"  r"   )r   )r   r   r   r   r   r   r   r   )r#   r   r$   r   r   r%   )r0   r1   r   r2   )rB   rE   rF   r   r   r   )rN   rE   rO   rP   rF   r   r   r2   )rV   r   rW   rX   r   rY   )
ro   rp   rq   rY   rW   rX   rr   rs   r   rP   )r   r   r   r   )2r   
__future__r   r   r   os.pathr  r  rf   r(   r  	importlibr   typingr   r"  sphinx._cli.util.colourr   sphinx.buildersr   sphinx.localer   sphinx.utilr	   sphinx.util.inspectr
   collections.abcr   r   r   r   r   r   r   sphinx.applicationr   sphinx.util.typingr   	getLoggerr  r+   r!   r/   rD   r@   rA   rh   r|   r~   r$  rK   r"   r    <module>r2     sQ    # " " " " "      				 



 # # # # # #              ' ' ' ' ' ' # # # # # #             , , , , , , 5AAAAAAAAAAAA&&&&&&&&&&))))))444444		8	$	$' ' ' ' '
   - - - -K K K K+ + + +! ! ! !H6 6 6 6ra a a a ag a a aH" " " " " "r"   