o
    wiq#                     @  s   d Z ddlmZ ddlmZ ddlmZmZ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 ddlmZ ddlmZ erhddlmZ ddlm Z  ddl!m"Z" G dd ded Z#G dd deZ$dS )a3  W&B Public API for Project objects.

This module provides classes for interacting with W&B projects and their
associated data.

Example:
```python
from wandb.apis.public import Api

# Get all projects for an entity
projects = Api().projects("entity")

# Access project data
for project in projects:
    print(f"Project: {project.name}")
    print(f"URL: {project.url}")

    # Get artifact types
    for artifact_type in project.artifacts_types():
        print(f"Artifact Type: {artifact_type.name}")

    # Get sweeps
    for sweep in project.sweeps():
        print(f"Sweep ID: {sweep.id}")
        print(f"State: {sweep.state}")
```

Note:
    This module is part of the W&B Public API and provides methods to access
    and manage projects. For creating new projects, use wandb.init()
    with a new project name.
    )annotations)Mapping)TYPE_CHECKINGAnyClassVar)override)gql)nameof)public)Attrs)normalize_exceptions)RelayPaginator)RetryingClient)Sweeps)ipython)Document
Connection)ProjectFragmentc                      sj   e Zd ZU dZdZded< ded< 	dd fddZedddZe	dddZ
d ddZdd Z  ZS )!Projectsa  An lazy iterator of `Project` objects.

    An iterable interface to access projects created and saved by the entity.

    Args:
        client (`wandb.apis.internal.Api`): The API client instance to use.
        entity (str): The entity name (username or team) to fetch projects for.
        per_page (int): Number of projects to fetch per request (default is 50).

    Example:
    ```python
    from wandb.apis.public.api import Api

    # Find projects that belong to this entity
    projects = Api().projects(entity="entity")

    # Iterate over files
    for project in projects:
        print(f"Project: {project.name}")
        print(f"- URL: {project.url}")
        print(f"- Created at: {project.created_at}")
        print(f"- Is benchmark: {project.is_benchmark}")
    ```
    NzClassVar[Document | None]QUERYz"Connection[ProjectFragment] | Nonelast_response2   clientr   entitystrper_pageintreturnc                   sD   | j du rddlm} t|t| _ || _t j|d|i|d dS )a   An iterable collection of `Project` objects.

        Args:
            client: The API client used to query W&B.
            entity: The entity which owns the projects.
            per_page: The number of projects to fetch per request to the API.
        Nr   )GET_PROJECTS_GQLr   )	variablesr   )r   wandb.apis._generatedr   r   typer   super__init__)selfr   r   r   r   	__class__ N/home/ubuntu/.local/lib/python3.10/site-packages/wandb/apis/public/projects.pyr$   W   s
   
zProjects.__init__Nonec                 C  sp   ddl m} ddlm}m} | jj| j| jd}|	|}|j
 }s.tdtt| d|| 	|| _dS )z:Fetch and validate the response data for the current page.r   r   )GetProjectsr   )variable_valueszUnable to parse z response dataN)wandb._pydanticr   r!   r+   r   r   executer   r    model_validatemodels
ValueErrorr	   r"   r   )r%   r   r+   r   dataresultconnr(   r(   r)   _update_responsel   s   

zProjects._update_responsec                 C  s   dS )zReturns the total number of projects.

        Note: This property is not available for projects.

        <!-- lazydoc-ignore: internal -->
        Nr(   r%   r(   r(   r)   lengthx   s   	zProjects.lengthnoder   Projectc                 C  s   t | j| j|j| S N)r9   r   r   name
model_dump)r%   r8   r(   r(   r)   _convert   s   zProjects._convertc                 C  s   d| j  dS )Nz
<Projects >)r   r6   r(   r(   r)   __repr__   s   zProjects.__repr__r   )r   r   r   r   r   r   r   r   r   r*   )r8   r   r   r9   )__name__
__module____qualname____doc__r   __annotations__r$   r   r5   propertyr7   r=   r?   __classcell__r(   r(   r&   r)   r   :   s   
 

r   )r   r9   c                      s   e Zd ZdZd9 fd
dZd:ddZed;ddZed<ddZed=ddZ	d>d?ddZ
d=dd Zd!d" Zed@dAd&d'Ze	(	(	#dBdCd.d/Zed@dDd1d2Zed=d3d4ZedE fd7d8Z  ZS )Fr9   zA project is a namespace for runs.

    Args:
        client: W&B API client instance.
        name (str): The name of the project.
        entity (str): The entity name that owns the project.
    r   r   r   r   projectattrsMapping[str, Any]r   c                   s,   t  | t|| _|| _|| _|| _dS )a  A single project associated with an entity.

        Args:
            client: The API client used to query W&B.
            entity: The entity which owns the project.
            project: The name of the project to query.
            attrs: The attributes of the project.
        N)r#   r$   bool
