
    ]i                         S SK JrJr  S SKrS SKrS SKrS SKrS SKJ	r	   " S S5      r
S\S\4S jrS\S\4S	 jrSS
.S\4S jjrS\R                  4S jrSqSS jrS rg)    )IterableSizedNcolorizec                       \ rS rSrSrSSSSS \R                  4S\R                  S\S	\	S
\	S\
S\R                  \	   S\S\	4S jjrS\
4S jrS rS rS rSrg)LogProgress   a  
Sort of like tqdm but using log lines and not as real time.
Args:
    - logger: logger obtained from `logging.getLogger`,
    - iterable: iterable object to wrap
    - updates (int): number of lines that will be printed, e.g.
        if `updates=5`, log every 1/5th of the total length.
    - time_per_it (bool): force speed to display as ms/it
    - total (int): length of the iterable, in case it does not support
        `len`.
    - name (str): prefix to use in the log.
    - level: logging level (like `logging.INFO`).
      FNloggeriterableupdatesmin_intervaltime_per_ittotalnamelevelc	                     X l         Uc"  [        U[        5      (       d   e[        U5      nX`l        X0l        X@l        XPl        Xpl        Xl	        Xl
        g )N)r   
isinstancer   lenr   r   r   r   r   r   r   )	selfr   r   r   r   r   r   r   r   s	            E/mnt/rpi/tmp/demucs-venv-sys/lib/python3.13/site-packages/dora/log.py__init__LogProgress.__init__   sO     !=h....ME
(&	
    returnc                 &    Xl         U R                  $ )ziUpdate the metrics to show when logging. Return True if logging will
happen at the end of this iteration.)_infos	_will_log)r   infoss     r   updateLogProgress.update3   s     ~~r   c                     [        U R                  5      U l        SU l        SU l        0 U l        [        R                  " 5       U l        U $ )NF)iterr   	_iteratorr   _indexr   time_begin)r   s    r   __iter__LogProgress.__iter__9   s9    dmm,iikr   c                    U R                   (       a  U R                  5         SU l          [        U R                  5      nU =R                  S-  sl        U R
                  S:  aW  [        U R                  U R                  U R
                  -  5      nU R                  S:  a  U R                  U-  S:X  a  SU l         U$ ! [         a    e f = f)NFr   r   T)
r   _lognextr&   r'   r   maxr   r   StopIteration)r   value	log_everys      r   __next__LogProgress.__next__A   s    >>IIK"DN	(E KK1K||a 1 14::3MN	;;!#i(?1(D%)DNL  		s   B= =C	c                    SU R                   -   [        R                  " 5       U R                  -
  -  U l        SR	                  S U R
                  R                  5        5       5      nU R                  S:  a  SnOU R                  (       a$  U R                  S:  a  SU R                  -  S S3nOYU R                  (       a  SU R                  -  S	 S
3nO4U R                  S:  a  SU R                  -  S	 S3nOU R                  S S3nU R                   SU R                    SU R                   SU 3nU(       a  USU-   -  nU R                  R                  U R                  U5        g )Nr   z | c              3   P   #    U  H  u  pUR                  5        S U 3v   M     g7f) N)
capitalize).0kvs      r   	<genexpr>#LogProgress._log.<locals>.<genexpr>T   s&     S?Rtqalln-Qqc2?Rs   $&g-C6?z	oo sec/itz.2fz sec/iti  z.1fz ms/itg?z it/sec/)r'   r(   r)   _speedjoinr   itemsr   r   r   r   logr   )r   r    speedouts       r   r-   LogProgress._logR   s'   4;;499;+DE

St{{?P?P?RSS;;E$++/4;;s+73Edkk)#.f5E[[3}S)1E{{3'w/E3t{{m1TZZLE7C55= C

C(r   )r)   r'   r   r&   r?   r   r   r   r   r   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__loggingINFOLoggerr   intbooltpOptionalstrr   r!   r*   r3   r-   __static_attributes__ r   r   r   r      s      !"%&%*+/*%ll #   #	
 # C(  * ")r   r   textr   c                     [        U S5      $ )z'
Display text in bold in the terminal.
1r   rU   s    r   boldrY   e   s     D#r   c                     [        U S5      $ )zDisplay text in red.
    31r   rX   s    r   redr\   l   s     D$r   )colorfirstc                P    [        [        U 5      /UQ7S[        R                  06  g )Nfile)printrY   sysstderr)r^   r]   argss      r   
simple_logre   s   s    	$u+..3::.r   c                  H    [        S/U Q76   [        R                  " S5        g )NzFATAL:r   )re   rb   exit)rd   s    r   fatalrh   w   s    x$HHQKr   c                    U (       a  [         R                  O[         R                  n[         R                  " S5      nUR	                  U5        [         R
                  " [        R                  5      q[        R                  [         R                  " S5      5        [        R	                  U5        UR                  [        5        g )Ndoraz"%(levelname)s:%(name)s:%(message)s)rK   DEBUGrL   	getLoggersetLevelStreamHandlerrb   rc   _dora_handlersetFormatter	Formatter
addHandler)verbose	log_levelr   s      r   setup_loggingru      sy    !(gllIv&F
OOI))#**5Mw001UVW9%
m$r   c                  l    [         c   e[        R                  " S5      n U R                  [         5        g )Nrj   )ro   rK   rl   removeHandler)r   s    r   disable_loggingrx      s,    $$$v&F
'r   )F)collections.abcr   r   rK   rb   r(   typingrP   treetable.textr   r   rR   rY   r\   re   NoReturnrh   ro   ru   rx   rT   r   r   <module>r}      s~    ,  
   #R) R)js s  c  c   )- /c /BKK 
 %(r   