
    mi                         d dl mZmZ d dlZd dlZd dlZd dlZd dlm	Z	  G d d      Z
dedefdZdedefd	Zdd
defdZdej                  fdZdaddZd Zy)    )IterableSizedNcolorizec                       e Zd ZdZddddd ej
                  fdej                  deded	ed
e	de
j                  e   dedefdZde	fdZd Zd Zd Zy)LogProgressa>  
    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	                     || _         |t        |t              sJ t        |      }|| _        || _        || _        || _        || _        || _	        || _
        y )N)r   
isinstancer   lenr   r   r   r   r   r   r   )	selfr   r   r   r   r   r   r   r   s	            B/var/www/stems/demucs_env/lib/python3.12/site-packages/dora/log.py__init__zLogProgress.__init__   s\     !=h...ME
(&	
    returnc                 (    || _         | j                  S )zqUpdate the metrics to show when logging. Return True if logging will
        happen at the end of this iteration.)_infos	_will_log)r   infoss     r   updatezLogProgress.update3   s     ~~r   c                     t        | j                        | _        d| _        d| _        i | _        t        j                         | _        | S )NF)iterr   	_iteratorr   _indexr   time_begin)r   s    r   __iter__zLogProgress.__iter__9   s9    dmm,iikr   c                    | j                   r| j                          d| _         	 t        | j                        }| xj                  dz  c_        | j
                  dkD  rUt        | j                  | j                  | j
                  z        }| j                  dk\  r| j                  |z  dk(  rd| _         |S # t        $ r  w xY w)NFr
   r   T)
r   _lognextr#   r$   r   maxr   r   StopIteration)r   value	log_everys      r   __next__zLogProgress.__next__A   s    >>IIK"DN	(E KK1K||a 1 14::3MN	;;!#i(?1(D%)DNL  		s   B5 5C c                    d| j                   z   t        j                         | j                  z
  z  | _        dj	                  d | j
                  j                         D              }| j                  dk  rd}n| j                  r#| j                  dk  rd| j                  z  dd}nS| j                  rd| j                  z  d	d
}n3| j                  dk  rd| j                  z  d	d}n| j                  dd}| j                   d| j                    d| j                   d| }|r|d|z   z  }| j                  j                  | j                  |       y )Nr
   z | c              3   L   K   | ]  \  }}|j                          d |   yw) N)
capitalize).0kvs      r   	<genexpr>z#LogProgress._log.<locals>.<genexpr>T   s&     Stq!alln-Qqc2Ss   "$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)   z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   )__name__
__module____qualname____doc__loggingINFOLoggerr   intbooltpOptionalstrr   r   r'   r/   r)    r   r   r   r      s      !"%&%*+/*%ll #   #	
 # C(  * ")r   r   textr   c                     t        | d      S )z/
    Display text in bold in the terminal.
    1r   rL   s    r   boldrP   e   s     D#r   c                     t        | d      S )zDisplay text in red.
    31r   rO   s    r   redrS   l   s     D$r   )colorfirstc                P    t        t        |       g|dt        j                  i y )Nfile)printrP   sysstderr)rU   rT   argss      r   
simple_logr\   s   s    	$u+..3::.r   c                  F    t        dg|   t        j                  d       y )NzFATAL:r
   )r\   rY   exit)r[   s    r   fatalr_   w   s    x$HHQKr   c                 ~   | rt         j                  nt         j                  }t        j                  d      }|j	                  |       t        j
                  t        j                        at        j                  t        j                  d             t        j	                  |       |j                  t               y )Ndoraz"%(levelname)s:%(name)s:%(message)s)rC   DEBUGrD   	getLoggersetLevelStreamHandlerrY   rZ   _dora_handlersetFormatter	Formatter
addHandler)verbose	log_levelr   s      r   setup_loggingrl      sy    !(gllIv&F
OOI))#**5Mw001UVW9%
m$r   c                  h    t         J t        j                  d      } | j                  t                y )Nra   )rf   rC   rc   removeHandler)r   s    r   disable_loggingro      s,    $$$v&F
'r   )F)collections.abcr   r   rC   rY   r%   typingrH   treetable.textr   r   rJ   rP   rS   r\   NoReturnr_   rf   rl   ro   rK   r   r   <module>rt      s~    ,  
   #R) R)js s  c  c   )- /c /BKK 
 %(r   