L i_ UdZddlmZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlmZddlmZmZddlmZmZmZddlmZddlmZmZdd lmZmZmZdd l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&dd l'm(Z(m)Z)dd l*m+Z+m,Z,dd l-m.Z.m/Z/m0Z0m1Z1er ddl2m3Z3ddl4m5Z5eeee e e e gZ6de7d<ejprddl9Z9ddl:Z:e6jwe:e9ge(eZdddZddZ?d dZ@d!dZAd!dZBd!dZCGddZDy)"z=Determining whether files are being measured/reported or not.) annotationsN)Iterable) FrameType ModuleType) TYPE_CHECKINGAnycast)env)FileDispositiondisposition_init) ConfigErrorCoverageException PluginError) GlobMatcher ModuleMatcher TreeMatchercanonical_filenamefind_python_files prep_patterns)isolate_modulesys_modules_saved)source_for_filesource_for_morf) TDebugCtlTFileDispositionTMorfTWarnFn)CoverageConfig)Pluginszlist[ModuleType]modules_we_happen_to_havectt|}|jds|r"tjj |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)rrendswithospathsplit)morf directory morf_paths V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/coverage/inorout.pycanonical_pathr*Bs@#?4#89I-(IGGMM),Q/ c| |jni}|jdd}t|tr|dk7r|S|jdd}|r#|j}t|tr|dk7r|St j |}||S|S)aGet 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_globalsget isinstancestrnameinspect getmodulename)filenameframemodule_globals dunder_namespecfullname inspectednames r)name_for_moduler>Ps).(9U__rN,00TBK+s# z(A   j$ /D 99 h $Z)?O))(3M r+c<t|dxrt|ddduS)z5Is the module object `mod` a PEP420 namespace module?__path____file__N)hasattrgetattr)mods r)module_is_namespacerErs" 3 # NZ(F$(NNr+c`t|dd}|ytjj|S)z8Does the module object `mod` have an existing __file__ ?rANF)rCr#r$exists)rD mod__file__s r)module_has_filerIws,#z40K 77>>+ &&r+cd}g} tjj|}|%|j}t |j xsd}||fS#t $rY||fSwxYw)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) importlibutil find_specoriginlistsubmodule_search_locations Exception) modulenamer7r$r;s r)file_and_path_for_modulerTswH D?~~'' 3  {{H77=2>D T>   T>  sA AAcltD]+}t|ds|jt|d-y)z;Add paths where the stdlib can be found to the set `paths`.rATr'N)r rBaddr*)pathsms r)add_stdlib_pathsrZs0'9 1j ! IInQ$7 89r+cttj}|D]]}|dk(rdn|}tj|j dvs.tj |}dD]}|j||_y)z:Add locations for third-party packages to the set `paths`.pypy pypy_posix_)platlibpurelibscriptsN)set sysconfigget_scheme_namesr#r4r% get_pathsrW)rX scheme_namesscheme better_scheme config_paths path_names r)add_third_party_pathsrks{y1134L3(.&(8 f 77m))#. .$..v6L> 3  ,y12 3 3r+cttd}|j|tjr0|jt j j|dyy)zAAdd paths where coverage.py code can be found to the set `paths`.TrVtestsN)r*rArWr TESTINGr#r$join)rX cover_paths r)add_coverage_pathsrqsAD9J IIj {{ "'',,z734r+c~eZdZdZ ddZdddZddZddZddZddZ dd Z dd Z dd Z dd Z dd Zy)InOrOutz0Machinery for determining what files to measure.c  |_|_|_g_jj |jg_j j |j |j xsgD]X}tjj|rj j|>jj|Ztj D]J\}}tjj|std|t|j |<Ljdd_t|j _t|j$_t)_|j,st/j*t)_t3j0t)_t7j4d!fd }|ddj9dt:jDzd_d_d_ dx_!_"j s jrg}j r9tGj d_|jdj<jr9tIjd_|jd j>|d d j9|zn<j*r0tGj*d _ |d j@j"r0tKj"d_!|djBj&r0tKj&d_"|djDtGj0d_&|djLtGj4d_'|djNt)_(tS5jD]} tU| \} } |d| d| | rXjNjY| s>|d| d| jPj[t]t_| z| D]G} jNjY| s|d| d| jPj[| I dddj D]D}jNjY|s|d|jPj[|FtGjPd_0|d j`tb_2y#tV$r} |d| d| Yd} ~ d} ~ wwxYw#1swYxYw)"NzSource dir is not a directory: cVjrjj|yyN)debugwrite)msgselfs r)_debugz InOrOut.__init__.._debugs!zz   %r+z sys.path:c3&K|] }d| yw)z NrK).0ps r) z#InOrOut.__init__..s$DavaS\$Dssourceztrees source_pkgszmodules zSource matching against z and pylibzPython stdlib matching: includezInclude matching: omitzOmit matching: coveragezCoverage code matching: thirdzThird-party lib matching: zImported source package z as zCouldn't import source package z: z"Source in third-party: source_pkg z at zSource in third-party: z path directory at z(Source in third-party: source directory source_in_thirdz Source in third-party matching: )ryr3returnNone)3warnrwinclude_namespace_packagesrextend source_dirsrr#r$isdirappend enumerater rsource_pkgs_unmatchedr run_includerrun_omitrrb pylib_paths cover_pylibrZ cover_pathsrq third_pathsrkrosys source_matchsource_pkgs_match pylib_match include_match omit_matchrrr cover_match third_matchsource_in_third_pathsrrTrmatchrWr*rsource_in_third_matchr disp_class)rzconfigrrwrsrcir{againstpkgmodfiler$excpathdirs` r)__init__zInOrOut.__init__s3  *D'&(  2 23&(  2 23==&B -Cww}}S!  '',  '',  -  0 01 :FAs77==%!$CC7"KLL"4S"9D  Q  : &*%5%5a%8"$V%7%78 !&//2 &)U!! T-- .&)U4++,&)Ud../ & {RWW$D388$DDDE!!%/33T_   t//G$/0@0@($K!(9(9'<=>)6t7G7G)W&$*@*@)CDE - W0EE F#.t/?/?#I 1$2B2B1EFG < ? 99)$))V?&t'7'7A+D,<,<+?@A &)U"   D'' D$.nopeBsDJ DKKr+? ?   //Meoo.A.A*.MK*3{+;<$->-I-I#-N77++,=>Drww//99$5>? ?   y )67 7   s # 56 6&x0 "+ll// -F++ $00; *39K0!%DJ'2D$">>@481/A'7790,+  -2DJ#,D ((''!fZ'HI_I_H``ab001E1EuMFT6" ) $:: ))+ .{o=TUWTXYZ+0(  sAHAI I ct||}|js |jrd}d}|jr]t|trG|jj |r,d}||j vr"|j j|nd|d}|s)|jr|jj |rd}|s|dzS|jj |r|jj |sy|jr|jj |say|jj |ry |jr|jj |ry |jj |ry |jr|jj |ry |jd y#t$rYywxYw)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|FTzmodule  zfalls outside the --source specz#inside --source, but is third-partyz!falls outside the --include treeszis part of coverage.pyzis in the stdlibzis a third-party modulezis inside an --omit patternzutf-8znon-encodable filenameN)r>rrr2r3rrremoverrrrrrencodeUnicodeEncodeError)rzr7r8rSextraoks r)rzInOrOut.check_include_omit_etcs%Xu5    6 6EB%%j#.43I3I3O3OPZ3[B!T%?%??2299*E%j^15E$++$$**84B@@@%%h/8R8R8X8XYa8b<   %%++H5:%%h//D$4$4$:$:8$D)%%h/0 ??t44X>0 , OOG $  " ,+ ,s,F>> G  G cv|jr-|js |jr|jddyyy)z)Warn if there are settings that conflict.z,--include is ignored because --source is setzinclude-ignoredslugN)rrrr)rzs r)warn_conflicting_settingsz!InOrOut.warn_conflicting_settingss6 <<4#3#3 HO` a$4 r+c|js|js |jr"t}t t j jD]}t|dd}|||vrtt|dddkDr2|j|}|jrP|jr*d|}|j|d|j||js|jj!d s|jj#d j%|j&|j(yy) zCWarn if files have already been imported that we will be measuring.rANr@rKz/Already imported a file that will be measured: zalready-importedrrz+Didn't trace already imported file {!r}: {})rrrrbrPrmodulesvaluesrClenrrrrrWrwshouldrxformatrr)rzwarnedrDr7rrys r)warn_already_imported_filesz#InOrOut.warn_already_imported_filess <<4++t/?/?UFCKK..01 "3 D9#v%wsJ34q8((2,,::KH:VCIIc(:I;JJx(ZZDJJ$5$5g$>JJ$$ELL 22 KK- 0@r+cH|jD]}|j|y)zCWarn about source packages that were of interest, but never traced.N)r_warn_about_unmeasured_code)rzrs r)warn_unimported_sourcezInOrOut.warn_unimported_sources%-- 2C  , ,S 1 2r+ctjj|}||jd|ddyt |ryt |s|jd|ddyd|d}|j|d y) z}Warn about a package or module that we never traced. `pkg` is a string, the name of the package or module. NzModule z was never imported.zmodule-not-importedrz has no Python source.zmodule-not-pythonz* was previously imported, but not measuredzmodule-not-measured)rrr1rrErI)rzrrDrys r)rz#InOrOut._warn_about_unmeasured_codes kkooc" ; IIu$89@UI V  s # s# IIu$:;BUI V  uFG #1 2r+c#K|jD]}|tjvsttj|s2t t t tj|j}|jt|Ed{|jD]}|j|Ed{y717 w)zFind files in the areas of interest that might be untraced. Yields pairs: file path, and responsible plug-in name. N) rrrrIrr r3rA_find_executable_filesr*r)rzrpkg_filers r)find_possibly_unexecuted_filesz&InOrOut.find_possibly_unexecuted_filess ## MC#++%_S[[=M-N&tCS1A1J1J'KLH22>(3KL L L  M ## 8C2237 7 7 8 M 8s$BCC)C<C=CCc#K|jjD](}|j|D]}||jf*yw)z&Get executable files from the plugins.N)rrfind_executable_filesr)rzsrc_dirrx_files r)_find_plugin_fileszInOrOut._find_plugin_files)sJll// ;F 66w? ;f:::: ; ;sAAc#Kdt||jD}|j|}tj||D]>\}}t |}|j r|j j|r9||f@yw)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. c3$K|]}|df ywrvrK)r~py_files r)rz1InOrOut._find_executable_files..9s dO sN)rrr itertoolschainrrr)rzrpy_files plugin_files file_pathrs r)rzInOrOut._find_executable_files/s ,Wd6U6UV ..w7 &/ooh &M ) "I{*95I4??#8#8#C[( (  )sBB cd|jfd|jfd|jfd|jfg}gd}|D]6}t ||}|r|j }nd}|j ||f8|S)z^Our information for Coverage.sys_info. Returns a list of (key, value) pairs. coverage_paths stdlib_pathsthird_party_pathssource_in_third_party_paths)rrrrrrrrz-none-)rrrrrCinfor)rzr matcher_names matcher_namematcher matcher_infos r)sys_infozInOrOut.sys_infoGs t// 0 T-- . $"2"2 3 *D,F,F G    * 6LdL1G&||~ ' KK|4 5  6 r+) rrrrrwzTDebugCtl | Nonerboolrrrv)r7r3r8FrameType | Nonerrr7r3r8rrz str | None)rr)rr3rr)r Iterable[tuple[str, str | None]])rr3rzIterable[tuple[str, str]])rr3rr)rzIterable[tuple[str, Any]])r- __module__ __qualname____doc__rrrrrrrrrrrrKr+r)rsrss~:zBzBzB zB %) zB  zBx`D;zb B2 34 8; )0r+rs)F)r&rr'rrr3r)rDrrr)rSr3rztuple[str | None, list[str]])rXzset[str]rr)Er __future__rimportlib.utilrLr5rr#os.pathplatformrerrcrcollections.abcrtypesrrtypingrrr rr coverage.dispositionr r coverage.exceptionsr rrcoverage.filesrrrrrr coverage.miscrrcoverage.pythonrrcoverage.typesrrrrcoverage.configrcoverage.plugin_supportrr __annotations__PYPY_pypy_irc_topic _structseqrr*r>rErIrTrZrkrqrsrKr+r)rsD"  $'++BKK<<FF./     /+88 $$j/%BCB DO '* 9 35oor+