
    5pj\                        S SK r S SKrS SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S S	KJr   " S
 S\\5      r " S S\\5      r\R*                  \R,                  \R.                  \R0                  4rSr\ " S S5      5       r\ " S S5      5       r\ " S S5      5       r\ " S S5      5       r\ " S S5      5       r\ " S S5      5       r \ " S S5      5       r!\ " S S5      5       r"\ " S S 5      5       r#\ " S! S"5      5       r$\ " S# S$5      5       r%S%\\	-  S&\4S' jr&S(\S&\4S) jr'S*\(\   S&\4S+ jr)S,\S-\(\   S&\4S. jr*S/\S0\(\   S&\4S1 jr+SSSSS2SS3.S,\S-\(\   S4\,\\4   S-  S5\,\\4   S-  S6\\-  S-  S7\-\.-  \-  S-  S(\S-  S8\,\\4   S-  S9\(\   S-  S:\(\-   S-  S;\/S<\S-  S&\,\\4   4S= jjr0g)>    N)	dataclass)datetime)Enum)Path)Any)	constants)Volume)parse_datetimec                       \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrg)JobHardware   z
Enumeration of hardware flavors available to run Jobs on the Hub.

Value can be compared to a string:
```py
assert JobHardware.CPU_BASIC == "cpu-basic"
```

