grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026B Ôã8º[Ûöã@sòdZddgZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlZdZGdd„dƒZd d „Zd d „ZGd d„dƒZdd„Zdd„Zddd„Zdd„ZGdd„dƒZdd„ZedkrîeƒdS)a·program/module to trace Python program or function execution Sample use, command line: trace.py -c -f counts --ignore-dir '$prefix' spam.py eggs trace.py -t --ignore-dir '$prefix' spam.py eggs trace.py --trackcalls spam.py eggs Sample use, programmatically import sys # create a Trace object, telling it what to ignore, and whether to # do tracing or line-counting or both. tracer = trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,], trace=0, count=1) # run the new command using the given tracer tracer.run('main()') # make a report, placing output in /tmp r = tracer.results() r.write_results(show_missing=True, coverdir="/tmp") ÚTraceÚCoverageResultséN)Ú monotonicz#pragma NO COVERc@seZdZddd„Zdd„ZdS)Ú_IgnoreNcCs:|s tƒnt|ƒ|_|sgn dd„|Dƒ|_ddi|_dS)NcSsg|]}tj |¡‘qS©)ÚosÚpathÚnormpath)Ú.0Údrrú*/opt/alt/python37/lib64/python3.7/trace.pyú Hsz$_Ignore.__init__..zé)ÚsetÚ_modsÚ_dirsÚ_ignore)ÚselfÚmodulesÚdirsrrr Ú__init__Fs z_Ignore.__init__cCsª||jkr|j|S||jkr,d|j|<dSx*|jD] }| |d¡r4d|j|<dSq4W|dkrnd|j|<dSx,|jD]"}| |tj¡rvd|j|<dSqvWd|j|<dS)NrÚ.r)rrÚ startswithrrÚsep)rÚfilenameÚ modulenameÚmodr rrr ÚnamesLs$          z _Ignore.names)NN)Ú__name__Ú __module__Ú __qualname__rrrrrr rEs rcCs tj |¡}tj |¡\}}|S)z-Return a plausible module name for the patch.)rrÚbasenameÚsplitext)rÚbaserÚextrrr Ú_modnamews r%cCsÆtj |¡}d}xJtjD]@}tj |¡}| |¡r|t|ƒtjkrt|ƒt|ƒkr|}qW|rv|t|ƒdd…}n|}tj |¡\}}| tjd¡}tj r¬| tj d¡}tj  |¡\}}|  d¡S)z,Return a plausible module name for the path.ÚrNr) rrÚnormcaseÚsysrÚlenrÚ splitdriveÚreplaceÚaltsepr"Úlstrip)rZ comparepathZlongestÚdirr#Zdriverr$rrr Ú _fullmodname~s    r/c@s:eZdZddd„Zdd„Zdd„Zdd d „Zdd d „ZdS)rNc Csþ||_|jdkri|_|j ¡|_||_|jdkr8i|_|j ¡|_||_|jdkrZi|_|j ¡|_||_||_|jrúy@t|jdƒ�}t  |¡\}}}WdQRX|  |  |||¡¡Wn@t t tfk rø}ztd|j|ftjd�Wdd}~XYnXdS)NÚrbzSkipping counts file %r: %s)Úfile)ÚcountsÚcopyZcounterÚ calledfuncsÚcallersÚinfileÚoutfileÚopenÚpickleÚloadÚupdateÚ __class__ÚOSErrorÚEOFErrorÚ ValueErrorÚprintr(Ústderr)rr2r4r6r5r7ÚfÚerrrrr r›s,      zCoverageResults.__init__cCs| d¡o| d¡S)z_Return True if the filename does not refer to a file we want to have reported. ú<ú>)rÚendswith)rrrrr Úis_ignored_filenameµsz#CoverageResults.is_ignored_filenamec Csz|j}|j}|j}|j}|j}|j}x$|D]}| |d¡||||<q*Wx|D] }d||<qPWx|D] }d||<qfWdS)z.Merge in the data from another CoverageResultsrrN)r2r4r5Úget) rÚotherr2r4r5Z other_countsZother_calledfuncsZ other_callersÚkeyrrr r;»s    zCoverageResults.updateTFc! Csô|jrDtƒtdƒ|j}x(t|ƒD]\}}}td|||fƒq$W|jrØtƒtdƒd}} xvt|jƒD]h\\} } } \} }}| |kr¢tƒtd| dƒ| }d} | | krÀ| | krÀtd| ƒ| } td| | ||fƒqlWi}x8|jD].\}}| |i¡}||<|j||f||<qäWi}�x$| ¡D�]\}}| |¡�r@�q&| d¡�rX|d d …}|d k�r€t j   t j   |¡¡}t |ƒ}n$|}t j  |¡�sœt  |¡t|ƒ}|�r´t|ƒ}ni}t |¡}t j  ||d ¡}t|d ƒ�}t |j¡\}}Wd QRX| |||||¡\}}|�r&|�r&td ||ƒ}||||f||<�q&W|�rŠ|�rŠtdƒx2t|ƒD]&}||\}}}}td||ƒ�q`W|j�rðy&t |j|j|jft|jdƒd¡Wn6tk �rî} ztd| tj d�Wd d } ~ XYnXd S)af Write the coverage results. :param show_missing: Show lines that had no hits. :param summary: Include coverage summary per module. :param coverdir: If None, the results of each module are placed in its directory, otherwise it is included in the directory specified. zfunctions called:z*filename: %s, modulename: %s, funcname: %szcalling relationships:r&z***z -->z %s.%s -> %s.%sz.pycNéÿÿÿÿz.coverr0édzlines cov% module (path)z%5d %3d%% %s (%s)Úwbrz"Can't save counts files because %s)r1)!r4r@Úsortedr5r2rHÚitemsrGrFrrÚdirnameÚabspathr%ÚexistsÚmakedirsr/Ú_find_executable_linenosÚ linecacheÚgetlinesÚjoinr8ÚtokenizeÚdetect_encodingÚreadlineÚwrite_results_fileÚintr7r9Údumpr=r(rA)!rZ show_missingÚsummaryÚcoverdirZcallsrrÚfuncnameZlastfileZ lastcfileZpfileZpmodZpfuncÚcfileZcmodZcfuncZper_fileÚlinenoÚ lines_hitZsumsÚcountr.ÚlnotabÚsourceZ coverpathÚfpÚencodingÚ_Ún_hitsÚn_linesZpercentÚmrCrrr Ú write_resultsÍs|              zCoverageResults.write_resultsc Csîyt|d|d�}Wn8tk rJ}ztd||ftjd�dSd}~XYnXd}d} |�ˆx€t|dƒD]r\} } | |krš| d || ¡| d7} |d7}n.| |kr¾t| kr¾| d ¡|d7}n | d ¡| |  d ¡¡qfWWdQRX| |fS) z'Return a coverage results file in path.Úw)rhz3trace: Could not open %r for writing: %s - skipping)r1)rrNrrz%5d: z>>>>>> z é) r8r=r@r(rAÚ enumerateÚwriteÚPRAGMA_NOCOVERÚ expandtabs) rrÚlinesrercrhr7rCrkrjrbÚlinerrr r[(s(    z"CoverageResults.write_results_file)NNNNN)TFN)N)rrr rrGr;rmr[rrrr ršs   [cCs0i}x&t |¡D]\}}||krd||<qW|S)z:Return dict where keys are lines in the line number table.r)ÚdisZfindlinestarts)ÚcodeÚstrsÚlinenosrirbrrr Ú_find_lines_from_codeHs  rzcCs8t||ƒ}x(|jD]}t |¡r| t||ƒ¡qW|S)z|s&tdƒ‚n0d|krB| d¡}|^}}ntdt|ƒdƒ‚d}|jslt |j¡z|||Ž}Wd|jsŒt d¡X|S)Néz8descriptor 'runfunc' of 'Trace' object needs an argumentÚfuncz7runfunc expected at least 1 positional argument, got %dr)r)Ú TypeErrorÚpoprŽr(r©r–)ÚargsÚkwrr­Úresultrrr ÚrunfuncÈs"       z Trace.runfuncc Csð|j}|j}|rt|ƒ}nd}|j}d}||jkrL|j|dk rÒ|j|}n†d|j|<dd„t |¡Dƒ}t|ƒdkrÒdd„t |d¡Dƒ}t|ƒdkrÒdd„t |d¡Dƒ} t| ƒdkrÒ| dj}||j|<|dk ræd||f}|||fS)NcSsg|]}t |¡r|‘qSr)r|Z isfunction)r rBrrr r ðsz1Trace.file_module_function_of..rcSsg|]}t|tƒr|‘qSr)Ú isinstancer¦)r r rrr r ösrcSsg|]}t|dƒr|‘qS)Ú __bases__)Úhasattr)r r~rrr r ùsz%s.%s) Úf_codeÚ co_filenamer%Úco_namer’ÚgcZ get_referrersr)r) rÚframerwrrr`ZclsnameZfuncsZdictsÚclassesrrr Úfile_module_function_ofßs,          zTrace.file_module_function_ofcCs0|dkr,| |¡}| |j¡}d|j||f<dS)zkHandler for call events. Adds information about who called who to the self._callers dict. ÚcallrN)r½Úf_backr‘)rr»ÚwhyÚargÚ this_funcZ parent_funcrrr r•s  zTrace.globaltrace_trackcallerscCs |dkr| |¡}d|j|<dS)zoHandler for call events. Adds (filename, modulename, funcname) to the self._calledfuncs dict. r¾rN)r½r�)rr»rÀrÁrÂrrr r—s zTrace.globaltrace_countfuncscCsj|dkrf|j}|j dd¡}|rbt|ƒ}|dk rf|j ||¡}|sf|jrZtd||jfƒ|j SndSdS)z’Handler for call events. If the code block being entered is to be ignored, returns `None', else returns self.localtrace. r¾Ú__file__Nz! --- modulename: %s, funcname: %s) r·Ú f_globalsrHr%r�rr�r@r¹rš)rr»rÀrÁrwrrZ ignore_itrrr r˜szTrace.globaltrace_ltcCs„|dkr~|jj}|j}||f}|j |d¡d|j|<|jrTtdtƒ|jdd�tj   |¡}td||t   ||¡fdd�|j S) Nrurrz%.2fú )r†z %s(%d): %sr&)r·r¸Úf_linenor2rHr“r@r”rrr!rUÚgetlinerš)rr»rÀrÁrrbrJÚbnamerrr r™3s z Trace.localtrace_trace_and_countcCsd|dkr^|jj}|j}|jr4tdtƒ|jdd�tj |¡}td||t   ||¡fdd�|j S)Nruz%.2frÅ)r†z %s(%d): %sr&) r·r¸rÆr“r@r”rrr!rUrÇrš)rr»rÀrÁrrbrÈrrr r›Bs zTrace.localtrace_tracecCs<|dkr6|jj}|j}||f}|j |d¡d|j|<|jS)Nrurr)r·r¸rÆr2rHrš)rr»rÀrÁrrbrJrrr rœOs zTrace.localtrace_countcCst|j|j|j|j|jd�S)N)r6r7r4r5)rr2r6r7r�r‘)rrrr ÚresultsWs z Trace.results) rrrrrrNNF)NN)rrr rr§r¤r³r½r•r—r˜r™r›rœrÉrrrr rƒs 0 )   c stddl}| ¡}|jdddd�| dd¡}|jdd d d d �|jd dd dd �|jddd dd �|jddd dd �| d¡}| ¡}|jddd dd �|jddd dd �|jdddd �|jd!d"d#d �|jd$d%d d&d �|jd'd(d d)d �|jd*d+d d,d �| d-d.¡}|jd/d0gd1d2�|jd3d0gd4d2�|jd5d6d7d8�|jd9|jd:d8�| ¡}|j�rvt  d;¡‰t  d<¡‰‡‡fd=d>„‰d?d@„|j Dƒ|_ ‡fdAd@„|jDƒ|_|j �rê|j �sÆ|  dB¡t|j |j dC�}| |j|j|j¡St|j|j|j|jgƒ�s|  dD¡|j�r0|j�s&|j�r0|  dE¡|j�rJ|j�sJ|  dF¡|jdk�r`|  dG¡|jf|j•t_tj |j¡tjd<t|j|j|j|j|j |j|j |j |j dH� }yJt!|jƒ�}t"| #¡|jdIƒ}WdQRX|jdJdddKœ} | $|| | ¡WnPt%k �r6} zt &dLtjd| f¡Wdd} ~ XYnt'k �rJYnX| (¡}|j)�sp| |j|j|j¡dS)MNrz --versionÚversionz trace 2.0)ÚactionrÊz Main optionsz(One of these (or --report) must be givenz-cz--countÚ store_truez»Count the number of times each line is executed and write the counts to .cover for each module executed, in the module's directory. See also --coverdir, --file, --no-report below.)rËÚhelpz-tz--tracez3Print each line to sys.stdout before it is executedz-lz --listfuncsz§Keep track of which functions are executed at least once and write the results to sys.stdout after the program exits. Cannot be specified alongside --trace or --count.z-Tz --trackcallsz^Keep track of caller/called pairs and write the results to sys.stdout after the program exits.Z Modifiersz-rz--reportz¶Generate a report from a counts file; does not execute any code. --file must specify the results file to read, which must have been created in a previous run with --count --file=FILEz-Rz --no-reportz^Do not generate the coverage report files. Useful if you want to accumulate over several runs.z-fz--filez+File to accumulate counts over several runs)rÍz-Cz --coverdirz†Directory where the report files go. The coverage report for . will be written to file //.coverz-mz --missingz?Annotate executable lines that were not executed with ">>>>>> "z-sz --summaryz\Write a brief summary for each file to sys.stdout. Can only be used with --count or --reportz-gz--timingzQPrefix each line with the time since the program started. Only used while tracingZFilterszCan be specified multiple timesz--ignore-moduleÚappendzqIgnore the given module(s) and its submodules (if it is a package). Accepts comma separated list of module names.)rËÚdefaultrÍz --ignore-dirzWIgnore files in the given directory (multiple directories can be joined by os.pathsep).rú?zfile to run as main program)ÚnargsrÍÚ argumentszarguments to the programZstdlibZ platstdlibcs4tj tj |¡¡}| dˆ¡ dˆ¡}tj |¡S)Nz$prefixz $exec_prefix)rrÚ expanduserÚ expandvarsr+r )Ús)Ú _exec_prefixÚ_prefixrr Úparse_ignore_dir¦szmain..parse_ignore_dircSs$g|]}| d¡D] }| ¡‘qqS)ú,)ÚsplitÚstrip)r r‡rrrr r «szmain..cs&g|]}| tj¡D] }ˆ|ƒ‘qqSr)rÚrÚpathsep)r r‡rÕ)rØrr r ­sz-r/--report requires -f/--file)r6r7zLmust specify one of --trace, --count, --report, --listfuncs, or --trackcallsz8cannot specify both --listfuncs and (--trace or --count)z3--summary can only be used with --count or --reportz3filename is missing: required with the main options)r�ržrŸr r6r7r¡r‰r¢)rÃrÚ __package__Ú __cached__zCannot run file %r because: %s)*ÚargparseÚArgumentParserÚ add_argumentZadd_argument_groupZadd_mutually_exclusive_groupZ REMAINDERÚ parse_argsZ ignore_dirÚ sysconfigZget_pathZ ignore_moduleZreportr1ÚerrorrrmZmissingr^r_Úanyr�rdZ listfuncsZ trackcallsrrÒr(ÚargvrrrPrr¡r8r‹rŠr¤r=ÚexitÚ SystemExitrÉZ no_report) rßÚparserZgrpZ_grpZoptsrÉÚtrgrwZglobsrCr)rÖr×rØr Úmain]s¤                         (rër¢)N)Ú__doc__Ú__all__rUrÚrer(rãrrXr|rºrvr9Ztimerr”r¨rrrr%r/rrzr}rˆrTrrërrrrr Ú1s< 2/  [