o
    -wi!                     @  s   d Z ddlmZ ddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZmZmZ ddlmZmZmZmZ ee Z!ersddl"m#Z# ddl$m%Z% G dd de#ddZ&G dd dZ'dS )zArtifact manifest entry.    )annotationsN)Path)TYPE_CHECKING)urlparse)
Deprecated)
filesystem)	deprecate)B64MD5ETagb64_to_hex_idhex_to_b64_idmd5_file_b64)FilePathStrLogicalPathStrPathURIStr)	TypedDict)Artifactc                   @  sN   e Zd ZU ded< ded< ded< ded< ded< ded	< d
ed< ded< dS )ArtifactManifestEntryDictstrpathdigestbool
skip_cacherefbirthArtifactIDintsizedictextra
local_pathN)__name__
__module____qualname____annotations__ r%   r%   h/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest_entry.pyr       s   
 r   F)totalc                   @  s   e Zd ZU dZded< ded< ded< ded	< d
ed< ded< ded< d
ed< dZded< dZd
ed< 						d=d>ddZd?dd Zd@d#d$Z	e
dAd%d&ZdBd(d)Z				dCdDd/d0ZdEd2d3Zd?d4d5ZdFd7d8ZdGd9d:ZdHd;d<ZdS )IArtifactManifestEntryz'A single entry in an artifact manifest.r   r   $B64MD5 | URIStr | FilePathStr | ETagr   r   r   FilePathStr | URIStr | Noner   
str | Nonebirth_artifact_id
int | Noner   r   r   r    NzArtifact | None_parent_artifact_download_urlFr   bool | Nonedict | NoneStrPath | NonereturnNonec	           	      C  sn   t || _|| _|| _|| _|| _|pi | _|rt|nd | _| jr0| jd u r0t	| j
 j| _|p3d| _d S )NF)r   r   r   r   r,   r   r   r   r    r   statst_sizer   )	selfr   r   r   r   r,   r   r   r    r%   r%   r&   __init__:   s   

zArtifactManifestEntry.__init__r   c           	      C  s   | j j}| jd urd| jnd}| jd urd| jnd}| jd ur)d| j nd}| jr7dt| j nd}| jrBd| jnd}d| j	 }|| | | | | }| d| j
d	| j| d
S )Nz, ref= z, birth_artifact_id=z, size=z, extra=z, local_path=z, skip_cache=z(path=z	, digest=))	__class__r!   r   r,   r   r   jsondumpsr    r   r   r   )	r7   clsr   r,   r   r   r    r   othersr%   r%   r&   __repr__P   s   
zArtifactManifestEntry.__repr__otherobjectc                 C  sn   t |tsdS | j|jko6| j|jko6| j|jko6| j|jko6| j|jko6| j|jko6| j|jko6| j	|j	kS )zStrict equality, comparing all public fields.

        ArtifactManifestEntries for the same file may not compare equal if they were
        added in different ways or created for different parent artifacts.
        F)

isinstancer(   r   r   r   r,   r   r   r    r   )r7   rA   r%   r%   r&   __eq___   s"   







zArtifactManifestEntry.__eq__c                 C  s   t tjdd | jS )zDeprecated; use `path` instead.z<ArtifactManifestEntry.name is deprecated, use .path instead.)
field_namewarning_message)r   r   artifactmanifestentry__namer   r7   r%   r%   r&   namer   s
   zArtifactManifestEntry.namer   c                 C  s   | j du rt| j S )zGet the artifact to which this artifact entry belongs.

        Returns:
            (PublicArtifact): The parent artifact
        N)r.   NotImplementedErrorrH   r%   r%   r&   parent_artifact{   s   
z%ArtifactManifestEntry.parent_artifactrootexecutor"concurrent.futures.Executor | None	multipartr   c           
   	   C  s   | j du rt|p| j  }| j | tt| j}tj||}|r'|}nd}zt	|}W n t
