
    L-Ph^                       U 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ZddlZddlZddlmZmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZmZ dd	lmZmZmZ dd
l m!Z!m"Z"m#Z# ddl m$Z$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1 erddl2m3Z3 ddl4m5Z5 eeee	e
eegZ6de7d<   ej8        rddl9Z9ddl:Z:e6;                    e:e9g            e(e          Zd/d0dZ<d1dZ=d2d"Z>d2d#Z?d3d&Z@d4d*ZAd4d+ZBd4d,ZC G d- d.          ZDdS )5z=Determining whether files are being measured/reported or not.    )annotationsN)	FrameType
ModuleType)castAnyTYPE_CHECKING)Iterable)env)FileDispositiondisposition_init)ConfigErrorCoverageExceptionPluginError)TreeMatcherGlobMatcherModuleMatcher)prep_patternsfind_python_filescanonical_filename)isolate_modulesys_modules_saved)source_for_filesource_for_morf)TFileDispositionTMorfTWarnFn	TDebugCtl)CoverageConfig)Pluginszlist[ModuleType]modules_we_happen_to_haveFmorfr   	directoryboolreturnstrc                    t          t          |                     }|                    d          s|r%t          j                            |          d         }|S )zReturn the canonical path of the module or file `morf`.

    If the module is a package, then return its directory. If it is a
    module, then return its file, unless `directory` is True, in which
    case return its enclosing directory.

    z__init__.pyr   )r   r   endswithospathsplit)r!   r"   	morf_paths      P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/coverage/inorout.pycanonical_pathr-   7   sT     #?4#8#899I-(( 0I 0GMM),,Q/	    filenameframeFrameType | None
str | Nonec                *   ||j         ni }|                    dd          }t          |t                    r|dk    r|S |                    dd          }|r$|j        }t          |t                    r|dk    r|S t          j        |           }||S |S )a  Get the name of the module for a filename and frame.

    For configurability's sake, we allow __main__ modules to be matched by
    their importable name.

    If loaded via runpy (aka -m), we can usually recover the "original"
    full dotted module name, otherwise, we resort to interpreting the
    file name to get the module's name.  In the case that the module name
    can't be determined, None is returned.

    N__name____main____spec__)	f_globalsget
isinstancer%   nameinspectgetmodulename)r/   r0   module_globalsdunder_namespecfullnameinspectednames          r,   name_for_modulerB   E   s     ).(9U__rN,00TBBK+s## z(A(Aj$//D 9h$$ 	Z)?)?O )(33M r.   modr   c                H    t          | d          ot          | dd          du S )z5Is the module object `mod` a PEP420 namespace module?__path____file__N)hasattrgetattr)rC   s    r,   module_is_namespacerI   g   s(    3
##NZ(F(F$(NNr.   c                j    t          | dd          }|dS t          j                            |          S )z8Does the module object `mod` have an existing __file__ ?rF   NF)rH   r(   r)   exists)rC   mod__file__s     r,   module_has_filerM   l   s2    #z400Ku7>>+&&&r.   
modulenametuple[str | None, list[str]]c                    d}g }	 t           j                            |           }||j        }t	          |j        pd          }n# t          $ r Y nw xY w||fS )zFind the file and search path for `modulename`.

    Returns:
        filename: The filename of the module, or None.
        path: A list (possibly empty) of directories to find submodules in.

    N )	importlibutil	find_specoriginlistsubmodule_search_locations	Exception)rN   r/   r)   r?   s       r,   file_and_path_for_modulerY   t   s{     HD?~''
33 {H7=2>>D     T>s   A 
AApathsset[str]Nonec                    t           D ]6}t          |d          r$|                     t          |d                     7dS )z;Add paths where the stdlib can be found to the set `paths`.rF   Tr"   N)r    rG   addr-   )rZ   ms     r,   add_stdlib_pathsra      sO     ' 9 91j!! 	9IInQ$7778889 9r.   c                   t          t          j                              }|D ]a}|dk    rdn|}t          j        |                    d          v r4t          j        |          }dD ]}|                     ||                    bdS )z:Add locations for third-party packages to the set `paths`.pypy
pypy_posix_)platlibpurelibscriptsN)set	sysconfigget_scheme_namesr(   r:   r*   	get_pathsr_   )rZ   scheme_namesschemebetter_schemeconfig_paths	path_names         r,   add_third_party_pathsrr      s     y13344L 3 3(.&(8(8f7m))#....$.v66L> 3 3			,y122223 3r.   c                    t          t          d          }|                     |           t          j        r5|                     t
          j                            |d                     dS dS )zAAdd paths where coverage.py code can be found to the set `paths`.Tr^   testsN)r-   rF   r_   r
   TESTINGr(   r)   join)rZ   
