o
    xi
                     @  s   d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ er<dd	lmZ dd
lmZ G dd deeZdS )zArtifact manifest.    )annotations)ABCabstractmethod)TYPE_CHECKING	AnnotatedAnyDict)Field)HexMD5   )ArtifactsBase)ArtifactManifestEntry)StoragePolicyc                   @  s   e Zd ZU ded< eedZded< ded< ed-d
dZee	d.ddZ
d-ddZe	d/ddZe	d0ddZe	d-ddZd1d2dd Zd3d!d"Zd4d&d'Zd5d*d+Zd,S )6ArtifactManifestz!Annotated[Any, Field(repr=False)]manifest_version)default_factoryz Dict[str, ArtifactManifestEntry]entriesz9Annotated[StoragePolicy, Field(exclude=True, repr=False)]storage_policyreturnintc                 C  s   | j d jS )Nr   )model_fieldsdefault)cls r   Y/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/artifacts/artifact_manifest.pyversion   s   zArtifactManifest.versionmanifest_jsondict[str, Any]c                 C  sJ   | d }d u rtd|  D ]}| |kr ||  S qtd)Nr   z4Invalid manifest format. Must contain version field.zInvalid manifest version.)get
ValueError__subclasses__r   from_manifest_json)r   r   r   subr   r   r   r!      s   z#ArtifactManifest.from_manifest_jsonc                 C  s
   t | jS N)lenr   selfr   r   r   __len__*   s   
zArtifactManifest.__len__c                 C     t r#   NotImplementedErrorr%   r   r   r   to_manifest_json-      z!ArtifactManifest.to_manifest_jsonr
   c                 C  r(   r#   r)   r%   r   r   r   digest1   r,   zArtifactManifest.digestc                 C  r(   r#   r)   r%   r   r   r   size5   r,   zArtifactManifest.sizeFentryr   	overwriteboolNonec                 C  sB   |s| j |j }r|j|jkrtd|j|| j |j< d S )Nz Cannot add the same path twice: )r   r   pathr-   r   )r&   r/   r0   	old_entryr   r   r   	add_entry9   s   zArtifactManifest.add_entryc                 C  s0   z| j |j= W d S  ty   td|jw )NzCannot remove missing entry: )r   r3   LookupErrorFileNotFoundError)r&   r/   r   r   r   remove_entryB   s
   zArtifactManifest.remove_entryr3   strArtifactManifestEntry | Nonec                 C  s   | j |S r#   )r   r   )r&   r3   r   r   r   get_entry_by_pathH   s   z"ArtifactManifest.get_entry_by_path	directorylist[ArtifactManifestEntry]c                   s"   | d  fdd| j  D S )N/c                   s   g | ]\}}|  r|qS r   )
startswith).0keyobj
dir_prefixr   r   
<listcomp>N   s    z=ArtifactManifest.get_entries_in_directory.<locals>.<listcomp>)r   items)r&   r<   r   rC   r   get_entries_in_directoryK   s   
z)ArtifactManifest.get_entries_in_directoryN)r   r   )r   r   r   r   )r   r   )r   r
   )F)r/   r   r0   r1   r   r2   )r/   r   r   r2   )r3   r9   r   r:   )r<   r9   r   r=   )__name__
__module____qualname____annotations__r	   dictr   classmethodr   r   r!   r'   r+   r-   r.   r5   r8   r;   rG   r   r   r   r   r      s(   
 
	
	
r   N)__doc__
__future__r   abcr   r   typingr   r   r   r   pydanticr	   wandb.sdk.lib.hashutilr
   _models.base_modelr   artifact_manifest_entryr   r   r   r   r   r   r   r   <module>   s    