tfyC   td| d Y n
w | j|krMt|S | jdur^| j jjj| d|d}	n| j jjj| j | |||d}	|rrt|S ttt|	|S )a+  Download this artifact entry to the specified root path.

        Args:
            root: (str, optional) The root path in which to download this
                artifact entry. Defaults to the artifact's root.

        Returns:
            (str): The path of the downloaded artifact entry.
        Nzunable to find z, skip searching for fileT)local	dest_path)rQ   rM   rO   )r.   rJ   _default_root_add_download_rootr   r   r   osjoinr   FileNotFoundErrorIsADirectoryErrorloggerdebugr   r   r   manifeststorage_policyload_reference	load_filer   copy_or_overwrite_changed)
r7   rL   r   rM   rO   r   rQ   override_cache_pathmd5_hash
cache_pathr%   r%   r&   download   s@   




zArtifactManifestEntry.downloadFilePathStr | URIStrc                 C  sB   | j du r	td| jdu r| j S | jjjj| jjj| j ddS )zGet the reference URL that is targeted by this artifact entry.

        Returns:
            (str): The reference URL of this artifact entry.

        Raises:
            ValueError: If this artifact entry was not a reference.
        Nz,Only reference entries support ref_target().F)rP   )r   
ValueErrorr.   rZ   r[   r\   entriesr   rH   r%   r%   r&   
ref_target   s   
	

z ArtifactManifestEntry.ref_targetc                 C  s<   | j du rt| j jdusJ dtt| j j d | j S )aw  Get a URL to this artifact entry.

        These URLs can be referenced by another artifact.

        Returns:
            (str): A URL representing this artifact entry.

        Examples:
            Basic usage
            ```
            ref_url = source_artifact.get_entry("file.txt").ref_url()
            derived_artifact.add_reference(ref_url)
            ```
        Nzwandb-artifact:///)r.   rJ   idr   r	   r   rH   r%   r%   r&   ref_url   s   
zArtifactManifestEntry.ref_urlr   c                 C  sv   | j | jd}| jd ur| j|d< | jr| j|d< | jr!| j|d< | jr)| j|d< | jr1| j|d< | jr9| j|d< |S )N)r   r   r   r   r   r    r   r   )r   r   r   r   r,   r    r   r   )r7   contentsr%   r%   r&   to_json   s    






zArtifactManifestEntry.to_jsonc                 C  s   | j d uot| j jdkS )Nzwandb-artifact)r   r   schemerH   r%   r%   r&   _is_artifact_reference   s   z,ArtifactManifestEntry._is_artifact_referencec                 C  s   |   sd S tt| jjS )N)rm   r   r   r   netlocrH   r%   r%   r&   _referenced_artifact_id   s   z-ArtifactManifestEntry._referenced_artifact_id)FNNNNN)r   r   r   r)   r   r0   r   r*   r,   r+   r   r-   r   r1   r    r2   r3   r4   )r3   r   )rA   rB   r3   r   )r3   r   )r3   r   )NNNN)
rL   r+   r   r0   rM   rN   rO   r0   r3   r   )r3   rc   )r3   r   )r3   r   )r3   r+   )r!   r"   r#   __doc__r$   r.   r/   r8   r@   rD   propertyrI   rK   rb   rf   ri   rk   rm   ro   r%   r%   r%   r&   r(   +   sD   
 



;


r(   )(rp   
__future__r   concurrent.futures
concurrentr<   loggingrT   pathlibr   typingr   urllib.parser   wandb.proto.wandb_deprecatedr   wandb.sdk.libr   wandb.sdk.lib.deprecater   wandb.sdk.lib.hashutilr	   r
   r   r   r   wandb.sdk.lib.pathsr   r   r   r   	getLoggerr!   rX   typing_extensionsr   wandb.sdk.artifacts.artifactr   r   r(   r%   r%   r%   r&   <module>   s(    