cover_paths     r,   add_coverage_pathsrx      sb    D999J	IIj
{ 5		"',,z733444445 5r.   c                  l    e Zd ZdZd#dZd$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 )-InOrOutz0Machinery for determining what files to measure.configr   warnr   debugTDebugCtl | Noneinclude_namespace_packagesr#   r$   r\   c           	     ^    | _         | _        | _        g  _         j                            |j                   g  _         j                            |j                   |j        pg D ]V}t          j        	                    |          r j        
                    |           < j        
                    |           Wt           j                  D ]M\  }}t          j        	                    |          st          d|          t          |           j        |<   N j        d d           _        t          |j                   _        t          |j                   _        t)                       _        |j        st/           j                   t)                       _        t3           j                   t)                       _        t7           j                   d% fd} |dd                    d	 t:          j        D                       z              d  _        d  _        d  _         d x _!         _"         j        s j        rg } j        r7tG           j        d
           _        |
                    d j                    j        r7tI           j        d           _        |
                    d j                    |dd                    |          z              n4 j        r-tG           j        d           _          |d j                     j        r-tK           j        d           _!         |d j!                    j        r-tK           j        d           _"         |d j"                   tG           j        d           _&         |d j&                   tG           j        d           _'         |d j'                   t)                       _(        tS                      5   j        D ]}		 tU          |	          \  }
} |d|	d|
           n(# tV          $ r} |d|	d|            Y d }~Gd }~ww xY w|
r` j'        ,                    |
          rE |d|	d|
            j(        -                    t]          t_          |
                               |D ]G} j'        ,                    |          r+ |d |	d!|            j(        -                    |           H	 d d d            n# 1 swxY w Y    j        D ]D} j'        ,                    |          r( |d"|            j(        -                    |           EtG           j(        d#           _0         |d$ j0                      tb           _2        d S )&NzSource dir is not a directory: msgr%   r$   r\   c                N    j         rj                             |            d S d S N)r}   write)r   selfs    r,   _debugz InOrOut.__init__.<locals>._debug   s3    z &
  %%%%%& &r.   z	sys.path: c              3      K   | ]	}d | V  
dS )z
    NrQ   ).0ps     r,   	<genexpr>z#InOrOut.__init__.<locals>.<genexpr>   s(      $D$Da\a\\$D$D$D$D$D$Dr.   sourceztrees source_pkgszmodules zSource matching against z and pylibzPython stdlib matching: includezInclude matching: omitzOmit matching: coveragezCoverage code matching: thirdzThird-party lib matching: zImported source package z as zCouldn't import source package z: z"Source in third-party: source_pkg z at zSource in third-party: z path directory at z(Source in third-party: source directory source_in_thirdz Source in third-party matching: )r   r%   r$   r\   )3r|   r}   r   r   extendsource_dirsr   r(   r)   isdirappend	enumerater   r   source_pkgs_unmatchedr   run_includer   run_omitr   ri   pylib_pathscover_pylibra   cover_pathsrx   third_pathsrr   rv   syssource_matchsource_pkgs_matchpylib_matchinclude_match
omit_matchr   r   r   cover_matchthird_matchsource_in_third_pathsr   rY   r   matchr_   r-   r   source_in_third_matchr   
disp_class)r   r{   r|   r}   r   srcir   againstpkgmodfiler)   excpathdirs   `             r,   __init__zInOrOut.__init__   s    	
*D'&( 2333&( 2333=&B 	- 	-Cw}}S!! - '',,,, '',,,,   011 	: 	:FAs7==%% M!"KC"K"KLLL"4S"9"9DQ%)%5aaa%8"$V%788!&/22	 &)UU! 	/T-... &)UU4+,,, &)UUd.///	& 	& 	& 	& 	& 	& 	{RWW$D$D38$D$D$DDDDEEE !!%/33T_ 	Ht/ 	HG ?$/0@($K$K!=(9==>>> F)6t7G)W)W&D$*@DDEEEF-W0E0EEFFFF H#.t/?#I#I F$2BFFGGG< 	@!,T\9!E!EDF>(:>>???9 	:)$)V<<DOF8T_88999&t'7DD>$*:>>???&t'7AA@D,<@@AAA
 &)UU"   	D 	D' D D$<S$A$AMGTFLcLLLLMMMM(   FKSKKcKKLLLHHHH  D'--g66 aWWWGWW   266~oV]F^F^7_7_```#' D D+11':: D"F _# _ _T[ _ _   !6::7CCCDD	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 	D, # 	4 	4C%%c** 4I#IIJJJ*..s333%01KM^%_%_"N$2LNNOOO2As=   

