
    wi*                     P   d dl mZ d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ  G d d	ee          Ze G d
 d                      Ze G d d                      Ze G d d                      Ze G d d                      Ze G d d                      Ze G d d                      Ze G d d                      Zdedee         de	eeef                  de	eeef                  de	e         de	e
eeef                  deeef         fdZd S )!    )	dataclass)datetime)Enum)AnyDictListOptionalUnion)	constants)SpaceHardware)parse_datetimec                   &    e Zd ZdZdZdZdZdZdZdS )JobStageah  
    Enumeration of possible stage of a Job on the Hub.

    Value can be compared to a string:
    ```py
    assert JobStage.COMPLETED == "COMPLETED"
    ```
    Possible values are: `COMPLETED`, `CANCELED`, `ERROR`, `DELETED`, `RUNNING`.
    Taken from https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (private url).
    	COMPLETEDCANCELEDERRORDELETEDRUNNINGN)	__name__
__module____qualname____doc__r   r   r   r   r        q/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/huggingface_hub/_jobs_api.pyr   r      s3        	 	 IHEGGGGr   r   c                   0    e Zd ZU eed<   ee         ed<   dS )	JobStatusstagemessageN)r   r   r   r   __annotations__r	   strr   r   r   r   r   -   s+         OOOc]r   r   c                   .    e Zd ZU eed<   eed<   eed<   dS )JobOwneridnametypeN)r   r   r   r!   r    r   r   r   r#   r#   3   s+         GGG
III
IIIIIr   r#   c                   6   e Zd ZU dZeed<   ee         ed<   ee         ed<   ee         ed<   eee                  ed<   eee                  ed<   ee	ee
f                  ed<   ee	ee
f                  ed	<   ee         ed
<   eed<   eed<   eed<   eed<   ddZdS )JobInfoa&	  
    Contains information about a Job.

    Args:
        id (`str`):
            Job ID.
        created_at (`datetime` or `None`):
            When the Job was created.
        docker_image (`str` or `None`):
            The Docker image from Docker Hub used for the Job.
            Can be None if space_id is present instead.
        space_id (`str` or `None`):
            The Docker image from Hugging Face Spaces used for the Job.
            Can be None if docker_image is present instead.
        command (`List[str]` or `None`):
            Command of the Job, e.g. `["python", "-c", "print('hello world')"]`
        arguments (`List[str]` or `None`):
            Arguments passed to the command
        environment (`Dict[str]` or `None`):
            Environment variables of the Job as a dictionary.
        secrets (`Dict[str]` or `None`):
            Secret environment variables of the Job (encrypted).
        flavor (`str` or `None`):
            Flavor for the hardware, as in Hugging Face Spaces. See [`SpaceHardware`] for possible values.
            E.g. `"cpu-basic"`.
        status: (`JobStatus` or `None`):
            Status of the Job, e.g. `JobStatus(stage="RUNNING", message=None)`
            See [`JobStage`] for possible stage values.
        owner: (`JobOwner` or `None`):
            Owner of the Job, e.g. `JobOwner(id="5e9ecfc04957053f60648a3e", name="lhoestq", type="user")`

    Example:

    ```python
    >>> from huggingface_hub import run_job
    >>> job = run_job(
    ...     image="python:3.12",
    ...     command=["python", "-c", "print('Hello from the cloud!')"]
    ... )
    >>> job
    JobInfo(id='687fb701029421ae5549d998', created_at=datetime.datetime(2025, 7, 22, 16, 6, 25, 79000, tzinfo=datetime.timezone.utc), docker_image='python:3.12', space_id=None, command=['python', '-c', "print('Hello from the cloud!')"], arguments=[], environment={}, secrets={}, flavor='cpu-basic', status=JobStatus(stage='RUNNING', message=None), owner=JobOwner(id='5e9ecfc04957053f60648a3e', name='lhoestq', type='user'), endpoint='https://huggingface.co', url='https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998')
    >>> job.id
    '687fb701029421ae5549d998'
    >>> job.url
    'https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998'
    >>> job.status.stage
    'RUNNING'
    ```
    r$   
