
    W|hf6                         S r SSKJrJr  SSKJr  SSKrSS0rSS jrSS jr " S	 S
5      r	 " S S\	5      r
 " S S\
5      r " S S5      r " S S\\
5      r " S S\
5      r     SS jrg)zHImplements the generic progress logger class, and the ProgressBar class.    )tqdmtqdm_notebook)OrderedDictNnotebookFc                 &    U S:X  a  SOS[         S'   g )NonTFr   )SETTINGS)turns    I/home/james-whalen/.local/lib/python3.13/site-packages/proglog/proglog.pyr   r   
   s    $(DL4uHZ    c                 4    [        U 5      U:  a  U $ U S U S-   $ )Nz...)len)s
max_lengths     r   troncate_stringr      s#    Q*$1CAkzNU,BCr   c                   P    \ rS rSrSrSS jrS rSS jrS rS r	S	 r
S
 rS rSrg)ProgressLogger   zGeneric class for progress loggers.

A progress logger contains a "state" dictionary.

Parameters
----------
init_state : dict
    Dictionary representing the initial state.
Nc                 z    0 U l         0 U l        / U l        SU l        Ub  U R                   R	                  U5        g g )Nr   )statestoredlogs
log_indentupdate)self
init_states     r   __init__ProgressLogger.__init__   s;    
	!JJj) "r   c                 Z    U R                   R                  SU R                  -  U-   5        g )N )r   appendr   )r   messages     r   logProgressLogger.log&   s"    		#/7:;r   c                     Ub@  [        US5       nUR                  SR                  U R                  5      5        S S S 5        g SR                  U R                  5      $ ! , (       d  f       g = f)Na
)openwritejoinr   )r   filepathfs      r   	dump_logsProgressLogger.dump_logs)   sS    h$		$)),- %$ 99TYY'' %$s   +A
A-c                     g)zExecute something after the state has been updated by the given
state elements.

This default callback does nothing, overwrite it by subclassing.
N r   kws     r   callbackProgressLogger.callback0        	r   c                 ^    U R                   R                  U5        U R                  " S0 UD6  g)ah  Store objects in the logger and trigger ``self.store_callback``.

This works exactly like ``logger()``, but the later is meant for simple
data objects (text, numbers) that will be sent over the network or
written to a file. The ``store`` method expects rather large objects
which are not necessarily serializable, and will be used eg to draw
plots on the fly.
Nr0   )r   r   store_callbackr1   s     r   storeProgressLogger.store8   s'     	2!b!r   c                     g)zExecute something after the store has been updated by the given
state elements.

This default callback does nothing, overwrite it by subclassing
Nr0   r1   s     r   r7   ProgressLogger.store_callbackD   r5   r   c              +   j   #    UR                  5        H  u  p#U H  nU " S0 X$0D6  Uv   M     M     g7f)zIterate through a list while updating the state.

Examples
--------
>>> for username in logger.iter(user=['tom', 'tim', 'lea']):
>>>     # At every loop, logger.state['user'] is updated
>>>     print(username)
Nr0   )items)r   r2   fielditerableits        r   iterProgressLogger.iterL   s5       "xxzOE#{#   *s   13c                 ^    U R                   R                  U5        U R                  " S0 UD6  g )Nr0   )r   r   r3   r1   s     r   __call__ProgressLogger.__call__Z   s#    

"r   )r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r#   r-   r3   r8   r7   rA   rD   __static_attributes__r0   r   r   r   r      s/    *<(
"r   r   c                   n    \ rS rSrSrSr      SS jr\S 5       rS r	S r
S	 rSS
 jrSS jrS rSrg)ProgressBarLogger_   aT  Generic class for progress loggers.

A progress logger contains a "state" dictionary.

Parameters
----------
init_state : dict
    Initial state of the logger.
bars : None, list, tuple, or dict, optional
    Either None (will be initialized with no bar) or a list/tuple of bar
    names (e.g., ['main', 'sub']) which will be initialized with index -1 and
    no total, or a dictionary (possibly ordered) of bars, of the form
    `{bar_1: {title: 'bar1', index: 2, total: 23}, bar_2: {...}}`.
