
    <Bh ^                     z   S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
JrJrJr  SSKJr  SSKJr  SSKJr  SSKJrJr  SS	KJrJr  SS
KJrJr  SSKJr  SSKJrJ r J!r!J"r"J#r#  SSK$J%r%J&r&J'r'J(r(  SSK)J*r*J+r+J,r,J-r-  SSK.J/r/J.r.  SSK0J1r1  SSK2J3r3  SSK4J5r5  SSK6J7r7  SSK8J9r9J:r:  SSK;J<r<  SSK=J>r>  \#" \?5      r@\A" \R                  S5      =(       a    \R                  R                  5       rD " S S\!5      rE\5" \R                  R                  S5      5      (       a	  \E" S5      rHO\!" S5      rHSFS jrI " S  S!5      rJ " S" S#\J5      rK\K" 5       rL " S$ S%\5      rM\SGS& j5       rN\SHS' j5       rO\SIS( j5       rP\\MR                  \MR                  4S) j5       rR\S* 5       rS\7" S+S,S-S.9\S/ 5       5       rT\S0 5       rU\SIS1 j5       rV\ SS2SS4S3 jrWSS4.S5 jrX\7" S6S+S7S.9 " S8 S95      5       rY\7" S6S+S:S.9 " S; S<5      5       rZ " S= S>\	5      r[ " S? S@\5      r\\rSA r] " SB SC\J5      r^SD r_\?SE:X  a  \_" 5         gg)JzCommon I/O utilities.    N)defaultdict)ExecutorFutureThreadPoolExecutor_baseas_completed)	_WorkItem)contextmanager)Enum)EPIPE	ESHUTDOWN)partialwraps)BytesIOStringIO)cycle)CRITICALWARN	FormatterStreamHandler	getLogger)dirnameisdirisfilejoin)EventLockRLockThread)sleeptime   )memoizemethod)NullHandler)boolify)
deprecated   )encode_environmenton_win)NULL)expandisattyc                   <   ^  \ rS rSrSrSU 4S jjrU 4S jrSrU =r$ )DeltaSecondsFormatter$   aW  
Logging formatter with additional attributes for run time logging.

Attributes:
  `delta_secs`:
    Elapsed seconds since last log/format call (or creation of logger).
  `relative_created_secs`:
    Like `relativeCreated`, time relative to the initialization of the
    `logging` module but conveniently scaled to seconds as a `float` value.
c                 >   > [        5       U l        [        TU ]  XS9  g )N)fmtdatefmt)r!   	prev_timesuper__init__)selfr1   r2   	__class__s      /lib/python3.13/site-packages/conda/common/io.pyr5   DeltaSecondsFormatter.__init__0   s    S2    c                    > [        5       nU R                  n[        U R                  U5      U l        X#-
  Ul        UR                  S-  Ul        [        TU ]  U5      $ )Ni  )r!   r3   max