created_atdocker_imagespace_idcommand	argumentsenvironmentsecretsflavorstatusownerendpointurlreturnNc                    |d         | _         |                    d          p|                    d          }|rt          |          nd | _        |                    d          p|                    d          | _        |                    d          p|                    d          | _        |                    di           }t          |d         |d	         |d
                   | _        |                    d          | _        |                    d          | _	        |                    d          | _
        |                    d          | _        |                    d          | _        |                    di           }t          |d         |                    d                    | _        |                    dt          j                  | _        | j         d| j        j         d| j          | _        d S )Nr$   	createdAtr)   dockerImager*   spaceIdr+   r2   r%   r&   r$   r%   r&   r,   r-   r.   r/   r0   r1   r   r   )r   r   r3   z/jobs//)r$   getr   r)   r*   r+   r#   r2   r,   r-   r.   r/   r0   r   r1   r   ENDPOINTr3   r%   r4   )selfkwargsr)   r2   r1   s        r   __init__zJobInfo.__init__~   s   ,ZZ,,H

<0H0H
8BL.444"JJ}55SN9S9S

9--GJ1G1G

7B''t5=uV}UUU
zz),,K00!::m44zz),,jj**Hb))fWovzz)?T?TUUU 

:y/ABBmFF4:?FFTWFFr   r5   N)r   r   r   r   r!   r    r	   r   r   r   r   r   r   r#   r@   r   r   r   r(   r(   :   s        0 0d 	GGG""""3-smd3i    S	""""$sCx.))))d38n%%%%]####OOO MMM	HHHG G G G G Gr   r(   c                   8   e Zd ZU ee         ed<   ee         ed<   eee                  ed<   eee                  ed<   eeeef                  ed<   eeeef                  ed<   ee	         ed<   ee
         ed<   eee                  ed	<   ee         ed
<   ddZdS )JobSpecr*   r+   r,   r-   r.   r/   r0   timeouttagsarchr5   Nc                 b   |                     d          p|                     d          | _        |                     d          p|                     d          | _        |                     d          | _        |                     d          | _        |                     d          | _        |                     d          | _        |                     d	          | _        |                     d
          | _        |                     d          | _	        |                     d          | _
        d S )Nr8   r*   r9   r+   r,   r-   r.   r/   r0   rD   rE   rF   )r<   r*   r+   r,   r-   r.   r/   r0   rD   rE   rF   r>   r?   s     r   r@   zJobSpec.__init__   s    "JJ}55SN9S9S

