L imHdZddlmZddlZddlZddlZddlZddlmZddl m Z ddl m Z m Z mZmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZmZdd lmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(eeZedZ)GddZ*y)z#Raw data collector for coverage.py.) annotationsN)Mapping) FrameType)AnyCallableTypeVarcast)env)Core) CoverageData) short_stack) ConfigError)human_sorted_itemsisolate_module)CoveragePlugin) TArcTCheckIncludeFnTFileDispositionTracerTShouldStartContextFnTShouldTraceFn TTraceDataTTraceFnTWarnFnTceZdZUdZgZded< ddZddZddZddZ ddZ dd Z dd Z dd Z dd Zd d ZddZddZddZddZddZd!dZd"dZd#dZej2d$dZd%dZd&dZd!dZy)' CollectoraCollects trace data. Creates a Tracer object for each thread, since they track stack information. Each Tracer points to the same shared data, contributing traced data points. When the Collector is started, it creates a Tracer for the current thread, and installs a function to create Tracers for each new thread started. When the Collector is stopped, all active Tracers are stopped. Threads started while the Collector is stopped will never have Tracers associated with them. zlist[Collector] _collectorsc ||_||_||_||_||_||_||_t|ts Jd|tj|_ |d|_ d|_ t|_d|_d} d} d|vrd} ddl} | j$|_nAd|vr"d} ddl} | j(j$|_nd|vrd} ddl} | j$|_d |vrd } |j r?t1|j2d s)t/dj5| |j7| s|s ddl }||_ |j9y#t,$r}d | d }t/||d}~wwxYw)aCreate a collector. `should_trace` is a function, taking a file name and a frame, and returning a `coverage.FileDisposition object`. `check_include` is a function taking a file name and a frame. It returns a boolean: True if the file should be traced, False if not. `should_start_context` is a function taking a frame, and returning a string. If the frame should be the start of a new context, the string is the new context. If the frame should not be the start of a new context, return None. `file_mapper` is a function taking a filename, and returning a Unicode filename. The result is the name that will be recorded in the data file. If `branch` is true, then branches will be measured. This involves collecting data on which statements followed each other (arcs). Use `get_arc_data` to get the arc data. `warn` is a warning function, taking a single string message argument and an optional slug argument which will be a string or None, to be used if a warning needs to be issued. `concurrency` is a list of strings indicating the concurrency libraries in use. Valid values are "greenlet", "eventlet", "gevent", or "thread" (the default). "thread" can be combined with one of the other three. Other values are ignored. zExpected a list: NFnothinggreenletreventletgeventthreadTz Couldn't trace with concurrency=z, the module isn't installed.concur_id_funczACan't support concurrency={} with {}, only threads are supported.)core should_trace check_includeshould_start_context file_mapperbranchwarn isinstancelistosgetpidpid threadingstatic_contextr originr%r! getcurrenteventlet.greenthread greenthreadr# ImportErrorrhasattr tracer_classformat tracer_namereset)selfr&r'r(r)r*r+r, concurrency do_threadingtriedr!r"r#exmsgr2s X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/coverage/collector.py__init__zCollector.__init__>sT (*$8!&  +t,Q0A+.QQ,99; *.!m "  +[("&.&9&9#{*"+&.&:&:&E&E#[( &,&7&7#;&#   wt/@/@BR'SSZZ$$&  { &DN ) +4UG;XYCc" * +sA#E E>'E99E>cDdt|dd|jdS)Nz)idr<r>s rD__repr__zCollector.__repr__s'4}Bt/?/?/A.B!DDcj||_||_|jj|jy)z!Use `covdata` for recording data.N)covdatar3 set_context)r>rNcontexts rDuse_datazCollector.use_datas) %   !4!45rLcB|jjjS)z0Return the class name of the tracer we're using.)r&r:__name__rJs rDr<zCollector.tracer_namesyy%%...rLc|jxstj5|jj D]}|j  ddd|j D]}|jy#1swY+xYw)zdtracers rD _clear_datazCollector._clear_datast ^^ 7z557 YY%%'    ll $F  ! ! # $   s 0A>>Bc*|jr|jjnd|_i|_i|_t |_tjrddl }|jd|_ ni|_ g|_ |jy)z2Clear collected data, and prepare to collect more.Nrmodule)r2LockrUrX file_tracerssetdisabled_pluginsr PYPY__pypy__newdictshould_trace_cacher[r_)r>rgs rDr=zCollector.resetsy26..,,.d!# -/*-% 88  '/&6&6x&@D #&(D #&(  rLcR|j|jjyy)z-Lock self.data_lock, for use by the C tracer.N)rUacquirerJs rD lock_datazCollector.lock_data! >> % NN " " $ &rLcR|j|jjyy)z/Unlock self.data_lock, for use by the C tracer.N)rUreleaserJs rD unlock_datazCollector.unlock_datarmrLc@|jjdi|jj}|j|_|j|_|j |_|j |_|j|_|j|_ |j|_ t|dr|j|_ t|dr|j|_ t|dr|j|_t|dr|j|_t|dr|j |_t|dr|j"|_t|dr|j$|_|j'}|j(j+||S) z8Start a new Tracer object, and store it in self.tracers.r%rcr2r(r)switch_contextdisable_plugin)r&r: tracer_kwargsrXrlrpr+ trace_arcsr'rir,r9r%rcr2r(r)rrrsstartr[append)r>r^fns rD _start_tracerzCollector._start_tracersI'''B$))*A*ABii >>!-- KK"//$($;$;!ii 6+ ,$($7$7F ! 6> *"&"3"3F  6; '#~~F  6? +#'#5#5F 61 2*.*C*CF ' 6+ ,$($7$7F ! 6+ ,$($7$7F ! \\^ F# rLchtjd|j}|r ||||}|S)z0Called on new threads, installs the real tracer.N)syssettracerz)r>frameeventargrys rD_installation_tracezCollector._installation_trace s6 T"002 E5#&B rLcfg}|jD]=}|j|jk(r|j|.|j?||jdd|jr|jdj g|_ |j |jj||jjr3|jr&|jj|jyyy#|jr|jdjxYw)z#Start collecting trace information.N) rr1rx post_forkpauser[rzresumer&systracer2r}r)r>keep_collectorscs rDrwzCollector.start-s !! Auu &&q)   .      R & & (       % 99  $.. NN # #D$<$< =#1    $++- s D,D0c|jsJ|jd|ur7td|jD]}td|d|j|jd|usJd|d|jd|j|jj |jr|jdj yy)z"Stop collecting trace information.rzself._collectors:z  z!Expected current collector to be z , but it's N)rprintr4rpopr)r>rs rDstopzCollector.stopPs   B t + % &%% .1%r!((,- .#t+ /x{4CSCSTVCWBZ [ +        R ' ' ) rLcf|jD]z}|j|j}|s&td|jj dt |jD]\}}t|dd|||jr|jjdyy)z+Pause tracing, but be prepared to `resume`.z Coverage.py z stats:z>20rGN) r[r get_statsr __class__rSritemsr2r})r>r^statskvs rDrzCollector.pausebsll +F KKM$$&Ev'7'7'@'@&AIJ.u{{}=+DAqQsG2aS/*+  + >> NN # #D ) rLc|jD]}|j|jjrC|jr&|jj |j y|jyy)zResume tracing after a `pause`.N)r[rwr&rr2r}rrzr>r^s rDrzCollector.resumens[ll F LLN  99  ~~''(@(@A""$ rLc`|jD]}t|ds|j!y)z+After a fork, tracers might need to adjust.rN)r[r9rrs rDrzCollector.post_forkxs+ll #Fv{+  " #rLc:td|jDS)zkHas any activity been traced? Returns a boolean, True if any trace function was invoked. c3<K|]}|jyw)N)activity).0r^s rD z&Collector._activity..s@6??$@s)anyr[rJs rD _activityzCollector._activity~s @4<<@@@rLc|j|jr|j}|r |d|zz }n|}|jj|y)z Switch to a new dynamic context.|N) flush_datar3rNrO)r> new_contextrPs rDrrzCollector.switch_contextsK    ))G3,,!G   )rLc|j}|J|j}|j}|jd|dd|_d|_y)z.Disable the plugin mentioned in `disposition`.NzDisabling plug-in z due to previous exceptionF) file_tracer_coverage_plugin_coverage_plugin_namer,_coverage_enabledtrace)r> dispositionrplugin plugin_names rDrszCollector.disable_pluginsV!-- &&&--22  &{o5OPQ#( ! rLc$|j|S)zBA locally cached version of file names mapped through file_mapper.)r*)r>filenames rDcached_mapped_filezCollector.cached_mapped_files))rLcd}tdD]} t|j}nt |t sJ||Dcic]\}}|s |j ||c}}S#t$r }|}Yd}~ld}~wwxYwcc}}w)zr] runtime_err_rrBrrs rDmapped_file_dictzCollector.mapped_file_dicts  q A QWWY k95 55 :?E$!Q1''*A-EE  !  !Fs#A* BB* A?3A::A?cN|jj|jy)z1Record that `plugin` was disabled during the run.N)readdr)r>rs rDplugin_was_disabledzCollector.plugin_was_disableds !!&">">?rLc|jsy|jr |jjri}t t t ttf|j}t|jD]P\}}g}t|D]6}|dz}|dzdz }|dzr|dz}|dzr|dz}|j||f8|||<Rn.t t t ttf|j}|jj|j!|nXt t t ttf|j} |jj#|j!| |j$jD cic]\} } | |j&vs| | } } } |jj)|j!| |j+ycc} } w) zSave the collected data to our associated `CoverageData`. Data may have also been saved along the way. This forces the last of the data to be saved. Returns True if there was data to save, False if not. FillrlT)rr+r& packed_arcsr dictstrrdintrXr.rrxrrNadd_arcsr add_linesrcreadd_file_tracersr_) r>arc_data packed_datafnamepackedstuplespackedl1l2 line_datarrrcs rDrzCollector.flush_datas~~ ;;yy$$35"4SX #6 B '+;+<+<+>&? -NE7F"&w-0#g-$ 62=!W-"HB!W-"HB r2h/0'-HUO - S$t*_ 5tyyA LL ! !$"7"7"A BT#s3x-0$))F*$ *%# A *"__**F(@-rLr)+r __future__rrVrr/r|collections.abcrtypesrtypingrrrr coverager coverage.corer coverage.datar coverage.debugr coverage.exceptionsr coverage.miscrrcoverage.pluginrcoverage.typesrrrrrrrrrrrrtrLrDrsl*" #//&&+<*   B CL}}rL