o
    -wi                     @  s  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
 d dlmZ ddlmZmZmZmZmZmZmZmZ e
d	ZG d
d deeZd&ddZd&ddZd&ddZd&ddZd&ddZed'ddZejd(dd Z ejd)d"d Z ejd*d$d Z d%S )+    )annotations)Enum)singledispatch)chain)AnyTypeVarPydanticUseDefault   )And
FilterExprInNorNotNotInOpOrTc                   @  s(   e Zd ZdZdddZedd	d
ZdS )LenientStrEnumzA string enum allowing for case-insensitive lookups by value.

    May include other internal customizations if needed.

    Note: This is a bespoke, internal implementation and NOT intended as a
    backport of `enum.StrEnum` from Python 3.11+.
    returnstrc                 C  s   | j S N)name)self r   Z/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/automations/_validators.py__repr__   s   zLenientStrEnum.__repr__valueobjectr   c                   s.   t |tr|  t fdd| D d S d S )Nc                 3  s"    | ]}|j   kr|V  qd S r   )r   lower).0evr   r   	<genexpr>    s     z+LenientStrEnum._missing_.<locals>.<genexpr>)
isinstancer   r   next)clsr   r   r"   r   	_missing_   s   
zLenientStrEnum._missing_N)r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   classmethodr(   r   r   r   r   r      s
    
r   r#   r   r   c                 C  s   | du rt | S )zTA before-validator validator that coerces `None` to the default field value instead.Nr   r"   r   r   r   default_if_none$   s   r.   c                 C  s   t | tr|   S | S r   )r%   r   stripupperr"   r   r   r   upper_if_str,   s   r1   c                 C  sl   ddl m}m} ddlm}m}m} t| |r|| j| j	dS t| |r4| 
 r*|n|}|| j| j	dS | S )zWConvert eligible objects, including pre-existing `wandb` types, to an automation scope.r   )ArtifactCollectionProjectr
   )ProjectScope_ArtifactPortfolioScope_ArtifactSequenceScope)idr   )wandb.apis.publicr2   r3   scopesr4   r5   r6   r%   r7   r   is_sequence)r#   r2   r3   r4   r5   r6   r'   r   r   r   to_scope1   s   

r;   c                 C  s   ddl m}m}m}m}m}m} t| |r&|ddd| jii| j	dhdS t| |r<|ddd| jii| j	dhdS t| |rF|
| S | S )	zBIf necessary (and possible), convert the object to a saved action.r
   	DoNothingSavedNoOpActionSavedNotificationActionSavedWebhookActionSendNotificationSendWebhookintegrationr7   integration_idexcludeNr   )actionsr=   r>   r?   r@   rA   rB   r%   rD   
model_dumpmodel_validater#   r=   r>   r?   r@   rA   rB   r   r   r   to_saved_action?   s     
	


rK   c                 C  s   ddl m}m}m}m}m}m} t| |r%|dd| jj	i| j
dhdS t| |r:|dd| jj	i| j
dhdS t| |rD|| S | S )zCIf necessary (and possible), convert the object to an input action.r
   r<   rD   rC   rE   Nr   )rG   r=   r>   r?   r@   rA   rB   r%   rC   r7   rH   rI   rJ   r   r   r   to_input_actionZ   s     
	


rL   opOp | FilterExprc                 C  s   | S )zHSimplify a MongoDB filter by removing and unnesting redundant operators.r   )rM   r   r   r   simplify_opv   s   rO   r   r   c                 C  J   | j  }s| S t|dkrt|d S tdd |D }ttt|dS )Nr
   r   c                 s  &    | ]}t |tr|jn|gV  qd S r   )r%   r   and_r    xr   r   r   r$         $ _.<locals>.<genexpr>)rR   )rR   lenrO   r   from_iterabler   maprM   args	flattenedr   r   r   _|      
r]   r   c                 C  rP   )Nr
   r   c                 s  rQ   r   )r%   r   or_rS   r   r   r   r$      rU   rV   )r_   )r_   rW   rO   r   rX   r   rY   rZ   r   r   r   r]      r^   r   c                 C  s2   | j }t|tttttfrt| S tt|dS )N)not_)r`   r%   r   r   r   r   r   rO   )rM   innerr   r   r   r]      s   
N)r#   r   r   r   )rM   rN   r   rN   )rM   r   r   r   )rM   r   r   r   )rM   r   r   r   )!
__future__r   enumr   	functoolsr   	itertoolsr   typingr   r   pydantic_corer	   _filtersr   r   r   r   r   r   r   r   r   r   r   r.   r1   r;   rK   rL   rO   registerr]   r   r   r   r   <module>   s,    (




