
    VhT                     |    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dS )    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dS )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 | _         || _        dS )z0
        Initialize the Link with Dora.
        N)historyr	   )selfr	   s     O/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/dora/link.py__init__zLink.__init__   s     ')(    
   )stop_max_attempt_numberc                     | j         d S | j                                         r1t          j        | j         t          j        d          }||| _        d S d S d S )Nr)loadmode)r	   existsr   try_loadjsonr   r   r   r   s     r   r   z	Link.load"   sc    $F##%% 	'nT%6TYSQQQG"&	' 	'""r   c                     | j         d S ddlm} |                                sd S t	          j        | j         d          5 }t          j        | j        |d           d d d            d S # 1 swxY w Y   d S )Nr   )distribw   )indent)	r	    r   	is_masterr   write_and_renamer   dumpr   )r   r   tmps      r   _commitzLink._commit+   s    $F  "" 	F#D$5s;; 	3sIdlC2222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s    A**A.1A.r   c                     t          j        |          }t          |t                    st	          dt          |                     || j        d d <   |                                  d S )Nz history must be a list, but got )r   jsonable
isinstancelist
ValueErrortyper   r$   r   s     r   update_historyzLink.update_history5   sa    .))'4(( 	QOWOOPPP!QQQr   metricsc                     t          j        |          }| j                            |           |                                  d S N)r   r&   r   appendr$   )r   r,   s     r   push_metricszLink.push_metrics<   s8    .))G$$$r   r.   )__name__
__module____qualname____doc__tpOptionalr   r   r   r   r$   Listdictr+   r0    r   r   r   r      s         ) )R[%6 ) ) ) ) U2&&&' ' '&'3 3 3bgdm    D      r   r   )r   loggingpathlibr   typingr5   retryingr   r   r   	getLoggerr1   loggerr   r9   r   r   <module>r@      s                           		8	$	$- - - - - - - - - -r   