delta_secsrelativeCreatedrelative_created_secsr4   format)r6   recordnowr3   r7   s       r8   r@   DeltaSecondsFormatter.format4   sQ    fNN	T^^S1O'-'='='D$w~f%%r:   )r3   NN)	__name__
__module____qualname____firstlineno____doc__r5   r@   __static_attributes____classcell__r7   s   @r8   r.   r.   $   s    	3& &r:   r.   CONDA_TIMED_LOGGINGzm%(relative_created_secs) 7.2f %(delta_secs) 7.2f %(levelname)s %(name)s:%(funcName)s(%(lineno)d): %(message)sz<%(levelname)s %(name)s:%(funcName)s(%(lineno)d): %(message)sc                 8   ^ SR                  U4S jU 5       5      $ )N c              3   R   >#    U  H  nS ST-  -   S-   [        U5      -   v   M     g7f)
 z- N)str).0xindents     r8   	<genexpr>dashlist.<locals>.<genexpr>I   s(     I14#,&-A6s   $')r   )iterablerV   s    `r8   dashlistrZ   H   s    77IIIIr:   c                       \ rS rSrSrS rSrg)ContextDecoratorL   zqBase class for a context manager class (implementing __enter__() and __exit__()) that also
makes it a decorator.
c                 4   ^ ^ [        T5      UU 4S j5       nU$ )Nc                  N   > T   T" U 0 UD6sS S S 5        $ ! , (       d  f       g = fN )argskwdsfr6   s     r8   	decorated,ContextDecorator.__call__.<locals>.decoratedT   s    $'$' s   
$)r   )r6   rd   re   s   `` r8   __call__ContextDecorator.__call__S   s!    	q	( 
	( r:   ra   N)rE   rF   rG   rH   rI   rg   rJ   ra   r:   r8   r\   r\   L   s    r:   r\   c                        \ rS rSrS rS rSrg)SwallowBrokenPipe\   c                     g r`   ra   r6   s    r8   	__enter__SwallowBrokenPipe.__enter__`   s    r:   c                     U(       aE  [        U[        5      (       a/  [        USS 5      (       a  UR                  [        [
        4;   a  gg g g g )NerrnoT)
isinstanceEnvironmentErrorgetattrrq   r   r   r6   exc_typeexc_valexc_tbs       r8   __exit__SwallowBrokenPipe.__exit__c   sJ    7$455$//%!33 4 0 6 r:   ra   N)rE   rF   rG   rH   rn   ry   rJ   ra   r:   r8   rj   rj   \   s    r:   rj   c                        \ rS rSrSrSrSrSrg)CaptureTargetp   z{Constants used for contextmanager captured.

Used similarly like the constants PIPE, STDOUT for stdlib's subprocess.Popen.
ra   N)rE   rF   rG   rH   rI   STRINGSTDOUTrJ   ra   r:   r8   r|   r|   p   s    
 FFr:   r|   c              #     #    U c  0 n [        U 5      n0 nUR                  5        H>  u  pV[        R                  R	                  U[
        5      XE'   U[        R                  U'   M@      U(       a  U" 5         U(       a  U" S5        S v   UR                  5        H4  u  pVU[
        L a  [        R                  U	 M!  U[        R                  U'   M6     U(       a  U" 5         U(       a	  U" S5        g g ! UR                  5        H4  u  pVU[
        L a  [        R                  U	 M!  U[        R                  U'   M6     U(       a  U" 5         U(       a	  U" S5        f f = f7f)NTF)r(   itemsosenvirongetr*   )var_mapcallbackstack_callbacknew_var_map
saved_varsnamevalues          r8   env_varsr   z   s    $W-KJ"((*::>>$5
 

4 +"J4 %++-KD}JJt$#(

4 	 .
 J5!  &++-KD}JJt$#(

4 	 .
 J5! s    A%E(!C0 	A'E0A(EEc              #   b   #    X0n[        XBUS9 nUv   S S S 5        g ! , (       d  f       g = f7f)N)r   r   r   )r   r   r   r   dess         r8   env_varr      s)     	A	!~	F" 
G	F	Fs   /	/
,/c              #   Z   #    [        U S9 nUv   S S S 5        g ! , (       d  f       g = f7f)N)r   r   )r   r   s     r8   env_unmodifiedr      s     	8	$ 
%	$	$s   
+	+
(+c              #     #    S n " S S5      n[         R                  [         R                  pTU [        R                  :X  a7  [        5       nUR                  Ul        [        X&5      Ul        U[         l        OU nUb  U[         l        U[        R                  :X  a7  [        5       nUR                  Ul        [        X'5      Ul        U[         l        O2U[        R                  :X  a  U=[         l        nOUnUb  U[         l        U" 5       n[        R                  S5         Uv   U [        R                  :X  a  UR                  5       Ul        OXhl        U[        R                  :X  a  UR                  5       Ul        O"U[        R                  :X  a  SUl        OXxl        XEs[         l        [         l        [        R                  S5        g! U [        R                  :X  a  UR                  5       Ul        OXhl        U[        R                  :X  a  UR                  5       Ul        O"U[        R                  :X  a  SUl        OXxl        XEs[         l        [         l        [        R                  S5        f = f7f)a  Capture outputs of sys.stdout and sys.stderr.

If stdout is STRING, capture sys.stdout as a string,
if stdout is None, do not capture sys.stdout, leaving it untouched,
otherwise redirect sys.stdout to the file-like object given by stdout.

Behave correspondingly for stderr with the exception that if stderr is STDOUT,
redirect sys.stderr to stdout target and set stderr attribute of yielded object to None.

.. code-block:: pycon

   >>> from conda.common.io import captured
   >>> with captured() as c:
   ...     print("hello world!")
   ...
   >>> c.stdout
   'hello world!\n'

Args:
    stdout: capture target for sys.stdout, one of STRING, None, or file-like object
    stderr: capture target for sys.stderr, one of STRING, STDOUT, None, or file-like object

Yields:
    CapturedText: has attributes stdout, stderr which are either strings, None or the
        corresponding file-like function argument.
c                    [        U S5      (       a  SU R                  ;   a  [        nO"[        U [        5      (       a  [        nO[
        n[        X5      (       di  [        US5      (       a#  UR                  S5      nU R                  U5        g [        US5      (       a#  UR                  S5      nU R                  U5        g g U R                  U5        g )Nmodebdecodezutf-8encode)	hasattrr   bytesrr   r   rS   r   	old_writer   )r6   to_writewanteddecodedr   s        r8   write_wrappercaptured.<locals>.write_wrapper   s     4  SDII%5Fg&&FF(++x**"//'2w'8,,OOG,q! - NN8$r:   c                       \ rS rSrSrg)captured.<locals>.CapturedText   ra   NrE   rF   rG   rH   rJ   ra   r:   r8   CapturedTextr      s    r:   r   Nzovertaking stderr and stdoutzstderr and stdout yielding back)sysstdoutstderrr|   r   r   writer   r   r   logdebuggetvalue)	r   r   r   r   saved_stdoutsaved_stderroutfileerrfilecs	            r8   capturedr      s    :%(  "%SZZ,%%%*#MM7
 CJ%%%*#MM7
	=''	'&&
W CJAII,-5])))'')AHH])))'')AH}+++AHH!-
CJ		34 ])))'')AHH])))'')AH}+++AHH!-
CJ		34s    D!I<$G (B(I<B)I99I<c              #      #    [         R                  nU [         l         S v   U[         l        g ! U[         l        f = f7fr`   )r   argv)	args_list
saved_argss     r8   r   r     s+     JCH:s   ?/ ?<?z25.9z26.3zUse `logging._lock` instead.)addendumc               #      #    [         R                  " 5          S v   [         R                  " 5         g ! [         R                  " 5         f = f7fr`   )logging_acquireLock_releaseLockra   r:   r8   _logger_lockr     s3      s   A3 AA