_is_loadedr   r;   r   )r%   r   r   rI   rJ   r&   r(   r)   r$      s
   

zProject.__init__r*   c              
   C  s   ddl m} ddlm}m} | j| jd}z| jt	||}W n |y4 } zt
d||d }~ww ||j}|rA| ni | _d| _d S )Nr   )	HTTPError)GET_PROJECT_GQL
GetProject)r;   r   zUnable to fetch project ID: T)requestsrN   r!   rO   rP   r;   r   r   r.   r   r1   r/   rI   r<   _attrsrM   )r%   rN   rO   rP   gql_varsr2   erI   r(   r(   r)   _load   s   
zProject._loadpublic.Userc                 C  s<   | j s|   d| jvrtd| j t| j| jd S )zReturns the project owner as a User object.

        Raises:
            ValueError: when no user information is found for the project.
        userzNo user found for project )rM   rU   rR   r1   r;   r
   Userr   r6   r(   r(   r)   owner   s
   
zProject.owner	list[str]c                 C  s   | j | jgS )zcReturns the path of the project. The path is a list containing the
        entity and project name.)r   r;   r6   r(   r(   r)   path   s   zProject.pathc                 C  s   | j jd| jdg  S )zReturns the URL of the project./	workspace)r   app_urljoinr[   r6   r(   r(   r)   url   s   zProject.url  Fheightr   hiddenrL   c                 C  sF   | j d }d| d}d}|r|d7 }td}|d|d|d	 S )
zoGenerate HTML containing an iframe displaying this project.

        <!-- lazydoc-ignore: internal -->
        z?jupyter=truezborder:none;width:100%;height:zpx; zdisplay:none;rI   z<iframe src=z style=z
></iframe>)r`   r   toggle_button)r%   rb   rc   r`   styleprefixr(   r(   r)   to_html   s   

zProject.to_htmlc                 C  s   |   S r:   )rh   r6   r(   r(   r)   _repr_html_   s   zProject._repr_html_c                 C  s   d d| jS )Nz<Project {}>r\   )formatr_   r[   r6   r(   r(   r)   r?      s   zProject.__repr__r   r   public.ArtifactTypesc                 C  s   t | j| j| jS )z8Returns all artifact types associated with this project.)r
   ArtifactTypesr   r   r;   r%   r   r(   r(   r)   artifacts_types   s   zProject.artifacts_typesNfiltersMapping[str, Any] | Noneorder
str | None!public.ProjectArtifactCollectionsc                 C  s   t j| j| j| j|||dS )a  Returns all artifact collections associated with this project.

        Args:
            filters: Optional mapping of filters to apply to the query.
            order: Optional string to specify the order of the results.
                If you prepend order with a + order is ascending (default).
                If you prepend order with a - order is descending.
            per_page: The number of artifact collections to fetch per page.
                Default is 50.
        )ro   rq   r   )r
   ProjectArtifactCollectionsr   r   r;   )r%   ro   rq   r   r(   r(   r)   collections   s   zProject.collectionsr   c                 C  s   t | j| j| j|dS )a  Return a paginated collection of sweeps in this project.

        Args:
            per_page: The number of sweeps to fetch per request to the API.

        Returns:
            A `Sweeps` object, which is an iterable collection of `Sweep` objects.
        )r   )r   r   r   r;   rm   r(   r(   r)   sweeps  s   
zProject.sweepsc                 C  s4   | j s|   d| jvrtd| j d| jd S )NidzProject z
 not found)rM   rU   rR   r1   r;   r6   r(   r(   r)   rw     s
   

z
Project.idr;   r   c                   s   | j s|   t |S r:   )rM   rU   r#   __getattr__)r%   r;   r&   r(   r)   rx     s   zProject.__getattr__)
r   r   r   r   rI   r   rJ   rK   r   r9   rA   )r   rV   )r   rZ   )r   r   )ra   F)rb   r   rc   rL   r   r   r@   )r   r   r   rk   )NNr   )ro   rp   rq   rr   r   r   r   rs   )r   r   r   r   )r;   r   r   r   )rB   rC   rD   rE   r$   rU   rG   rY   r[   r`   rh   ri   r?   r   rn   ru   rv   rw   r   rx   rH   r(   r(   r&   r)   r9      s4    

	r9   N)%rE   
__future__r   collections.abcr   typingr   r   r   typing_extensionsr   	wandb_gqlr   wandb._strutilsr	   
wandb.apisr
   wandb.apis.attrsr   wandb.apis.normalizer   wandb.apis.paginatorr   wandb.apis.public.apir   wandb.apis.public.sweepsr   wandb.sdk.libr   wandb_graphql.language.astr   r-   r   r!   r   r   r9   r(   r(   r(   r)   <module>   s(    !P