T#P98T9
QQTQB0TT"TNr/   r%   r0   r1   r   c                   |}t          | j        |          }dd}|                    d          r ||d          S ||j        o|j                            d
          }|rwt          t          |                    }|rY|                    d          sDt          j        	                    |          }|t          j        	                    |          k    r|}|s ||d          S |                    d          r ||d          S |                    d          r ||d          S t          |          }||_
        d	}	| j        j        D ]}	|	j        s
	 |	                    |          }
|
Y|	|
_        d|_        |
|_        |
                                rd|_        n&t          |
                                          |_         n[|# t(          $ r? |	j        }t-          j                    }|                     d|d|            d|	_        Y w xY wd|_        ||_        |j        sK|j        st3          d|	d|j         d          |                     |j        |          }|r |||           |S )a  Decide whether to trace execution in `filename`, with a reason.

        This function is called from the trace function.  As each new file name
        is encountered, this function determines whether it is traced or not.

        Returns a FileDisposition object.

        dispr   reasonr%   r$   c                "    d| _         || _        | S )z+Simple helper to make it easy to return NO.F)tracer   )r   r   s     r,   nopez"InOrOut.should_trace.<locals>.nope7  s    DJ DKKr.   <zoriginal file name is not realNrF   zempty string isn't a file namezmemory:zmemory isn't traceablezfile name is not realTzDisabling plug-in z due to an exception:
FzPlugin z! didn't set source_filename for '')r   r   r   r%   r$   r   )r   r   
startswithr7   r8   r   r%   r(   r)   basenamer   pluginsfile_tracers_coverage_enabledfile_tracer_coverage_pluginr   has_dynamic_source_filenamehas_dynamic_filenamesource_filenamerX   _coverage_plugin_name	traceback
format_excr|   r   original_filenamecheck_include_omit_etc)r   r/   r0   r   r   r   dunder_fileorig	canonicalpluginr   plugin_nametbr   s                 r,   should_tracezInOrOut.should_trace+  s    %::	 	 	 	 '',, 	@4>???  /Meo.A.A*.M.MK 	5*3{+;+;<<$ 5->-I-I#-N-N 57++,=>>Drw//9999 $5 	@4>???y)) 	846777s## 	7
 45666&x00	"+ l/ 	- 	-F+ $00;;*39K0!%DJ'2D$">>@@ 4811/A'77990 0, E +    $:)++		Y{YYUWYYZZZ+0( DJ#,D ( 	#' !bfbbI_bbb   001EuMMF #T6"""s   A.G		AHHr2   c                h   t          ||          }| j        s| j        rd}d}| j        r[t          |t                    r@| j                            |          r&d}|| j        v r| j                            |           nd|d}|s#| j        r| j                            |          rd}|s|dz   S | j                            |          r| j	                            |          sdS n| j
        r| j
                            |          sdS n[| j                            |          rd	S | j        r| j                            |          rd
S | j                            |          rdS | j        r| j                            |          rdS 	 |                    d           n# t          $ r Y dS w xY wdS )zCheck a file name against the include, omit, etc, rules.

        Returns a string or None.  String means, don't trace, and is the reason
        why.  None means no reason found to not trace.

        r   FTzmodule  zfalls outside the --source specz#inside --source, but is third-partyz!falls outside the --include treeszis part of coverage.pyzis in the stdlibzis a third-party modulezis inside an --omit patternzutf-8znon-encodable filenameN)rB   r   r   r9   r%   r   r   remover   r   r   r   r   r   encodeUnicodeEncodeError)r   r/   r0   rN   extraoks         r,   r   zInOrOut.check_include_omit_etc  s-    %Xu55
  !	1 6 !	1EB% 6j#.. 643I3O3OPZ3[3[ 6B!T%???299*EEE5j555E $+ $**844 B A@@@%%h// =8R8X8XYa8b8b =<< 	1%++H55 ;::;
 %%h// 0//  *D$4$:$:8$D$D *)) %%h// 100 ? 	1t44X>> 	100	,OOG$$$$! 	, 	, 	,+++	, ts   F! !
F/.F/c                f    | j         r'| j        s| j        r|                     dd           dS dS dS )z)Warn if there are settings that conflict.z,--include is ignored because --source is setzinclude-ignoredslugN)r   r   r   r|   )r   s    r,   warn_conflicting_settingsz!InOrOut.warn_conflicting_settings  sZ    < 	b b4#3 b		HO`	aaaaa	b 	bb br.   c                   | j         s| j        s| j        r't                      }t	          t
          j                                                  D ]}t          |dd          }|||v rt          t          |dd                    dk    r>| 
                    |          }|j        r[|j        r2d| }|                     |d           |                    |           | j        rR| j                            d	          r8| j                            d
                    |j        |j                             dS dS )zCWarn if files have already been imported that we will be measuring.rF   NrE   rQ      z/Already imported a file that will be measured: zalready-importedr   r   z+Didn't trace already imported file {!r}: {})r   r   r   ri   rV   r   modulesvaluesrH   lenr   r   r   r|   r_   r}   shouldr   formatr   r   )r   warnedrC   r/   r   r   s         r,   warn_already_imported_filesz#InOrOut.warn_already_imported_files  sk   < 	4+ 	t/? 	UUFCK..0011  "3