9--GJ1G1Gzz),,K00!::m44zz),,jj**zz),,JJv&&	JJv&&			r   rA   )r   r   r   r	   r!   r    r   r   r   r   intr@   r   r   r   rC   rC      s         3-smd3i    S	""""$sCx.))))d38n%%%%]####c]
49

3-
' 
' 
' 
' 
' 
'r   rC   c                   ,    e Zd ZU eed<   eed<   ddZdS )LastJobInfor$   atr5   Nc                 T    |d         | _         t          |d                   | _        d S )Nr$   rL   )r$   r   rL   rH   s     r   r@   zLastJobInfo.__init__   s$    , ..r   rA   )r   r   r   r!   r    r   r@   r   r   r   rK   rK      s<         GGGLLL/ / / / / /r   rK   c                   D    e Zd ZU ee         ed<   ee         ed<   ddZdS )ScheduledJobStatuslast_jobnext_job_run_atr5   Nc                 "   |                     d          p|                     d          }|rt          di |nd | _        |                     d          p|                     d          }|rt          t	          |                    nd | _        d S )NlastJobrP   nextJobRunAtrQ   r   )r<   rK   rP   r   r!   rQ   )r>   r?   rP   rQ   s       r   r@   zScheduledJobStatus.__init__   s    ::i((BFJJz,B,B3;E//h/// **^44U

CT8U8UGV`~c/.B.BCCC\`r   rA   )r   r   r   r	   rK   r    r   r@   r   r   r   rO   rO      sR         {####h''''a a a a a ar   rO   c                       e Zd ZU dZeed<   ee         ed<   eed<   ee         ed<   ee	         ed<   ee	         ed<   e
ed<   eed	<   ddZdS )ScheduledJobInfoa  
    Contains information about a Job.

    Args:
        id (`str`):
            Scheduled Job ID.
        created_at (`datetime` or `None`):
            When the scheduled Job was created.
        tags (`List[str]` or `None`):
            The tags of the scheduled Job.
        schedule (`str` or `None`):
            One of "@annually", "@yearly", "@monthly", "@weekly", "@daily", "@hourly", or a
            CRON schedule expression (e.g., '0 9 * * 1' for 9 AM every Monday).
        suspend (`bool` or `None`):
            Whether the scheduled job is suspended (paused).
        concurrency (`bool` or `None`):
            Whether multiple instances of this Job can run concurrently.
        status (`ScheduledJobStatus` or `None`):
            Status of the scheduled Job.
        owner: (`JobOwner` or `None`):
            Owner of the scheduled Job, e.g. `JobOwner(id="5e9ecfc04957053f60648a3e", name="lhoestq", type="user")`
        job_spec: (`JobSpec` or `None`):
            Specifications of the Job.

    Example:

    ```python
    >>> from huggingface_hub import run_job
    >>> scheduled_job = create_scheduled_job(
    ...     image="python:3.12",
    ...     command=["python", "-c", "print('Hello from the cloud!')"],
    ...     schedule="@hourly",
    ... )
    >>> scheduled_job.id
    '687fb701029421ae5549d999'
    >>> scheduled_job.status.next_job_run_at
    datetime.datetime(2025, 7, 22, 17, 6, 25, 79000, tzinfo=datetime.timezone.utc)
    ```
    r$   r)   job_specschedulesuspendconcurrencyr1   r2   r5   Nc                 *   |d         | _         |                    d          p|                    d          }|rt          |          nd | _        t	          di |                    d          p|                    di           | _        |                    d          | _        |                    d          | _        |                    d          | _        |                    d	i           }t          |                    d
          p|                    d          |                    d          p|                    d                    | _
        |                    di           }t          |d         |d         |d                   | _        d S )Nr$   r7   r)   rW   jobSpecrX   rY   rZ   r1   rP   rS   rQ   rT   )rP   rQ   r2   r%   r&   r:   r   )r$   r<   r   r)   rC   rW   rX   rY   rZ   rO   r1   r#   r2   )r>   r?   r)   r1   r2   s        r   r@   zScheduledJobInfo.__init__   s\   ,ZZ,,H

<0H0H
8BL.444XX6::j#9#9#VVZZ	SU=V=VXX

:..zz),,!::m44Hb))(ZZ
++Dvzz)/D/D"JJ'899WVZZ=W=W
 
 
 

7B''t5=uV}UUU


r   rA   )r   r   r   r   r!   r    r	   r   rC   boolrO   r#   r@   r   r   r   rV   rV      s         & &P 	GGG""""smd^$OOOV V V V V Vr   rV   imager,   envr/   r0   rD   r5   c                    |g |pi |pt           j        d}|r||d<   |roddddd}t          |t                    rA|d         |v r7t	          t          |d d                   ||d                  z            |d	<   nt	          |          |d	<   d
D ]3}|                     |          r| t          |          d          |d<    n4| |d<   |S )N)r,   r-   r.   r0   r/      <   i  iQ )smhdtimeoutSeconds)zhttps://huggingface.co/spaces/zhttps://hf.co/spaces/zhuggingface.co/spaces/zhf.co/spaces/r9   r8   )r   	CPU_BASIC
isinstancer!   rI   float
startswithlen)	r^   r,   r_   r/   r0   rD   rW   time_units_factorsprefixs	            r   _create_job_specrp     s    yb3M3	   H  &% 6#$2DyIIgs## 	67I(I(I),U73B3<-@-@CUV]^`VaCb-b)c)cH%&&),WH%& 
( 
( F## 	"'F"6HYE	 #(Or   N)dataclassesr   r   enumr   typingr   r   r   r	   r
   huggingface_hubr   huggingface_hub._space_apir   huggingface_hub.utils._datetimer   r!   r   r   r#   r(   rC   rK   rO   rV   rI   rk   rp   r   r   r   <module>rw      s   " ! ! ! ! !             3 3 3 3 3 3 3 3 3 3 3 3 3 3 % % % % % % 4 4 4 4 4 4 : : : : : :    sD   (        
         UG UG UG UG UG UG UG UGp ' ' ' ' ' ' ' '2 / / / / / / / / a a a a a a a a @V @V @V @V @V @V @V @VF&& #Y& 
$sCx.	!	&
 d38n%& ]#& eCO,-& 
#s(^& & & & & &r   