Both enums are kept in sync with the Hub API by `utils/check_hardware_flavors.py`.
z	cpu-basiczcpu-upgradezcpu-performancezcpu-xlzt4-smallz	t4-mediuml4x1l4x4l40sx1l40sx4l40sx8z
a10g-smallz
a10g-largeza10g-largex2za10g-largex4z
a100-largea100x4a100x8h200h200x2h200x4h200x8zrtx-pro-6000zrtx-pro-6000x2zrtx-pro-6000x4zrtx-pro-6000x8 N) __name__
__module____qualname____firstlineno____doc__	CPU_BASICCPU_UPGRADECPU_PERFORMANCECPU_XLT4_SMALL	T4_MEDIUML4X1L4X4L40SX1L40SX4L40SX8
A10G_SMALL
A10G_LARGEA10G_LARGEX2A10G_LARGEX4
A100_LARGEA100X4A100X8H200H200X2H200X4H200X8RTX_PRO_6000RTX_PRO_6000X2RTX_PRO_6000X4RTX_PRO_6000X8__static_attributes__r       U/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/_jobs_api.pyr   r      s    	 IK'OF HIDDFFFJJ!L!LJFFDFFF!L%N%N%Nr:   r   c                   0    \ rS rSrSrSrSrSrSrSr	Sr
S	rg
)JobStageG   aV  
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`, `SCHEDULING`, `RUNNING`.
Taken from https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (private url).
	COMPLETEDCANCELEDERRORDELETED
SCHEDULINGRUNNINGr   N)r   r   r   r   r   r?   r@   rA   rB   rC   rD   r9   r   r:   r;   r=   r=   G   s'    	 IHEGJGr:   r=   )zhttps://huggingface.co/spaces/zhttps://hf.co/spaces/zhuggingface.co/spaces/zhf.co/spaces/c                   V    \ rS rSr% \\S'   \S-  \S'   \\   S-  \S'   \S-  \S'   Srg)	JobStatush   stageNmessageexpose_urlsssh_urlr   )	r   r   r   r   r=   __annotations__strlistr9   r   r:   r;   rF   rF   h   s*    O4ZcT!!4Zr:   rF   c                   4    \ rS rSr% \\S'   \\S'   \\S'   Srg)JobOwnerp   idnametyper   N)r   r   r   r   rM   rL   r9   r   r:   r;   rP   rP   p   s    G
I
Ir:   rP   c                   T    \ rS rSr% Sr\S-  \S'   \S-  \S'   \S-  \S'   S	S jrSrg)
JobDurationsw   aE  
Timing breakdown for a Job, computed server-side.

Args:
    scheduling_secs (`int` or `None`):
        Seconds the job spent in the scheduling stage before starting to run.
        `None` if the job never reached the running stage.
    running_secs (`int` or `None`):
        Seconds the job has been or was running. Recomputed on each request
        while the job is in progress. `None` if the job never started running.
    total_secs (`int` or `None`):
        Total seconds elapsed since the job was created. Recomputed on each
        request while the job is in progress.
Nscheduling_secsrunning_secs
total_secsc                     UR                  SUR                  S5      5      U l        UR                  SUR                  S5      5      U l        UR                  SUR                  S5      5      U l        g )NschedulingSecsrX   runningSecsrY   	totalSecsrZ   )getrX   rY   rZ   selfkwargss     r;   __init__JobDurations.__init__   sW    %zz*:FJJGX<YZ"JJ}fjj6PQ **[&**\2JKr:   )rY   rX   rZ   returnN)	r   r   r   r   r   intrL   rc   r9   r   r:   r;   rV   rV   w   s-     4Z*d
Lr:   rV   c                   B    \ rS rSr% Sr\\S'   \\S'   Sr\S-  \S'   Srg)JobInitiator   a2  
Contains information about what triggered a Job.

Args:
    type (`str`): Initiator kind, for example `"user"`, `"org"`, `"scheduled-job"`, or `"duplicated-job"`.
    id (`str`): Identifier of the initiator.
    name (`str` or `None`): Human-readable name when available, usually for user/org initiators.
rT   rR   NrS   r   )	r   r   r   r   r   rM   rL   rS   r9   r   r:   r;   ri   ri      s!     IGD#*r:   ri   c                   f   \ rS rSr% Sr\\S'   \S-  \S'   \S-  \S'   \S-  \S'   \S-  \S'   \S-  \S	'   \\   S-  \S
'   \\   S-  \S'   \	\\
4   S-  \S'   \	\\
4   S-  \S'   \S-  \S'   \	\\4   S-  \S'   \\   S-  \S'   \\S'   \S-  \S'   \\S'   \S-  \S'   \\S'   \\S'   SS jrSrg)JobInfo   a  
Contains information about a Job.

Args:
    id (`str`):
        Job ID.
    created_at (`datetime` or `None`):
        When the Job was created.
    started_at (`datetime` or `None`):
        When the Job started running. None while the Job is still scheduling.
    finished_at (`datetime` or `None`):
        When the Job finished. None while the Job is still scheduling or running.
    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. See [`JobHardware`] for possible values.
        E.g. `"cpu-basic"`.
    labels (`dict[str, str]` or `None`):
        Labels to attach to the job (key-value pairs).
    volumes (`list[Volume]` or `None`):
        Volumes mounted in the job container (buckets, models, datasets, spaces).
    status: (`JobStatus` or `None`):
        Status of the Job, e.g. `JobStatus(stage="RUNNING", message=None)`
        See [`JobStage`] for possible stage values.
    durations (`JobDurations` or `None`):
        Timing breakdown of the Job. Present for all job states including SCHEDULING.
    owner: (`JobOwner` or `None`):
        Owner of the Job, e.g. `JobOwner(id="5e9ecfc04957053f60648a3e", name="lhoestq", type="user")`
    initiator (`JobInitiator` or `None`):
        What triggered the Job, e.g. `JobInitiator(type="scheduled-job", id="...")` for a cron-triggered run.
    expose_urls (`list[str]` or `None`):
        Public URLs through which the Job's exposed ports are reachable (one per port exposed via `expose=`),
        e.g. `["https://687fb701029421ae5549d998--8000.hf.jobs"]`. `None` when no port is exposed.
        Accessing a URL requires an HF token with read access to the Job's namespace.
    ssh_url (`str` or `None`):
        SSH endpoint of the Job, e.g. `"ssh://687fb701029421ae5549d998@ssh.hf.jobs"`. Only present when the Job
        was started with `ssh=True`. Connecting requires write access to the Job's namespace and an SSH public
        key registered on the Hub (https://huggingface.co/settings/keys).

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), started_at=datetime.datetime(2025, 7, 22, 16, 6, 31, 79000, tzinfo=datetime.timezone.utc), finished_at=None, docker_image='python:3.12', space_id=None, command=['python', '-c', "print('Hello from the cloud!')"], arguments=[], environment={}, secrets={}, flavor='cpu-basic', labels=None, status=JobStatus(stage='RUNNING', message=None), durations=JobDurations(scheduling_secs=6, running_secs=2, total_secs=8), owner=JobOwner(id='5e9ecfc04957053f60648a3e', name='lhoestq', type='user'), initiator=JobInitiator(type='user', id='5e9ecfc04957053f60648a3e', name='lhoestq'), 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'
```
rR   N
created_at
started_atfinished_atdocker_imagespace_idcommand	argumentsenvironmentsecretsflavorlabelsvolumesstatus	durationsowner	initiatorendpointurlc                 j   US   U l         UR                  S5      =(       d    UR                  S5      nU(       a  [        U5      OS U l        UR                  S5      =(       d    UR                  S5      nU(       a  [        U5      OS U l        UR                  S5      =(       d    UR                  S5      nU(       a  [        U5      OS U l        UR                  S5      =(       d    UR                  S	5      U l        UR                  S
5      =(       d    UR                  S5      U l        UR                  S0 5      n[        US   US   US   S9U l	        UR                  S5      U l
        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        UR                  S5      nU(       a  U Vs/ s H  n[!        S#0 UD6PM     snOS U l        UR                  S0 5      n[%        US   UR                  S5      UR                  S5      UR                  S5      S9U l        UR                  S5      n	U	(       a  [)        S#0 U	D6OS U l        UR                  S5      n
U
(       a   [-        U
S   U
S   U
R                  S5      S9OS U l        UR                  S [0        R2                  5      U l        U R4                   S!U R                  R6                   S"U R                    3U l        g s  snf )$NrR   	createdAtrn   	startedAtro   
finishedAtrp   dockerImagerq   spaceIdrr   r|   rS   rT   rR   rS   rT   rs   rt   ru   rv   rw   rx   ry   rz   rH   rI   
exposeUrlssshUrl)rH   rI   rJ   rK   r{   r}   )rT   rR   rS   r~   z/jobs//r   )rR   r_   r
   rn   ro   rp   rq   rr   rP   r|   rs   rt   ru   rv   rw   rx   r	   ry   rF   rz   rV   r{   ri   r}   r   ENDPOINTr~   rS   r   )ra   rb   rn   ro   rp   r|   ry   vrz   r{   r}   s              r;   rc   JobInfo.__init__   su   ,ZZ,H

<0H
8B.4ZZ,H

<0H
8B.4jj.K&**]2K:E>+64"JJ}5SN9S

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

7B't5=uV}U
zz),K0!::m4zz),jj*jj***Y'9@W5WW5dHb)/JJy)

<0JJx(	
 JJ{+	6?2	2TJJ{+	dmLi/IdO)--X^J_`sw 	
 

:y/A/ABmm_F4::??*;1TWWIF# 6s   8L0)rt   rs   rn   rq   r{   r~   ru   rp   rw   rR   r}   rx   r|   rv   rr   ro   rz   r   ry   re   )r   r   r   r   r   rM   rL   r   rN   dictr   r   r	   rF   rV   rP   ri   rc   r9   r   r:   r;   rl   rl      s    DL 	G44D *Dj#YCy4c3h$&&#s(^d""$cNT!!&\D  d""Od"" M	H$Gr:   rl   c                      \ rS rSr% \S-  \S'   \S-  \S'   \\   S-  \S'   \\   S-  \S'   \\\4   S-  \S'   \\\4   S-  \S'   \	S-  \S	'   \
S-  \S
'   \\   S-  \S'   \S-  \S'   \\\4   S-  \S'   \\   S-  \S'   SS jrSrg)JobSpeci'  Nrq   rr   rs   rt   ru   rv   rw   timeouttagsarchrx   ry   c                    UR                  S5      =(       d    UR                  S5      U l        UR                  S5      =(       d    UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        UR                  S	5      U l        UR                  S
5      U l        UR                  S5      U l	        UR                  S5      U l
        UR                  S5      U l        UR                  S5      nU(       a"  U Vs/ s H  n[        S0 UD6PM     snU l        g S U l        g s  snf )Nr   rq   r   rr   rs   rt   ru   rv   rw   r   r   r   rx   ry   r   )r_   rq   rr   rs   rt   ru   rv   rw   r   r   r   rx   r	   ry   )ra   rb   ry   r   s       r;   rc   JobSpec.__init__6  s   "JJ}5SN9S

9-GJ1Gzz),K0!::m4zz),jj*zz),JJv&	JJv&	jj***Y'9@W5WW5d5s   ?E%)r   rt   rs   rq   ru   rw   rx   rv   rr   r   r   ry   re   )r   r   r   r   rM   rL   rN   r   r   r   rg   r	   rc   r9   r   r:   r;   r   r   '  s    *Dj#YCy4c3h$&&#s(^d""$4Z
s)d

*cNT!!&\D  Kr:   r   c                   4    \ rS rSr% \\S'   \\S'   SS jrSrg)LastJobInfoiF  rR   atNc                 >    US   U l         [        US   5      U l        g )NrR   r   )rR   r
   r   r`   s     r;   rc   LastJobInfo.__init__K  s    , .r:   )r   rR   re   )	r   r   r   r   rM   rL   r   rc   r9   r   r:   r;   r   r   F  s    GL/r:   r   c                   @    \ rS rSr% \S-  \S'   \S-  \S'   SS jrSrg)ScheduledJobStatusiP  Nlast_jobnext_job_run_atc                 *   UR                  S5      =(       d    UR                  S5      nU(       a  [        S0 UD6OS U l        UR                  S5      =(       d    UR                  S5      nU(       a  [        [	        U5      5      U l        g S U l        g )NlastJobr   nextJobRunAtr   r   )r_   r   r   r
   rM   r   )ra   rb   r   r   s       r;   rc   ScheduledJobStatus.__init__U  sj    ::i(BFJJz,B3;/h/ **^4U

CT8UGV~c/.BC\`r:   r   r   re   )	r   r   r   r   r   rL   r   rc   r9   r   r:   r;   r   r   P  s    D  _$ar:   r   c                       \ rS rSr% Sr\\S'   \S-  \S'   \\S'   \S-  \S'   \	S-  \S'   \	S-  \S	'   \
\S
'   \\S'   SS jrSrg)ScheduledJobInfoi\  a9  
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)
```
rR   Nrn   job_specschedulesuspendconcurrencyrz   r|   c                    US   U l         UR                  S5      =(       d    UR                  S5      nU(       a  [        U5      OS U l        [	        S0 UR                  S5      =(       d    UR                  S0 5      D6U l        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        UR                  S	0 5      n[        UR                  S
5      =(       d    UR                  S5      UR                  S5      =(       d    UR                  S5      S9U l
        UR                  S0 5      n[        US   US   US   S9U l        g )NrR   r   rn   r   jobSpecr   r   r   rz   r   r   r   r   r   r|   rS   rT   r   r   )rR   r_   r
   rn   r   r   r   r   r   r   rz   rP   r|   )ra   rb   rn   rz   r|   s        r;   rc   ScheduledJobInfo.__init__  s   ,ZZ,H

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

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

7B't5=uV}U
r:   )r   rn   rR   r   r|   r   rz   r   re   )r   r   r   r   r   rM   rL   r   r   boolr   rP   rc   r9   r   r:   r;   r   r   \  sN    &P 	G4DjD[OVr:   r   c                   V    \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \\S'   SS	 jrS
rg)JobAcceleratori  a  
Contains information about a Job accelerator (GPU).

Args:
    type (`str`):
        Type of accelerator, e.g. `"gpu"`.
    model (`str`):
        Model of accelerator, e.g. `"T4"`, `"A10G"`, `"A100"`, `"L4"`, `"L40S"`.
    quantity (`str`):
        Number of accelerators, e.g. `"1"`, `"2"`, `"4"`, `"8"`.
    vram (`str`):
        Total VRAM, e.g. `"16 GB"`, `"24 GB"`.
    manufacturer (`str`):
        Manufacturer of the accelerator, e.g. `"Nvidia"`.
rT   modelquantityvrammanufacturerNc                 h    US   U l         US   U l        US   U l        US   U l        US   U l        g )NrT   r   r   r   r   )rT   r   r   r   r   r`   s     r;   rc   JobAccelerator.__init__  s<    6N	G_
z*6N	">2r:   )r   r   r   rT   r   re   )	r   r   r   r   r   rM   rL   rc   r9   r   r:   r;   r   r     s(      IJM
I3r:   r   c                       \ rS rSr% Sr\\S'   \\S'   \\S'   \\S'   \\S'   \S-  \S	'   \\S
'   \	\S'   \\S'   SS jr
Srg)JobHardwareInfoi  a  
Contains information about available Job hardware.

Args:
    name (`str`):
        Machine identifier, e.g. `"cpu-basic"`, `"a10g-large"`.
    pretty_name (`str`):
        Human-readable name, e.g. `"CPU Basic"`, `"Nvidia A10G - large"`.
    cpu (`str`):
        CPU specification, e.g. `"2 vCPU"`, `"12 vCPU"`.
    ram (`str`):
        RAM specification, e.g. `"16 GB"`, `"46 GB"`.
    ephemeral_storage (`str`):
        Ephemeral storage specification, e.g. `"20 GB"`, `"100 GB"`.
    accelerator (`JobAccelerator` or `None`):
        GPU/accelerator details if available.
    unit_cost_micro_usd (`int`):
        Cost in micro-dollars per unit, e.g. `167` (= $0.000167).
    unit_cost_usd (`float`):
        Cost in USD per unit, e.g. `0.000167`.
    unit_label (`str`):
        Cost unit period, e.g. `"minute"`.

Example:

```python
>>> from huggingface_hub import list_jobs_hardware
>>> hardware_list = list_jobs_hardware()
>>> hardware_list[0]
JobHardwareInfo(name='cpu-basic', pretty_name='CPU Basic', cpu='2 vCPU', ram='16 GB', ephemeral_storage='20 GB', accelerator=None, unit_cost_micro_usd=167, unit_cost_usd=0.000167, unit_label='minute')
>>> hardware_list[0].name
'cpu-basic'
```
rS   pretty_namecpuramephemeral_storageNacceleratorunit_cost_micro_usdunit_cost_usd
unit_labelc                    US   U l         US   U l        US   U l        US   U l        UR	                  SS5      U l        UR	                  S5      nU(       a  [        S0 UD6OS U l        US   U l        US	   U l	        US
   U l
        g )NrS   
prettyNamer   r   ephemeralStoragezN/Ar   unitCostMicroUSDunitCostUSD	unitLabelr   )rS   r   r   r   r_   r   r   r   r   r   r   )ra   rb   r   s      r;   rc   JobHardwareInfo.__init__  s    6N	!,/%=%=!',>!Fjj/<G>8K8T#)*<#= #M2 -r:   )	r   r   r   rS   r   r   r   r   r   re   )r   r   r   r   r   rM   rL   r   rg   floatrc   r9   r   r:   r;   r   r     sF    !F I	H	H$&&O
.r:   r   sourcerf   c                 B   [        U 5      R                  5       R                  5       n[        R                  " [
        R                  " 5        SU 3R                  5       5      R                  5       SS nUR                  R                  SS5      =(       d    SnU SU 3$ )a  Derive a stable remote folder name for a local directory synced as a Job volume.

The name is `{dirname}-{hash}` where the hash fingerprints the absolute path and the machine's
hostname: re-syncing the same directory from the same machine reuses the same remote folder
(so only changed files are re-uploaded), while same-named directories from different paths or
machines don't collide.
:N    _root-)r   
expanduserresolvehashlibsha256platformnodeencode	hexdigestrS   replace)r   resolveddigestdirnames       r;   _derive_job_volume_namer     s     F|&&(002H^^x}}/q
;BBDEOOQRTSTUFmm##C-7GYax  r:   rS   c                 2    [         R                  " SSU 5      $ )zSanitize a string so it is a valid Job `name` label.

Job names must match `^[a-zA-Z0-9._-]*$` and are also stored as tags, which only allow
alphanumerics, `-` and `_`. Every other character (including `/`, `:` and `.`) is replaced with `-`.
z[^a-zA-Z0-9_-]r   )resub)rS   s    r;   _sanitize_job_namer   
  s     66#S$//r:   partsc                     [         R                  " SR                  U 5      R                  5       5      R	                  5       SS $ )zShort, stable hash of a Job invocation (image/script + command line).

Appended to auto-generated names so reruns of the same command share a name while different ones don't.
 Nr   )r   r   joinr   r   )r   s    r;   _short_invocation_hashr     s5    
 >>&++e,3356@@B2AFFr:   imagers   c                    [          H;  nU R                  U5      (       d  M  [        U [        U5      S =(       d    U 5      n  O7   [        U R	                  S5      R                  S5      S   =(       d    U 5      nU S[        U /UQ5       3$ )a  Derive a default Job name from a Docker image or Space reference and its command.

A short hash of the full command line is appended to group reruns of the same command.
e.g. python:3.12 + [foo, --truc]             -> python-3-12-1a2b3c4d
     hf.co/spaces/lhoestq/duckdb             -> lhoestq-duckdb-<hash>
     pytorch/pytorch:2.6.0-cuda12.4-...      -> pytorch-2-6-0-cuda12-4-...-<hash>
Nr   r   )_SPACE_IMAGE_PREFIXES
startswithr   lenrstripsplitr   )r   rs   prefixbases       r;   _default_job_name_from_imager     s     (F##%eCKM&:&CeDD (
 "%,,s"3"9"9#">r"B"KeLV1+U,=W,=>?@@r:   scriptscript_argsc                 ,   U R                  SS5      S   R                  SS5      S   R                  S5      R                  S5      S   nUR                  S5      (       a  US[        S5      *  n[	        U=(       d    U 5      nU S	[        U /UQ5       3$ )
aM  Derive a default Job name from a UV script path, URL, or command and its arguments.

A short hash of the full command line is appended to group reruns of the same command.
e.g. my_script.py + [--epochs, 3]  -> my_script-1a2b3c4d
     https://.../sft.py?raw=1      -> sft-<hash>
     lighteval                     -> lighteval-<hash>
?   r   #r   r   z.pyNr   )r   r   endswithr   r   r   )r   r   rS   r   s       r;   _default_job_name_from_scriptr   ,  s     <<Q"((a03::3?EEcJ2ND}}UMs5zk"dnf-DV1+V,Bk,BCDEEr:   F)rS   rx   ry   exposesshresource_group_idenvrv   rw   r   rx   ry   r   r   r   c                    Ub%  Ub  SU;   a  [        S5      e0 U=(       d    0 ESU0EnU/ U=(       d    0 U=(       d    [        R                  S.nU(       a  X<S'   U(       aV  SSSSS	.n[        U[        5      (       a,  US
   U;   a#  [        [        US S
 5      XS
      -  5      US'   O[        U5      US'   U(       a  X|S'   U(       a#  U Vs/ s H  oR                  5       PM     snUS'   U	(       a  SU	0US'   U
(       a  SS0US'   U(       a  XS'   [         H-  nU R                  U5      (       d  M  U [        U5      S  US'     U$    XS'   U$ s  snf )NrS   z>`name` and the `name` key in `labels` cannot both be provided.)rs   rt   ru   rw   rv   r   <   i  iQ )smhdr   timeoutSecondsrx   ry   portsr   enabledTr   resourceGroupIdr   r   )
ValueErrorr   r   
isinstancerM   rg   r   to_dictr   r   r   )r   rs   r   rv   rw   r   rS   rx   ry   r   r   r   r   time_units_factorsvolr   s                   r;   _create_job_specr  ;  sv    &F"2]^^1V\r1FD1 yb1K11	 H %#$2DyIgs##7I(I),U73B<-@CU^`VaCb-b)cH%&),WH%&#8?@{{}@%v.
$d+&7"#'F##"'F"6HY O (
 #(O# As   E)1r   r   r   dataclassesr   r   enumr   pathlibr   typingr   huggingface_hubr   huggingface_hub._space_apir	   huggingface_hub.utils._datetimer
   rM   r   r=   r?   r@   rA   rB   TERMINAL_JOB_STAGESr   rF   rP   rV   ri   rl   r   r   r   r   r   r   r   r   rN   r   r   r   r   rg   r   r   r  r   r:   r;   <module>r     s%     	 !     % - :(&#t (&VsD ,  ))8+<+<hnnhN^N^_         L L L4    AG AG AGH K K K< / / / a a a @V @V @VF 3 3 3> 8. 8. 8.v!C$J !3 !0S 0S 0G$s) G GA Ad3i AC A"F# FDI F# F. $(#'#$(;; #Y; 
c3h$		;
 #s(^d"; #$; 5[3%; *; cNT!; &\D ; I; 
; Tz; 
#s(^;r:   