o
    xiK                     @  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	 d dl
mZ d dlmZ d dlmZ d d	lmZmZ e	rLd d
lmZ d dlmZ d dlmZ eddd0ddZeddd1ddZeddd2ddZd3d!d"Zd4d$d%Zed&d'G d(d) d)Z	*d5d6d.d/Zd*S )7    )annotations)suppress)	dataclass)	lru_cache)TYPE_CHECKING)gql)one)ServerFeature)SERVER_FEATURES_QUERY_GQLServerFeaturesQuery)RetryingClient)TypeInfoFragment)FetchOrgInfoFromEntityEntity   )maxsizeclientr   typenamestrreturnTypeInfoFragment | Nonec                 C  s2   ddl m}m} | jt|d|id}||jS )z/Returns the type info for a given GraphQL type.   )TYPE_INFO_GQLTypeInfonamevariable_values)
_generatedr   r   executer   model_validatetype)r   r   r   r   data r!   Q/home/ubuntu/.local/lib/python3.10/site-packages/wandb/sdk/artifacts/_gqlutils.py	type_info   s   r#   entity#FetchOrgInfoFromEntityEntity | Nonec                 C  s6   ddl m}m} t|}| j|d|id}||jS )z1Returns the organization info for a given entity.r   )FETCH_ORG_INFO_FROM_ENTITY_GQLFetchOrgInfoFromEntityr$   r   )r   r&   r'   r   r   r   r$   )r   r$   r&   r'   gql_opr    r!   r!   r"   org_info_from_entity   s   r)   dict[str, bool]c              
   C  sz   z	|  tt}W n ty$ } zdt|v ri W  Y d}~S  d}~ww t|}|j }r;|j }r;dd |D S i S )zzReturns a mapping of `{server_feature_name (str) -> is_enabled (bool)}`.

    Results are cached per client instance.
    z3Cannot query field "features" on type "ServerInfo".Nc                 S  s   i | ]	}|r|j |jqS r!   )r   
is_enabled).0featr!   r!   r"   
<dictcomp><   s    z#server_features.<locals>.<dictcomp>)	r   r   r
   	Exceptionr   r   r   server_infofeatures)r   responseeresultr0   r1   r!   r!   r"   server_features+   s   
r5   feature	str | intboolc                 C  sD   zt |trt|n|}W n
 ty   Y dS w t| |p!dS )zReturn whether the current server supports the given feature.

    Good to use for features that have a fallback mechanism for older servers.
    F)
isinstanceintr	   Name
ValueErrorr5   get)r   r6   r   r!   r!   r"   server_supports@   s   
r>   set[str]c                 C  s*   t | |}|r|jrdd |jD S t S )z9Returns the allowed field names for a given GraphQL type.c                 S  s   h | ]}|j qS r!   )r   )r,   fr!   r!   r"   	<setcomp>T   s    z!allowed_fields.<locals>.<setcomp>)r#   fieldsset)r   r   typr!   r!   r"   allowed_fieldsQ   s   
 rE   T)frozenc                   @  s(   e Zd ZU ded< ded< d
ddZd	S )OrgInfor   org_nameentity_nameotherr   r8   c                 C  s   || j | jhv S NrH   rI   )selfrJ   r!   r!   r"   __contains__\   s   zOrgInfo.__contains__N)rJ   r   r   r8   )__name__
__module____qualname____annotations__rN   r!   r!   r!   r"   rG   W   s   
 rG   Nnon_org_entity
str | Noneorg_or_entityc           	        s4  |st dt| |}|r(|j }r(|j  r(t|j jd}r%|v r( jS |r|j }r|j }r fdd|D }rztt	 t
fdd|D W  d    S 1 sYw   Y  t|dkrrt d|d	 jd
dt ddtdd |D t d|dt d|ddS t d|d)Nz3Entity name is required to resolve org entity name.rL   c                   s&   g | ]}|j   rt|j jd qS )rL   )
org_entityrG   r   r,   org)rV   r!   r"   
<listcomp>   s    z+resolve_org_entity_name.<locals>.<listcomp>c                 3  s    | ]
} |v r|j V  qd S rK   rI   )r,   info)rU   r!   r"   	<genexpr>   s    z*resolve_org_entity_name.<locals>.<genexpr>r   z8Expecting the organization name or entity name to match r   z# and cannot be linked/fetched with zC. Please update the target path with the correct organization name.zTPersonal entity belongs to multiple organizations and cannot be linked/fetched with zo. Please update the target path with the correct organization name or use a team entity in the entity settings.c                 s  s    | ]}|j V  qd S rK   rZ   rW   r!   r!   r"   r\      s    zCUnable to resolve an organization associated with personal entity: z. This could be because its a personal entity that doesn't belong to any organizations. Please specify the organization in the Registry path or use a team entity in the entity settings.zPersonal entity z belongs to multiple organizations and cannot be used without specifying the organization name. Please specify the organization in the Registry path or use a team entity in the entity settings.)	too_shorttoo_longz'Unable to find organization for entity .)r<   r)   organizationrV   rG   r   userorganizationsr   StopIterationnextlenrH   r   )	r   rS   rU   r$   rX   org_infora   orgs	org_infosr!   )rV   rU   r"   resolve_org_entity_name`   sL   


 

ri   )r   r   r   r   r   r   )r   r   r$   r   r   r%   )r   r   r   r*   )r   r   r6   r7   r   r8   )r   r   r   r   r   r?   rK   )r   r   rS   rT   rU   rT   r   r   ) 
__future__r   
contextlibr   dataclassesr   	functoolsr   typingr   	wandb_gqlr   wandb._iterutilsr   wandb.proto.wandb_internal_pb2r	   wandb.sdk.internal._generatedr
   r   wandb.apis.publicr   wandb.sdk.artifacts._generatedr   9wandb.sdk.artifacts._generated.fetch_org_info_from_entityr   r#   r)   r5   r>   rE   rG   ri   r!   r!   r!   r"   <module>   s2    

