
    miT                     x    d dl Z d dlZd dlmZ d dlZd dlmZ ddlm	Z	  ej                  e      Z G d d      Zy)    N)Path)retry   )utilsc                       e Zd ZdZddej
                  e   fdZ ed      d        Z	d Z
d	ej                  e   fd
ZdefdZy)Linkz
    Connection with Dora for your trainer.
    This is minimalistic and won't do much.

    This can also be used to simulate a fake link by passing `None`
    as the history file.
    Nhistory_filec                      g | _         || _        y)z0
        Initialize the Link with Dora.
        N)historyr	   )selfr	   s     C/var/www/stems/demucs_env/lib/python3.12/site-packages/dora/link.py__init__zLink.__init__   s     ')(    
   )stop_max_attempt_numberc                     | j                   y | j                   j                         r;t        j                  | j                   t        j
                  d      }||| _        y y y )Nr)loadmode)r	   existsr   try_loadjsonr   r   r   r   s     r   r   z	Link.load"   sV    $##%nnT%6%6TYYSQG"& # &r   c                     | j                   y ddlm} |j                         sy t	        j
                  | j                   d      5 }t        j                  | j                  |d       d d d        y # 1 sw Y   y xY w)Nr   )distribw   )indent)	r	    r   	is_masterr   write_and_renamer   dumpr   )r   r   tmps      r   _commitzLink._commit+   sd    $  "##D$5$5s; 	3sIIdllC2	3 	3 	3s   #A11A:r   c                     t        j                  |      }t        |t              st	        dt        |             || j                  d d  | j                          y )Nz history must be a list, but got )r   jsonable
isinstancelist
ValueErrortyper   r$   r   s     r   update_historyzLink.update_history5   sG    ..)'4(?WOPP!Qr   metricsc                     t        j                  |      }| j                  j                  |       | j	                          y N)r   r&   r   appendr$   )r   r,   s     r   push_metricszLink.push_metrics<   s+    ..)G$r   r.   )__name__
__module____qualname____doc__tpOptionalr   r   r   r   r$   Listdictr+   r0    r   r   r   r      sZ    )R[[%6 ) 2&' ''3bggdm D r   r   )r   loggingpathlibr   typingr5   retryingr   r   r   	getLoggerr1   loggerr   r9   r   r   <module>r@      s5         			8	$- -r   