o
    wi                     @  s   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
mZ d dlmZ d dlmZ e
r6d dlmZ G d	d
 d
eeZd!ddZd"d#ddZeddd$ddZd S )%    )annotations)
Collection)Enum)	lru_cachepartial)TYPE_CHECKINGAny)gql)ensureprefix)RetryingClientc                   @  s>   e Zd ZdZdZedddZedd
dZedddZdS )
VisibilityPRIVATE
RESTRICTEDvalueobjectreturnr   c                 C  s   | j |S N)__members__get)clsr    r   W/home/ubuntu/.local/lib/python3.10/site-packages/wandb/apis/public/registries/_utils.py	_missing_   s   zVisibility._missing_strc                 C  D   z| |W S  t y!   ddd | D }t d|d| dw )z:Convert a GraphQL `visibility` value to a Visibility enum.,c                 s      | ]}t |jV  qd S r   )reprr   .0er   r   r   	<genexpr>!       z&Visibility.from_gql.<locals>.<genexpr>Invalid visibility z  from backend. Expected one of: N
ValueErrorjoin)r   r   expectedr   r   r   from_gql      
zVisibility.from_gqlnamec                 C  r   )z3Convert a visibility string to a `Visibility` enum.r   c                 s  r   r   )r   r*   r   r   r   r   r!   ,   r"   z)Visibility.from_python.<locals>.<genexpr>r#   z. Expected one of: Nr$   )r   r*   r'   r   r   r   from_python&   r)   zVisibility.from_pythonN)r   r   r   r   )r   r   r   r   )r*   r   r   r   )	__name__
__module____qualname__organization
restrictedclassmethodr   r(   r+   r   r   r   r   r      s    
r   artifact_typesCollection[str] | Noner   list[dict[str, str]] | Nonec                 C  s&   ddl m} | rdd || D S dS )zFormat the artifact types for the GQL input.

    Args:
        artifact_types: The artifact types to add to the registry.

    Returns:
        The artifact types for the GQL input.
    r   )validate_artifact_typesc                 S  s   g | ]}d |iqS )r*   r   )r   typr   r   r   
<listcomp>@   s    z0prepare_artifact_types_input.<locals>.<listcomp>N)wandb.sdk.artifacts._validatorsr5   )r2   r5   r   r   r   prepare_artifact_types_input2   s   r9   Fqueryr   in_nameboolc           	      C  s   ddl m} t|  }tr|rt||S |S t|  }trHi }| D ]"\}}|dkr0|||< q#|dkr=t|dd||< q#t||d||< q#|S t|  }tt	fr\tt
tt|d|S | S )zRecursively the registry prefix to values under "name" keys, excluding regex ops.

    - in_name: True if we are under a "name" key (or propagating from one).

    EX: {"name": "model"} -> {"name": "wandb-registry-model"}
    r   )REGISTRY_PREFIXz$regexr*   T)r;   )r8   r=   
isinstancer   r
   dictitemsensure_registry_prefix_on_nameslisttuplemapr   )	r:   r;   r=   txtdctnew_dictkeyobjseqr   r   r   rA   D   s   
rA   
   )maxsizeclientr   r/   r   c              
   C  s   ddl m}m} t|}z| j|d|id}W n ty- } z
d|}t||d}~ww ||}|j }	rB|	j	 }
rB|
j
 }sJtd|d|S )	zFetch the org entity from the organization.

    Args:
        client (Client): Graphql client.
        organization (str): The organization to fetch the org entity for.
    r   )&FETCH_ORG_ENTITY_FROM_ORGANIZATION_GQLFetchOrgEntityFromOrganizationr/   )variable_valuesz,Error fetching org entity for organization: NzOrganization entity for z not found.)wandb.sdk.artifacts._generatedrN   rO   r	   execute	Exceptionr%   model_validater/   
org_entityr*   )rM   r/   rN   rO   gql_opdatar    msgresultorgrU   org_namer   r   r   "fetch_org_entity_from_organization`   s$   



r\   N)r2   r3   r   r4   )F)r:   r   r;   r<   r   r   )rM   r   r/   r   r   r   )
__future__r   collections.abcr   enumr   	functoolsr   r   typingr   r   	wandb_gqlr	   wandb._strutilsr
   wandb.apis.public.apir   r   r   r9   rA   r\   r   r   r   r   <module>   s    
"