D99#v%%wsJ3344q88((22,  : 	VHVVCIIc(:I;;;JJx((((Z DJ$5$5g$>$> J$$ELL 2DK   1	 	 r.   c                D    | j         D ]}|                     |           dS )zCWarn about source packages that were of interest, but never traced.N)r   _warn_about_unmeasured_code)r   r   s     r,   warn_unimported_sourcezInOrOut.warn_unimported_source  s5    - 	2 	2C,,S1111	2 	2r.   r   c                6   t           j                            |          }||                     d| dd           dS t	          |          rdS t          |          s|                     d| dd           dS d| d}|                     |d	           dS )
z}Warn about a package or module that we never traced.

        `pkg` is a string, the name of the package or module.

        NzModule z was never imported.zmodule-not-importedr   z has no Python source.zmodule-not-pythonz* was previously imported, but not measuredzmodule-not-measured)r   r   r8   r|   rI   rM   )r   r   rC   r   s       r,   r   z#InOrOut._warn_about_unmeasured_code  s     kooc"";II9999@UIVVVFs## 	 Fs## 	II;;;;BUIVVVF
 HGGG		#1	22222r.    Iterable[tuple[str, str | None]]c              #    K   | j         D ]}|t          j        vst          t          j        |                   s0t	          t          t          t          j        |         j                            }|                     t          |                    E d{V  | j
        D ]}|                     |          E d{V  dS )zFind files in the areas of interest that might be untraced.

        Yields pairs: file path, and responsible plug-in name.
        N)r   r   r   rM   r   r   r%   rF   _find_executable_filesr-   r   )r   r   pkg_filer   s       r,   find_possibly_unexecuted_filesz&InOrOut.find_possibly_unexecuted_files  s      
 # 	M 	MC3;&&#CK$455 '&tCS1A1J'K'KLLH22>(3K3KLLLLLLLLLL# 	8 	8C2237777777777	8 	8r.   src_dirIterable[tuple[str, str]]c              #  n   K   | j         j        D ]%}|                    |          D ]}||j        fV  &dS )z&Get executable files from the plugins.N)r   r   find_executable_filesr   )r   r   r   x_files       r,   _find_plugin_fileszInOrOut._find_plugin_files  s]      l/ 	; 	;F 66w?? ; ;f::::::;	; 	;r.   c              #    K   d t          || j                  D             }|                     |          }t          j        ||          D ]<\  }}t          |          }| j        r| j                            |          r6||fV  =dS )a(  Find executable files in `src_dir`.

        Search for files in `src_dir` that can be executed because they
        are probably importable. Don't include ones that have been omitted
        by the configuration.

        Yield the file path, and the plugin name that handles the file.

        c              3     K   | ]}|d fV  	d S r   rQ   )r   py_files     r,   r   z1InOrOut._find_executable_files.<locals>.<genexpr>.  s7       
 
 'WdO
 
 
 
 
 
