o
    -wiu                     @   sx   d dl Z d dlZd dlmZmZ d dlZd dlmZ er.d dlm	Z	m
Z
mZ d dlmZmZ e eZG dd dZdS )    N)TYPE_CHECKINGOptional)LogicalPath)dir_watcherstatsstep_upload)file_streaminternal_apic                       s   e Zd Zdddddddeded	d
dee dee deded dee ddf fddZdddZdddZ	de
ddfddZ  ZS )	UploadJobr   zstats.Statsapizinternal_api.Apir   zfile_stream.FileStreamApisilent	save_namepathzdir_watcher.PathStrartifact_idmd5copiedsave_fnzstep_upload.SaveFndigestreturnNc                    sP   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	|| _
t   dS )aM  A file uploader.

        Args:
            push_function: function(save_name, actual_path) which actually uploads
                the file.
            save_name: string logical location of the file relative to the run
                directory.
            path: actual string path of the file to upload on the filesystem.
        N)_stats_api_file_streamr   r   	save_pathr   r   r   r   r   super__init__)selfr   r   r   r   r   r   r   r   r   r   r   	__class__ V/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/filesync/upload_job.pyr      s   zUploadJob.__init__c              
   C   s   d}z&|    d}W | jrtj| jrt| j |r'| j| j	| j
 d S d S | jr9tj| jr9t| j |rE| j| j	| j
 w w )NFT)pushr   osr   isfiler   remover   push_successr   r   )r   successr   r   r   run5   s   zUploadJob.runc                    st   j rjz   fdd}W n@ tyN } z4 j j td j tj| t	|}t
|dr7|jj}td j dt|j d|   d }~ww |ratd j  j j d S td	 j d S  jr j j j j\}}|d
 }|d }n j } j| jg\}}}	|	 j }
|
d
 }|d u rtd j  j j d S  jj}|D ]}|dd\}}|||< q|drӈ jj | }z.t jd} jj|| fdd|d W d    n1 sw   Y  td	 j W d S  ty9 } z+ j j td j tj|  js4td j dt|j d|   d }~ww )Nc                    s    j  j|S N)r   update_uploaded_filer   _tr   r   r   <lambda>E   s    z UploadJob.push.<locals>.<lambda>zFailed to upload file: %sresponsezError uploading "z": z, zSkipped uploading %szUploaded file %s	uploadUrluploadHeaders:   /rbc                    s
     |S r'   )progressr)   r,   r   r   r-      s   
 )extra_headers) r   	Exceptionr   update_failed_filer   logger	exceptionwandb_sentrystrhasattrr.   content	termerrortype__name__infoset_file_dedupedr   r   create_artifact_manifestr   r   get_projectupload_urls_extra_http_headerssplit
startswithapi_urlopenupload_file_retryr   )r   dedupedemessager*   r.   
upload_urlupload_headersprojectresult	file_infor6   upload_headerkeyvalfr   r,   r   r    @   s   







zUploadJob.pushtotal_bytesc                 C   s   | j | j| d S r'   )r   r(   r   )r   rZ   r   r   r   r5      s   zUploadJob.progress)r   N)rB   
__module____qualname__boolr   r   r=   r   r&   r    intr5   __classcell__r   r   r   r   r
      s:    	

$
Mr
   )loggingr!   typingr   r   r;   wandb.sdk.lib.pathsr   wandb.filesyncr   r   r   wandb.sdk.internalr   r	   	getLoggerrB   r9   r
   r   r   r   r   <module>   s    