ignored_bars : None, list of str, or 'all_others', optional
    Either None (newly met bars will be added) or a list of blacklisted bar
    names, or 'all_others' to signify that all bar names not already in
    `self.bars` will be ignored.
logged_bars
min_time_interval : int or float
    Time in seconds between progress bar updates.
ignore_bars_under : int
   Nc                 t   [         R                  X5        Uc  [        5       nOD[        U[        [
        45      (       a)  [        U Vs/ s H  nU[        USS S SS94PM     sn5      n[        U[        [
        45      (       a  [        U5      nX0l        X@l	        X R                  S'   XPl        X`l        g s  snf )Nr   )titleindextotalr"   indentbars)r   r   r   
isinstancelisttupledictsetignored_barslogged_barsr   min_time_intervalignore_bars_under)r   r   rW   r]   r^   r_   r`   bs           r   r   ProgressBarLogger.__init__y   s     	1<=DtUm,, "! 1BdDQRST!D lT5M22|,L(&!

6!2!2s   B5c                      U R                   S   $ )zReturn ``self.state['bars'].``rW   )r   )r   s    r   rW   ProgressBarLogger.bars   s     zz&!!r   c                 v    U R                   c  gU R                   S:X  a  XR                  ;  $ XR                   ;   $ )NF
all_others)r]   rW   r   bars     r   bar_is_ignored ProgressBarLogger.bar_is_ignored   s;    $,.ii''++++r   c                 d    U R                   (       d  gU R                   S:X  a  gXR                   ;   $ )NFallT)r^   rg   s     r   bar_is_loggedProgressBarLogger.bar_is_logged   s.    &****r   c                 p    [        US5      (       a  [        U5      OS nUS L=(       a    X R                  :  $ )N__len__)hasattrr   r`   )r   r?   lengths      r   iterable_is_too_short'ProgressBarLogger.iterable_is_too_short   s2    ")(I">">XDd"I2H2H)HIr   c                 8  ^ ^^^ SU;   a  UR                  S5      mOSmUR                  5       u  mmT R                  T5      (       d  T R                  T5      (       a  T$ UT-   m[	        TS5      (       a  T " S0 TS-   [        T5      0D6  UUUU 4S jnU" 5       $ )aJ  Iterate through a list while updating a state bar.

Parameters
----------
bar_prefix : str
    Bar prefix.

Examples
--------
>>> for username in logger.iter_bar(user=['tom', 'tim', 'lea']):
>>>     # At every loop, logger.state['bars']['user'] is updated
>>>     # to {index: i, total: 3, title:'user'}
>>>     print (username)

bar_messageNrp   __totalc            	   3   v  >#    [         R                   " 5       n Sn[        T5       H[  u  p[         R                   " 5       nUS:X  d  X0-
  TR                  :  a%  Tb  T" S0 TS-   T" U5      0D6  T" S0 TS-   U0D6  Un Uv   M]     TR                  T   S   U:w  a  T" S0 TS-   U0D6  T" S0 TS-   US-   0D6  g 7f)Nr   	__message__indexrT      r0   )time	enumerater_   rW   )	last_timeir@   now_timerh   rv   r?   r   s       r   new_iterable0ProgressBarLogger.iter_bar.<locals>.new_iterable   s     		IA"8,99;F 4t7M7M M".Dk 1;r?CD0C)OQ/0 (I - yy~g&!+,i+,,C)OQU+,s   B6B9r0   )poppopitemri   rs   rq   r   )r   
bar_prefixr2   r   rh   rv   r?   s   `   @@@r   iter_barProgressBarLogger.iter_bar   s      B&&/KK

Xs##t'A'A('K'KO38Y''4C)OS]34	- 	-  ~r   c                     g)aN  Execute a custom action after the progress bars are updated.

Parameters
----------
bar
  Name/ID of the bar to be modified.

attr
  Attribute of the bar attribute to be modified

value
  New value of the attribute

old_value
  Previous value of this bar's attribute.

This default callback does nothing, overwrite it by subclassing.
Nr0   )r   rh   attrvalue	old_values        r   bars_callbackProgressBarLogger.bars_callback   s    & 	r   c           	      2   [        UR                  5       S S9nU GHJ  u  p4SU;   d  M  UR                  S5      u  pVU R                  U5      (       a  M9  UR	                  U5        XPR
                  ;  a  [        USS S S9U R
                  U'   U R
                  U   U   nU R                  U5      (       a  US:H  =(       a    XG:  nUS:X  d  U(       a  U R                  U R
                  U   S'   OU R
                  U   S   U l        U R                  S	U< S
U< SU< 35        U =R                  U R                  -  sl        X@R
                  U   U'   U R                  XVXG5        GMM     U R                  R                  U5        U R                  " S0 UD6  g )Nc                 4    U S   R                  S5      (       + $ )Nr   rU   )endswith)kvs    r   <lambda>,ProgressBarLogger.__call__.<locals>.<lambda>   s    bennW6M2Mr   )key__rR   )rS   rT   rU   r"   rT   rU   rV   [z] z: r0   )sortedr=   splitri   r   rW   r[   rm   r   r#   
bar_indentr   r   r   r3   )	r   r2   r=   r   r   rh   r   r   new_bars	            r   rD   ProgressBarLogger.__call__   sH   rxxz'MNJCs{IIdO	&&s++sii'%)2TSW%XDIIcN IIcN40	%%c**#wGU5FGW37??		#x0*.))C.*BHHc4?@OOt6O',		#t$""3e?'  ( 	

"r   )r`   r]   r   r^   r_   )NNNrl   r   r   ) rF   )rG   rH   rI   rJ   rK   r   r   propertyrW   ri   rm   rs   r   r   rD   rL   r0   r   r   rN   rN   _   s[    . J 36 " ",+J,\*r   rN   c                   L    \ rS rSrSr         S
S jrS rS rS rS r	S	r
g)TqdmProgressBarLoggeri  a  Tqdm-powered progress bar for console or Notebooks.

Parameters
----------
init_state : dict
    Initial state of the logger.
bars : None, list, tuple, or dict, optional
    Either None (will be initialized with no bar) or a list/tuple of bar
    names (e.g., ['main', 'sub']) which will be initialized with index -1 and
    no total, or a dictionary (possibly ordered) of bars, of the form
    `{bar_1: {title: 'bar1', index: 2, total: 23}, bar_2: {...}}`.
leave_bars : bool, optional
    Whether to leave the progress bars displayed upon completion.
ignored_bars : None, list of str, or 'all_others', optional
    Either None (newly met bars will be added) or a list of blacklisted bar
    names, or 'all_others' to signify that all bar names not already in
    `self.bars` will be ignored.
notebook : bool, optional
    True will make the bars look nice (HTML) in the Jupyter notebook. It is
    advised to leave to 'default' as the default can be globally set from
    inside a notebook with `import proglog; proglog.notebook_mode()`.
print_messages : bool
    If True, every `logger(message='something')` will print a message in
    the console or notebook.
min_time_interval : int or float
    Time in seconds between progress bar updates.
ignore_bars_under : int
Nc
           
      *   [         R                  U UUUUU	US9  X0l        [        U R                   V
s/ s H  oS 4PM     sn
5      U l        US:X  a	  [        S   nX`l        Xpl        U R                  (       a  [        U l
        g [        U l
        g s  sn
f )N)r   rW   r]   r^   r`   r_   defaultr   )rN   r   
leave_barsr   rW   	tqdm_barsr	   r   print_messagesr   r   )r   r   rW   r   r]   r^   r   r   r_   r`   rh   s              r   r   TqdmProgressBarLogger.__init__*  s     	""!%#// 	# 	
 %$TYY%GYcDkY%GHy 
+H ,%)]]M		 &Hs   Bc                    XR                   ;   a!  U R                   U   b  U R                  U5        U R                  U   nU R                  US   US   [	        [        [        US   5      5      S9U R                  S9U R                   U'   g)z:Create a new tqdm bar, possibly replacing an existing one.NrU   rS   r"   now)rU   descpostfixleave)r   close_tqdm_barrW   r   r[   r   strr   )r   rh   infoss      r   new_tqdm_bar"TqdmProgressBarLogger.new_tqdm_barG  s}    >>!s(;(G$		#"ii.w_Sy1A-BCD//	 ( 
sr   c                     U R                   U   R                  5         U R                  (       d  SU R                   U'   gg)zClose and erase the tqdm bar.N)r   closer   rg   s     r   r   $TqdmProgressBarLogger.close_tqdm_barS  s1    s!!#}}"&DNN3 r   c                 (   XR                   ;  d  U R                   U   c  U R                  U5        US:X  a  X4:  aQ  U R                  U   S   nU(       a  X5:  a  U R                  U5        g U R                   U   R	                  X4-
  5        g U R                  U5        U R                   U   R	                  US-   5        g US:X  aM  U R                   U   R                  [        [        U5      5      S9  U R                   U   R	                  S5        g g )NrT   rU   r{   r"   r   r   )r   r   rW   r   r   set_postfixr   r   )r   rh   r   r   r   rU   s         r   r   #TqdmProgressBarLogger.bars_callbackY  s    ~~%4>>#+>+Fc"7?!		#w/en'',NN3'..u/@A!!#&s#**5195YNN3++E
0K+LNN3&&q) r   c                     U R                   (       aQ  SU;   aJ  US   (       a?  U R                  (       a  [        US   5        g U R                  R	                  US   5        g g g g )Nr"   )r   r   printr   r)   r1   s     r   r3   TqdmProgressBarLogger.callbackj  sI    IOI}}bm$		9.	 :GOr   )r   r   r   r   r   )	NNFNrl   r   Tr   r   )rG   rH   rI   rJ   rK   r   r   r   r   r3   rL   r0   r   r   r   r     s=    > =:

'*"/r   r   c                        \ rS rSrS rS rSrg)RqWorkerProgressLoggerir  c                     Xl         SU R                   R                  ;  a4  0 U R                   R                  S'   U R                   R                  5         g g Nprogress_data)jobmetasave)r   r   s     r   r   RqWorkerProgressLogger.__init__s  s;    $((--/-/DHHMM/*HHMMO 0r   c                 ~    U R                   U R                  R                  S'   U R                  R                  5         g r   )r   r   r   r   r1   s     r   r3   RqWorkerProgressLogger.callbacky  s%    )-o&r   )r   N)rG   rH   rI   rJ   r   r3   rL   r0   r   r   r   r   r  s    r   r   c                   (    \ rS rSr     SS jrSrg)RqWorkerBarLoggeri~  Nr0   c           	      ^    [         R                  X5        [        R                  U UUUUUS9  g )N)r   rW   r]   r^   r_   )r   r   rN   )r   r   r   rW   r]   r^   r_   s          r   r   RqWorkerBarLogger.__init__  s7     	''2""!%#/ 	# 	
r   )NNr0   rl   r   )rG   rH   rI   rJ   r   rL   r0   r   r   r   r   ~  s    
 
r   r   c                       \ rS rSrS rSrg)MuteProgressBarLoggeri  c                     g)NTr0   rg   s     r   ri   $MuteProgressBarLogger.bar_is_ignored  s    r   r0   N)rG   rH   rI   rJ   ri   rL   r0   r   r   r   r     s    r   r   c                 F    U S:X  a  [        UUUUUS9$ U c
  [        5       $ U $ )Nrh   )rW   r]   r^   r_   r`   )r   r   )loggerrW   r]   r^   r_   r`   s         r   default_bar_loggerr     s<     $%#//
 	
 
$&&r   )r   )   )NNrl   r   r   )rK   r   r   collectionsr   r|   r	   r   r   r   rN   r   r   r   r   r   r0   r   r   <module>r      s    N $ # =DJ JZj jZc/- c/L	 	
.0A 
,-  
r   