r.   N)r   r   r   	itertoolschainr   r   r   )r   r   py_filesplugin_files	file_pathr   s         r,   r   zInOrOut._find_executable_files$  s      
 
gt'FGG
 
 
 ..w77&/oh&M&M 	) 	)"I{*955I 4?#8#8#C#C  [(((((	) 	)r.   Iterable[tuple[str, Any]]c                    d| j         fd| j        fd| j        fd| j        fg}g d}|D ]B}t	          | |          }|r|                                }nd}|                    ||f           C|S )z^Our information for Coverage.sys_info.

        Returns a list of (key, value) pairs.
        coverage_pathsstdlib_pathsthird_party_pathssource_in_third_party_paths)r   r   r   r   r   r   r   r   z-none-)r   r   r   r   rH   infor   )r   r  matcher_namesmatcher_namematchermatcher_infos         r,   sys_infozInOrOut.sys_info<  s     t/0T-. $"23*D,FG	

 
 
 * 	6 	6LdL11G (&||~~'KK|45555r.   )
r{   r   r|   r   r}   r~   r   r#   r$   r\   r   )r/   r%   r0   r1   r$   r   r/   r%   r0   r1   r$   r2   )r$   r\   )r   r%   r$   r\   )r$   r   )r   r%   r$   r   )r   r%   r$   r   )r$   r   )r4   
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r  rQ   r.   r,   rz   rz      s       ::zB zB zB zBx` ` ` ` `D; ; ; ;zb b b b   @2 2 2 2
3 3 3 348 8 8 8; ; ; ;) ) ) )0     r.   rz   )F)r!   r   r"   r#   r$   r%   r	  )rC   r   r$   r#   )rN   r%   r$   rO   )rZ   r[   r$   r\   )Er  
__future__r   importlib.utilrR   r;   r   r(   os.pathplatformrer   rj   r   typesr   r   typingr   r   r   collections.abcr	   r   r
   coverage.dispositionr   r   coverage.exceptionsr   r   r   coverage.filesr   r   r   r   r   r   coverage.miscr   r   coverage.pythonr   r   coverage.typesr   r   r   r   coverage.configr   coverage.plugin_supportr   r    __annotations__PYPY_pypy_irc_topic
_structseqr   r-   rB   rI   rM   rY   ra   rr   rx   rz   rQ   r.   r,   <module>r!     sO   D C C " " " " " "          				   				 



         ' ' ' ' ' ' ' '          % $ $ $ $ $       B B B B B B B B K K K K K K K K K K B B B B B B B B B B O O O O O O O O O O ; ; ; ; ; ; ; ; < < < < < < < < F F F F F F F F F F F F 0......////// YHb)Y/      8 D
 $$j/%BCCC ^B       DO O O O
' ' ' '   *	9 	9 	9 	93 3 3 35 5 5 5j j j j j j j j j jr.   