Ac              #     #    [        U 5      nUR                  UR                  UR                  pCn[	        5       n[
        R                     UR                  U5        UR                  [        S-   5        Su  Ul        Ul        S S S 5         S v   [
        R                     UR                  U5        X#sUl        Ul        XAl        S S S 5        g ! , (       d  f       NR= f! , (       d  f       g = f! [
        R                     UR                  U5        X#sUl        Ul        XAl        S S S 5        f ! , (       d  f       f = f= f7f)Nr'   )TF)r   leveldisabled	propagater$   r   _lock
addHandlersetLevelr   removeHandler)logger_namelogr_lvl_dsbld_prpgtnull_handlers         r8   disable_loggerr     s     [!D::t}}dnn&D=L	%hl#(3%t~ 
$]]|,(,%DJ#N ] 
 ]W]]|,(,%DJ#N ]]sf   A	E9CEC2 E!&C!	E
CE!
C/+E2E&D2)	E2
E <EEc              #     #    [        U5      nUR                  UR                  UR                  UR                  4u  p4pV[        [        R                  5      nSUl        UR                  U 5        UR                  [        5        [        R                     UR                  U 5        / SSsUl        Ul        Ul        UR                  U5        UR                  U 5        S S S 5         S v   [        R                     X4UsUl        Ul        Ul        Xbl        S S S 5        g ! , (       d  f       NH= f! , (       d  f       g = f! [        R                     X4UsUl        Ul        Ul        Xbl        S S S 5        f ! , (       d  f       f = f= f7f)Nr   F)r   handlersr   r   r   r   r   r   r   r   setFormatter
_FORMATTERr   r   r   )r   r   r   _hndlrsr   r   r   handlers           r8   stderr_log_levelr   (  s    [!D

	%!G6 CJJ'GGLU$	e795%4t}dn e	 

$]]7>f4DM4:t}#N ] 
 ]W]]7>f4DM4:t}#N ]]sg   BFA
