o
    niK                     @  sJ  U d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZmZ erWddlmZmZmZmZ ddlmZ e
d	ed
Ze
dZeee eee df f ZdZded< ed1d2ddZed1d3ddZeeffd4ddZd5ddZ e!d Z"d!ed"< d6d$d%Z#e
d&e	def d
Z$	 d7d(d)Z%d7d*d+Z&d8d/d0Z'dS )9z=Internal validation utilities that are specific to artifacts.    )annotationsN)wraps)TYPE_CHECKINGAnyCallableTypeVarcastoverload)ArtifactFinalizedErrorArtifactNotLoggedError)
CollectionFinalIterableUnion)Artifact	ArtifactT)boundT.zwandb-registry-z
Final[str]REGISTRY_PREFIXobjIterable[T]	base_type	ClassInforeturnlist[T]c                 C     d S N r   r   r   r   ]/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/wandb/sdk/artifacts/_validators.pyalways_list      r    c                 C  r   r   r   r   r   r   r   r       r!   r   c                 C  s   t | |r| gS t| S )at  Return a guaranteed list of objects from a single instance OR iterable of such objects.

    By default, assume the returned list should have string-like elements (i.e. `str`/`bytes`).

    Adapted from `more_itertools.always_iterable`, but simplified for internal use.  See:
    https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.always_iterable
    )
isinstancelistr   r   r   r   r    "   s   aliasesCollection[str] | str	list[str]c                   s:   t | }d t fdd|D rtdd  |S )zValidate the artifact aliases and return them as a list.

    Raises:
        ValueError: If any of the aliases contain invalid characters.
    )/:c                 3  s"    | ]} D ]}||v V  qqd S r   r   ).0aliascharinvalid_charsr   r   	<genexpr>6   s     z#validate_aliases.<locals>.<genexpr>z:Aliases must not contain any of the following characters: z, )r    any
ValueErrorjoin)r$   aliases_listr   r,   r   validate_aliases-   s   r3   z^[-\w]+( +[-\w]+)*$zre.Pattern[str]_VALID_TAG_PATTERNtagsc                 C  s0   t | }tdd |D rtdtt|S )a   Validate the artifact tag names and return them as a deduped list.

    In the case of duplicates, only keep the first tag, and otherwise maintain the order of appearance.

    Raises:
        ValueError: If any of the tags contain invalid characters.
    c                 s  s    | ]	}t | V  qd S r   )r4   match)r)   tagr   r   r   r.   J   s    z validate_tags.<locals>.<genexpr>zqInvalid tag(s).  Tags must only contain alphanumeric characters separated by hyphens, underscores, and/or spaces.)r    r/   r0   r#   dictfromkeys)r5   	tags_listr   r   r   validate_tags@   s   r;   
DecoratedFmethodc                   (    j t d
 fdd}tt|S )zDecorator to ensure that an Artifact method can only be called if the artifact has been logged.

    If the method is called on an artifact that's not logged, `ArtifactNotLoggedError` is raised.
    selfr   argsr   kwargsr   c                   s*   |   r
t| d | g|R i |S N)fullnamer   )is_draftr   r?   r@   rA   r=   method_fullnamer   r   wrapper^   s   zensure_logged.<locals>.wrapperNr?   r   r@   r   rA   r   r   r   __qualname__r   r   r<   r=   rH   r   rF   r   ensure_loggedV      
rM   c                   r>   )zDecorator to ensure that an `Artifact` method can only be called if the artifact isn't finalized.

    If the method is called on an artifact that's not logged, `ArtifactFinalizedError` is raised.
    r?   r   r@   r   rA   r   c                   s(   | j r	t| d | g|R i |S rB   )_finalr
   rE   rF   r   r   rH   o   s   z%ensure_not_finalized.<locals>.wrapperNrI   rJ   rL   r   rF   r   ensure_not_finalizedg   rN   rP   projectstrboolc                 C  s
   |  tS r   )
startswithr   )rQ   r   r   r   is_artifact_registry_projectx   s   
rU   ).)r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r$   r%   r   r&   )r5   r%   r   r&   )r=   r<   r   r<   )rQ   rR   r   rS   )(__doc__
__future__r   re	functoolsr   typingr   r   r   r   r   r	   wandb.sdk.artifacts.exceptionsr
   r   r   r   r   r   wandb.sdk.artifacts.artifactr   r   r   typetupler   r   __annotations__r    rR   bytesr3   compiler4   r;   r<   rM   rP   rU   r   r   r   r   <module>   s4     



