o
    xi                     @  s   d dl mZ 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r8d 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 )
    )annotationsN)TYPE_CHECKING)
get_sentry)LogicalPath)dir_watcherstatsstep_upload)file_streaminternal_apic                      s<   e Zd Zd  fddZd!ddZd!ddZd"ddZ  ZS )#	UploadJobr   stats.Statsapiinternal_api.Apir	   file_stream.FileStreamApisilentbool	save_namer   pathdir_watcher.PathStrartifact_id
str | Nonemd5copiedsave_fnstep_upload.SaveFn | NonedigestreturnNonec                   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__ M/home/ubuntu/.local/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(   run8   s   zUploadJob.runc                   st   j rjz   fdd}W n@ tyN } z4 j j td j t | 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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>H   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 r0   )progressr2   r5   r'   r(   r6      s   
 )extra_headers) r   	Exceptionr   update_failed_filer!   logger	exceptionr   strhasattrr7   contentwandb	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messager3   r7   
upload_urlupload_headersprojectresult	file_infor?   upload_headerkeyvalfr'   r5   r(   r)   C   s   







zUploadJob.pushtotal_bytesintc                 C  s   | j | j| d S r0   )r   r1   r   )r$   rb   r'   r'   r(   r>      s   zUploadJob.progress)r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )rb   rc   r   r   )rJ   
__module____qualname__r#   r/   r)   r>   __classcell__r'   r'   r%   r(   r      s
    
$
Mr   )
__future__r   loggingr*   typingr   rG   wandb.analyticsr   wandb.sdk.lib.pathsr   wandb.filesyncr   r   r   wandb.sdk.internalr	   r
   	getLoggerrJ   rB   r   r'   r'   r'   r(   <module>   s    
