o
    -wi                     @   s   d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
mZ d dlmZmZ er.d dlmZ d dlmZ G dd deeZ		dd
e
ee  fddZdeded fddZded defddZdddZedddddedefddZd	S )     )Enum)	lru_cache)TYPE_CHECKINGAnyListLiteralMappingOptionalSequence)REGISTRY_PREFIXvalidate_artifact_types_list)Client)gqlc                   @   s*   e Zd ZdZdZededefddZdS )
VisibilityPRIVATE
RESTRICTEDvaluereturnc                    s   t  fdd| D d S )Nc                 3   s    | ]
}|j  kr|V  qd S Nname.0er    `/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/apis/public/registries/_utils.py	<genexpr>   s    z'Visibility._missing_.<locals>.<genexpr>)next)clsr   r   r   r   	_missing_   s   zVisibility._missing_N)	__name__
__module____qualname__organization
restrictedclassmethodobjectr   r    r   r   r   r   r      s
    r   Nartifact_typesc                 C   s"   | du rg S t | }dd |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.
    Nc                 S   s   g | ]}d |iqS r   r   )r   typer   r   r   
<listcomp>,   s    z3format_gql_artifact_types_input.<locals>.<listcomp>)r   )r(   	new_typesr   r   r   format_gql_artifact_types_input   s   r,   
visibilityr   )r$   r%   c                 C   s,   zt | jW S  ty   td| dw )zConvert the GQL visibility to the registry visibility.

    Args:
        visibility: The GQL visibility.

    Returns:
        The registry visibility.
    Invalid visibility: z from backend)r   r   
ValueErrorr-   r   r   r   gql_to_registry_visibility/   s
   r1   c                 C   sF   zt |  jW S  ty"   td| ddttdd t D  w )z6Convert the registry visibility to the GQL visibility.r.   z. Must be one of: z, c                 s   s    | ]}|j V  qd S r   r   r   r   r   r   r   I   s    z-registry_visibility_to_gql.<locals>.<genexpr>)r   r   KeyErrorr/   joinmapreprr0   r   r   r   registry_visibility_to_gql@   s   r6   Fc                    s   t |  }tr r|tr|S t | S |S t |  }trJi }| D ]"\}}|dkr6t|dd||< q%|dkr?|||< q%t| d||< q%|S t |  }tr\tt	 fdd|S | S )zTraverse the filter to prepend the `name` key value with the registry prefix unless the value is a regex.

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

    EX: {"name": "model"} -> {"name": "wandb-registry-model"}
    r   Tin_namez$regexc                    s   t |  dS )Nr7   )ensure_registry_prefix_on_names)xr7   r   r   <lambda>f   s    z1ensure_registry_prefix_on_names.<locals>.<lambda>)

isinstancestr
startswithr   r   itemsr9   r
   listr4   )queryr8   txtdctnew_dictkeyobjobjsr   r7   r   r9   M   s$   
r9   
   )maxsizeclientr   r$   c              
   C   s   t d}z| j|d|id}W n ty# } ztd| |d}~ww |d  }r6|d  }r6|d  }s>t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.
    z
        query FetchOrgEntityFromOrganization($organization: String!) {
            organization(name: $organization) {
                    orgEntity {
                        name
                    }
                }
            }
        r$   )variable_valuesz,Error fetching org entity for organization: N	orgEntityr   zOrganization entity for z not found.)r   execute	Exceptionr/   )rJ   r$   rA   responser   org
org_entityorg_namer   r   r   "fetch_org_entity_from_organizationk   s*   


rS   r   )F)enumr   	functoolsr   typingr   r   r   r   r   r	   r
   wandb.sdk.artifacts._validatorsr   r   	wandb_gqlr   r   r=   r   r,   r1   r6   r9   rS   r   r   r   r   <module>   s2    $