D!F(E ,F<D2	F!
D/+F2
E <FF
E90	F
9
FF

FFc                 0   [        U5      n[        S UR                  5       S5      n[        [        R
                  5      nSUl        UR                  U 5        UR                  U=(       d    [        5        U=(       d    S H  nUR                  U5        M     [        R                     U(       a  UR                  U5        UR                  U5        XR                  5       :  a  UR                  U 5        X%l        SSS5        g! , (       d  f       g= f)a/  Attach a new `stderr` handler to the given logger and configure both.

This function creates a new StreamHandler that writes to `stderr` and attaches it
to the logger given by `logger_name` (which maybe `None`, in which case the root
logger is used). If the logger already has a handler by the name of `stderr`, it is
removed first.

The given `level` is set **for the handler**, not for the logger; however, this
function also sets the level of the given logger to the minimum of its current
effective level and the new handler level, ensuring that the handler will receive the
required log records, while minimizing the number of unnecessary log events. It also
sets the loggers `propagate` property according to the `propagate` argument.
The `formatter` argument can be used to set the formatter of the handler.
c              3   H   #    U  H  oR                   S :X  d  M  Uv   M     g7f)r   N)r   )rT   r   s     r8   rW   (attach_stderr_handler.<locals>.<genexpr>Z  s     JW1Is   "	"Nr   ra   )r   nextr   r   r   r   r   r   r   r   	addFilterr   r   r   r   getEffectiveLevelr   )	r   r   r   	formatterfiltersr   old_stderr_handlernew_stderr_handlerfilter_s	            r8   attach_stderr_handlerr   B  s    , [!DJJD
 'szz2&&##I$;<=b=$$W- ! 
12*+))++MM% " 
s   *AD
D)default_returnc                Z  ^ [         (       a	   U" U0 UD6$  " S S[        5      mU4S jn[        R                  " [        R                  U5        [        R
                  " U 5         U" U0 UD6n[        R
                  " S5        U$ ! [         a    Us $ f = f! T[        4 a    Us $ f = f)zSEnforce a maximum time for a callable to complete.
Not yet implemented on Windows.
c                       \ rS rSrSrg)!timeout.<locals>.TimeoutExceptioni|  ra   Nr   ra   r:   r8   TimeoutExceptionr   |  s    r:   r   c                    > T" 5       er`   ra   )signumframer   s     r8   	interrupttimeout.<locals>.interrupt  s    "$$r:   r   )r)   KeyboardInterrupt	ExceptionsignalSIGALRMalarm)timeout_secsfuncr   rb   kwargsr   retr   s          @r8   timeoutr   o  s     v	"(((
	y 		% 	fnni0\"	"''CLLOJ! ! 	"!!	"" !"34 	"!!	"s#   B 'B BBB*)B*z25.3z*Use `conda.reporters.get_spinner` instead.c                   Z    \ rS rSrSr\" S5      rSS jrS rS r	S r
\S 5       rS	 rS
rg)Spinneri  z
Args:
    message (str):
        A message to prefix the spinner with. The string ': ' is automatically appended.
    enabled (bool):
        If False, usage is a no-op.
    json (bool):
       If True, will not output non-json to stdout.

z/-\|c                 <   Xl         X l        X0l        [        5       U l        [        U R                  S9U l        [        [        U R                  5      5      S-   U l        [        R                  U l        U=(       a    U(       + =(       a    [        U l        X@l        g )N)targetr'   )messageenabledjsonr   _stop_runningr   _start_spinning_spinner_threadlenr   spinner_cycle_indicator_lengthr   r   fhIS_INTERACTIVE	show_spinfail_message)r6   r   r   r   r  s        r8   r5   Spinner.__init__  so    	"W%T-A-AB!$T$*<*<%=!>!B** @X@.(r:   c                     U R                   (       a  U R                  R                  5         g U R                  (       d6  U R                  R                  S5        U R                  R                  5         g g )Nz...working... )r  r   startr   r  r   flushrm   s    r8   r	  Spinner.start  sE    >>  &&(GGMM*+GGMMO r:   c                     U R                   (       a<  U R                  R                  5         U R                  R	                  5         SU l         g g NF)r  r   setr   r   rm   s    r8   stopSpinner.stop  s9    >>""$  %%'"DN r:   c                     U R                   R                  5       (       d  U R                  R                  [	        U R
                  5      S-   5        U R                  R                  5         [        S5        U R                  R                  SU R                  -  5        U R                   R                  5       (       d  M  g g ! [         a5  nUR                  [        [        4;   a  U R                  5          S nAg e S nAff = f)NrR   g?)r   is_setr  r   r   r  r
  r    r  OSErrorrq   r   r   r  )r6   es     r8   r   Spinner._start_spinning  s    
	((//11d4#5#56<=ddT%;%;;<	 ((//11
  	ww5),,				s   B<C 
D*C<;C<<Dc                     U R                   (       dJ  [        R                  R                  U R                   S35        [        R                  R                  5         U R                  5         g )N: )r   r   r   r   r   r
  r	  rm   s    r8   rn   Spinner.__enter__  s?    yyJJ~R01JJ

r:   c                 r   U R                  5         U R                  (       d  [           U(       d  U(       a*  [        R                  R                  U R                  5        O[        R                  R                  S5        [        R                  R                  5         S S S 5        g g ! , (       d  f       g = f)Nzdone
)r  r   swallow_broken_piper   r   r   r  r
  ru   s       r8   ry   Spinner.__exit__  sh    		yy$wJJ$$T%6%67JJ$$X.

  " %$ $$s   A6B((
B6)	r  r   r   r   r  r  r   r   r  N)TFzfailed
)rE   rF   rG   rH   rI   r   r  r5   r	  r  r   r  rn   ry   rJ   ra   r:   r8   r   r     s?    	 'NM
)#  #r:   r   z/Use `conda.reporters.get_progress_bar` instead.c                   b    \ rS rSr\S 5       r SS jrS rS rS r	\
S 5       r\S	 5       rS
rg)ProgressBari  c                 Z    [        U S5      (       d  [        5       U l        U R                  $ )Nr   )r   r   r   )clss    r8   get_lockProgressBar.get_lock  s$     sG$$CIyyr:   Nc           
      z   Xl         X l        X0l        U(       a  gU(       aa  [        (       a,  Sn U R	                  UUSS[
        R                  UUS9U l        gSU l        [
        R                  R                  U S35        gg! [         a,  nUR                  [        [        4;   a  SU l         SnAge SnAff = f)a  
Args:
    description (str):
        The name of the progress bar, shown on left side of output.
    enabled (bool):
        If False, usage is a no-op.
    json (bool):
        If true, outputs json progress to stdout rather than a progress bar.
        Currently, the json format assumes this is only used for "fetch", which
        maintains backward compatibility with conda 4.3 and earlier behavior.
z!{desc}{bar} | {percentage:3.0f}% Tr'   )desc
bar_formatasciitotalfilepositionleaveFNz ...working...)descriptionr   r   r  _tqdmr   r   pbarr  rq   r   r   r   )r6   r+  r   r   r)  r*  r%  r  s           r8   r5   ProgressBar.__init__  s     '	~@
 $

(#-" ZZ!)# !+ !DI !	

  K=!?@)   ww5)"44',	s   (B 
B:!B54B55B:c                 <    U R                   (       a  U R                  (       aK  U R                  5          [        R                  R                  SU R                   SUS S35        S S S 5        g [        (       a2  U R                  R                  XR                  R                  -
  5        g US:X  a   [        R                  R                  S5        g g g ! , (       d  f       g = f! [         a,  nUR                  [        [        4;   a  SU l          S nAg e S nAff = f)N
{"fetch":"z)","finished":false,"maxval":1,"progress":rd   z}
 r'    done
F)r   r   r!  r   r   r   r+  r  r-  updatenr  rq   r   r   )r6   fractionr  s      r8   	update_toProgressBar.update_to  s    	||99

(()$*:*:);;demnodppvw ) $^II$$X		%;<]JJ$$Y/ # (  	ww5),,$		sF   2C% 2C&C% /<C% ,%C% 
C"C% "C% %
D/!DDDc                 &    U R                  S5        g )Nr'   )r5  rm   s    r8   finishProgressBar.finish"  s    qr:   c                     U R                   (       a9  U R                  (       d'  [        (       a  U R                  R	                  5         gggg)z-Force refresh i.e. once 100% has been reachedN)r   r   r  r-  refreshrm   s    r8   r;  ProgressBar.refresh%  s,    <<		nnII /=	<r:   c                    U R                   (       a  U R                  (       ae  U R                  5          [        R                  R                  SU R                   S35        [        R                  R                  5         S S S 5        g [        (       a  U R                  R                  5         g [        R                  R                  S5        g g ! , (       d  f       g = f)Nr0  z,","finished":true,"maxval":1,"progress":1}
 r1  )r   r   r!  r   r   r   r+  r
  r  r-  closerm   s    r8   r>  ProgressBar.close*  s    <<yy]]_JJ$$%d&6&6%77fg JJ$$&	 %_
  		!

  + $_s   AC
Cc                      SSK Jn  U" U 0 UD6$ )z=Deferred import so it doesn't hit the `conda activate` paths.r   )tqdm)	tqdm.autorA  )rb   r   rA  s      r8   r,  ProgressBar._tqdm8  s     	#T$V$$r:   )r+  r   r   r-  )TFNT)rE   rF   rG   rH   classmethodr!  r5   r5  r8  r;  r  r>  staticmethodr,  rJ   ra   r:   r8   r  r    s[       KO(AT$ 
 , , % %r:   r  c                   0    \ rS rSrS rS rS rSS jrSrg)	DummyExecutoriA  c                 0    SU l         [        5       U l        g r  )	_shutdownr   _shutdownLockrm   s    r8   r5   DummyExecutor.__init__B  s    !Vr:   c                 $   U R                      U R                  (       a  [        S5      e[        5       n U" U0 UD6nUR	                  U5        UsS S S 5        $ ! [
         a  nUR                  U5         S nAN+S nAff = f! , (       d  f       g = f)N*cannot schedule new futures after shutdown)rJ  rI  RuntimeErrorr   
set_resultBaseExceptionset_exception)r6   fnrb   r   rd   resultr  s          r8   submitDummyExecutor.submitF  s|    ~~"#OPPA%T,V, V$   ! #""#  s3   'BAB
A>#A94B9A>>B
Bc              '   D   #    U H  nU H  nU" U5      v   M     M     g 7fr`   ra   )r6   r   	iterablesrY   things        r8   mapDummyExecutor.mapU  s#     !H!5k! " "s    c                 ^    U R                      SU l        S S S 5        g ! , (       d  f       g = f)NT)rJ  rI  )r6   waits     r8   shutdownDummyExecutor.shutdownZ  s    !DN  s   
,)rI  rJ  N)T)	rE   rF   rG   rH   r5   rT  rY  r]  rJ   ra   r:   r8   rG  rG  A  s    $"
"r:   rG  c                   2   ^  \ rS rSrSU 4S jjrS rSrU =r$ )ThreadLimitedThreadPoolExecutori_  c                 $   > [         TU ]  U5        g r`   )r4   r5   )r6   max_workersr7   s     r8   r5   (ThreadLimitedThreadPoolExecutor.__init__`  s    %r:   c                 z   U R                      U R                  (       a  [        S5      e[        R                  " 5       n[        XAX#5      nU R                  R                  U5         U R                  5         UsSSS5        $ ! [         a    [        U R                  5      S:  a   N0e f = f! , (       d  f       g= f)a  
This is an exact reimplementation of the `submit()` method on the parent class, except
with an added `try/except` around `self._adjust_thread_count()`.  So long as there is at
least one living thread, this thread pool will not throw an exception if threads cannot
be expanded to `max_workers`.

In the implementation, we use "protected" attributes from concurrent.futures (`_base`
and `_WorkItem`). Consider vendoring the whole concurrent.futures library
as an alternative to these protected imports.

https://github.com/agronholm/pythonfutures/blob/3.2.0/concurrent/futures/thread.py#L121-L131  # NOQA
https://github.com/python/cpython/blob/v3.6.4/Lib/concurrent/futures/thread.py#L114-L124
rM  r   N)_shutdown_lockrI  rN  r   r   r	   _work_queueput_adjust_thread_countr   _threads)r6   rR  rb   r   rd   ws         r8   rT  &ThreadLimitedThreadPoolExecutor.submitc  s       ~~"#OPPA!.A  #
))+ ' !     t}}%)  ! s0   AB,'B7B,#B)%B,'B))B,,
B:ra   )
   )rE   rF   rG   rH   r5   rT  rJ   rK   rL   s   @r8   r`  r`  _  s    &! !r:   r`  c                  n    [        SSS5      n [        [        R                  R	                  SU 5      5      $ )N~z.condazinstrumentation-record.csv!CONDA_INSTRUMENTATION_RECORD_FILE)r   r+   r   r   r   )default_record_files    r8   get_instrumentation_record_filerq    s3    sH.JK


:<OP r:   c                      ^  \ rS rSr\" 5       rSr\" \5      r	\" \
5      rSS jrS rU 4S jrS rS r\S 5       r\S	 5       rS
rU =r$ )time_recorderi  Nc                     Xl         X l        g r`   )
entry_namemodule_name)r6   ru  rv  s      r8   r5   time_recorder.__init__  s    $&r:   c                     U R                   cb  [        US5      (       a  UR                  nOSUR                  -   nU R                  (       a  SR                  U R                  U45      nX l         g g )NrG   :.)ru  r   rG   rE   rv  r   )r6   rd   ru  s      r8   _set_entry_nametime_recorder._set_entry_name  s\    ??"q.))^^
 1::-
 XXt'7'7&DE
(O #r:   c                 D   > U R                  U5        [        TU ]	  U5      $ r`   )r{  r4   rg   )r6   rd   r7   s     r8   rg   time_recorder.__call__  s!    Qw""r:   c                     [         R                  R                  S5      nU(       a  [        U5      (       a  [	        5       U l        U $ )NCONDA_INSTRUMENTATION_ENABLED)r   r   r   r%   r!   
start_time)r6   r   s     r8   rn   time_recorder.__enter__  s0    **..!@Aww''"fDOr:   c                 |   U R                   (       a  U R                  n[        5       nXPR                   -
  nU R                  U==   S-  ss'   U R                  U==   U-  ss'   U R                  5         [        U R                  S5       nUR                  U SUS S35        S S S 5        g g ! , (       d  f       g = f)Nr'   a,rd   rQ   )	r  ru  r!   total_call_numtotal_run_time_ensure_diropenrecord_filer   )r6   rv   rw   rx   ru  end_timerun_timer  s           r8   ry   time_recorder.__exit__  s    ??JvH//1H
+q0+
+x7+d&&,J<q!B78 -,  -,s   
B--
B;c                 T   [         R                  R                  S5      nU(       a  [        U5      (       d  g [        R                  S5        [        U R                  R                  5       5       H5  n[        R                  SU R                  U   U R                  U   U5        M7     g )Nr  z*=== time_recorder total time and calls ===zTOTAL %9.3f % 9d %s)
r   r   r   r%   r   infosortedr  keysr  )r   r   ru  s      r8   
log_totalstime_recorder.log_totals  s~    **..!@AGG,,=> !3!3!8!8!:;JHH%"":."":.	 <r:   c                     [        [        U R                  5      5      (       d*  [        R                  " [        U R                  5      5        g g r`   )r   r   r  r   makedirsrm   s    r8   r  time_recorder._ensure_dir  s4    WT--.//KK 0 012 0r:   )ru  rv  r  rD   )rE   rF   rG   rH   rq  r  r  r   intr  floatr  r5   r{  rg   rn   ry   rD  r  r#   r  rJ   rK   rL   s   @r8   rs  rs    se    13KJ %N 'N')#	9   3 3r:   rs  c            	         [        5       n [        [        5      n0 n[        U 5      (       d  g [	        U 5       nU H@  nUR                  5       R                  S5      u  pVX   R                  [        U5      5        MB     S S S 5        [        U5       H)  nX   n[        U5      n[        U5      nXh-  n	UUU	S.X%'   M+     [        [        R                  " USSSS95        g ! , (       d  f       Ng= f)Nr  )counts
total_timeaverage_timeTr"   )r  r  )	sort_keysrV   
separators)rq  r   listr   r  stripsplitappendr  r  r   sumprintr   dumps)
r  grouped_data
final_datar  lineru  r  	all_timesr  r  s
             r8   print_instrumentation_datar    s    13Kt$LJ+	k	bD%)ZZ\%7%7%<"J$++E*,=>  

 \*
 ,	Y^
!*$("

 + 
$**Z4k
RS! 
	s   AC  
C.__main__)r"   )NNNrD   r`   )`rI   r   r   r   r   r   collectionsr   concurrent.futuresr   r   r   r   r   concurrent.futures.threadr	   
contextlibr
   enumr   rq   r   r   	functoolsr   r   ior   r   	itertoolsr   r   r   r   r   r   os.pathr   r   r   r   	threadingr   r   r   r   r!   r    auxlib.decoratorsr#   auxlib.logzr$   auxlib.type_coercionr%   deprecationsr&   compatr(   r)   	constantsr*   pathr+   rE   r   r   r   r,   r  r.   r   r   r   rZ   r\   rj   r  r|   r   r   r   r   r   r   r   r   r   r   r   r   r  rG  r`  rq  rs  r  ra   r:   r8   <module>r     s      	  
 # X X / %  " $    G G 0 0 0 0  - % * % .  X.F3::3D3D3F&I &2 2::>>/011&	GJ
 FJ
J  ( " () D  " "6    
 !((1E1E [5 [5|   FF%CD  E $ $" $ $4 *#Z 7; "< 

9
D# D#
D#N 

>
_% _%
_%F"H "<%&8 %P =3$ =3@T8 z  r:   