U
    di                     @   s  d Z ddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZmZmZmZ ddl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 eeZdd eD ZG dd deZG dd deZ G dd deZ!eeee"e#f   ee" e"dddZ$G dd deZ%G dd deZ&G dd deZ'G dd deZ(ee"e"f dd d!Z)G d"d# d#eZ*G d$d% d%eZ+G d&d' d'eZ,G d(d) d)eZ-G d*d+ d+eZ.G d,d- d-eZ/G d.d/ d/eZ0G d0d1 d1eZ1dS )2a  Contains commands to interact with jobs on the Hugging Face Hub.

Usage:
    # run a job
    hf jobs run <image> <command>

    # List running or completed jobs
    hf jobs ps [-a] [-f key=value] [--format TEMPLATE]

    # Stream logs from a job
    hf jobs logs <job-id>

    # Inspect detailed information about a job
    hf jobs inspect <job-id>

    # Cancel a running job
    hf jobs cancel <job-id>
    N)	Namespace_SubParsersActionasdict)Path)DictListOptionalUnion)HfApiSpaceHardware	get_token)logging)load_dotenv   )BaseHuggingfaceCLICommandc                 C   s   g | ]}|j d kr|j qS )z	zero-a10g)value).0item r   </tmp/pip-unpacked-wheel-ohruig0i/huggingface_hub/cli/jobs.py
<listcomp>4   s     
 r   c                   @   s   e Zd ZeedddZdS )JobsCommandsparserc                    sx   | j ddd  jdd} j fddd t| t| t| t| t| t	| t
| d S )NjobszRun and manage Jobs on the Hub.helpz$huggingface.co jobs related commandsc                    s      S N
print_helpargsZjobs_parserr   r   <lambda>>       z2JobsCommands.register_subcommand.<locals>.<lambda>func)
add_parseradd_subparsersset_defaultsInspectCommandregister_subcommandLogsCommand	PsCommand
RunCommandCancelCommand	UvCommandScheduledJobsCommands)r   Zjobs_subparsersr   r#   r   r,   8   s    





z JobsCommands.register_subcommandN__name__
__module____qualname__staticmethodr   r,   r   r   r   r   r   7   s   r   c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r/   Nr   returnc                 C   s   | j ddd}|jdtdd |jddd	d
d |jddd	dd |jdtdd |jdtdd |jdtddt dd |jdtdd |jddddd |jdtdd |jdtd d |jd!d"d#d$ |jtd% d S )&Nrunz	Run a Jobr   imageThe Docker image to use.typer   -e--envappend/Set environment variables. E.g. --env ENV=valueactionr   -s	--secretsvSet secret environment variables. E.g. --secrets SECRET=value or `--secrets HF_TOKEN` to pass your Hugging Face token.
--env-file(Read in a file of environment variables.--secrets-file/Read in a file of secret environment variables.--flavorTFlavor for the hardware, as in HF Spaces. Defaults to `cpu-basic`. Possible values: , .	--timeoutVMax duration: int/float with s (seconds, default), m (minutes), h (hours) or d (days).-d--detach
store_truez3Run the Job in the background and print the Job ID.--namespaceVThe namespace where the Job will be created. Defaults to the current user's namespace.--tokenIA User Access Token generated from https://huggingface.co/settings/tokenscommand...The command to run.nargsr   r&   )r(   add_argumentstrjoinSUGGESTED_FLAVORSr*   r/   r   
run_parserr   r   r   r,   K   sN    	zRunCommand.register_subcommandr"   r9   c                 C   s   |j | _ |j| _i | _|jr@| jtt|j tj	
 d |jpHg D ]}| jt|tj	
 d qJi | _t }|jr| jtt|j |d |jpg D ]}| jt||d q|j| _|j| _|j| _|j| _|j| _d S Nenviron)r;   rY   envenv_fileupdater   r   	read_textosrg   copysecrets_get_extended_environsecrets_fileflavortimeoutdetach	namespacetokenselfr"   Z	env_valueextended_environsecretr   r   r   __init__x   s$    $zRunCommand.__init__r9   c              	   C   s|   t | jd}|j| j| j| j| j| j| j| j	d}t
d|j  t
d|j  | jr\d S |j|jdD ]}t
| qjd S )Nru   )r;   rY   rh   rn   rq   rr   rt   Job started with ID: 	View at: job_id)r   ru   Zrun_jobr;   rY   rh   rn   rq   rr   rt   printidurlrs   fetch_job_logsrw   apijoblogr   r   r   r:      s     
zRunCommand.run	r4   r5   r6   r7   r   r,   r   rz   r:   r   r   r   r   r/   J   s   ,r/   c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r-   Nr8   c                 C   sN   | j ddd}|jdtdd |jdtdd |jd	td
d |jtd d S )NZlogszFetch the logs of a Jobr   r   Job IDr=   rU   QThe namespace where the job is running. Defaults to the current user's namespace.rW   rX   r&   )r(   r^   r_   r*   r-   rb   r   r   r   r,      s      zLogsCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   r   rt   ru   rw   r"   r   r   r   rz      s    zLogsCommand.__init__r{   c                 C   s0   t | jd}|j| j| jdD ]}t| qd S Nr|   r   rt   )r   ru   r   r   rt   r   )rw   r   r   r   r   r   r:      s    zLogsCommand.runr   r   r   r   r   r-      s   r-   )rowsheadersr9   c           	      C   s  dd t | |f D }tt jt|d }t|t| |kr|t|}||  d  < t|t| |kr0|t| t| ||  ||< q0dt| j| }g }|	|j|  |	|jdd |D   | D ](}dd t ||D }|	|j|  qd
|S )	z
    Inspired by:

    - stackoverflow.com/a/8356620/593036
    - stackoverflow.com/questions/9535954/printing-lists-as-tabular-data
    c                 S   s   g | ]}t d d |D qS )c                 s   s   | ]}t t|V  qd S r   lenr_   )r   xr   r   r   	<genexpr>   s     z'_tabulate.<locals>.<listcomp>.<genexpr>)max)r   colr   r   r   r      s     z_tabulate.<locals>.<listcomp>      z{{:{}}} c                 S   s   g | ]}d | qS )-r   )r   wr   r   r   r      s     c                 S   s@   g | ]8\}}t t||kr4t|d |d  d nt|qS )N   rZ   r   )r   r   Z	col_widthr   r   r   r      s   
)zipr   rl   get_terminal_sizecolumnsr   sumindexformatrA   r`   )	r   r   Z
col_widthsZterminal_widthZcol_to_minimizeZ
row_formatlinesrowZrow_format_argsr   r   r   	_tabulate   s"    "r   c                   @   s^   e Zd ZeeddddZeddddZddd	d
Ze	e
e
f edddZdd ZdS )r.   Nr8   c                 C   st   | j ddd}|jddddd |jd	td
d |jdtdd |jdddg dd |jdtdd |jtd d S )Npsz	List Jobsr   -a--allrT   z*Show all Jobs (default shows just running)rC   rU   UThe namespace from where it lists the jobs. Defaults to the current user's namespace.r=   rW   rX   -f--filterrA   >Filter output based on conditions provided (format: key=value)rD   defaultr   --format%Format output using a custom templater&   )r(   r^   r_   r*   r.   rb   r   r   r   r,      s<    zPsCommand.register_subcommandrd   c                 C   sn   |j | _ |j| _|j| _|j| _i | _|jD ]<}d|krX|dd\}}|| j| < q,td| d q,d S N=r   z)Warning: Ignoring invalid filter format 'z'. Use key=value format.	allrt   ru   r   filtersfiltersplitlowerr   rw   r"   fkeyr   r   r   r   rz      s    
zPsCommand.__init__r{   c              
   C   s  z"t | jd}|j| jd}dddddg}g }|D ]}|jrF|jjnd}| jsZ|d	krZq4|j}|jphd
}|j	prg }	|	rd
|	nd
}
|jr|jdnd
}||| |
d}| |sq4||||
||g q4|sd}| jrdd
dd | j D  }td|  W dS | || W n tjk
rX } ztd|  W 5 d}~X Y nt tttfk
r } ztd|  W 5 d}~X Y n> tk
r } ztdt|j d|  W 5 d}~X Y nX dS )z
        Fetch and display job information for the current user.
        Uses Docker-style filtering with -f/--filter flag and key=value pairs.
        r|   rt   zJOB IDIMAGE/SPACECOMMANDCREATEDZSTATUSUNKNOWN)ZRUNNINGZUPDATINGN/A %Y-%m-%d %H:%M:%S)r   r;   statusrY     matching filters: rN   c                 S   s   g | ]\}}| d | qS r   r   r   kvr   r   r   r   D  s     z!PsCommand.run.<locals>.<listcomp>zNo jobs foundNzError fetching jobs data: zError processing jobs data: Unexpected error - : )r   ru   Z	list_jobsrt   r   Zstager   r   docker_imagerY   r`   
created_atstrftimer   _matches_filtersrA   r   itemsr   _print_outputrequestsRequestExceptionKeyError
ValueError	TypeError	Exceptionr>   r4   )rw   r   r   table_headersr   r   r   r   image_or_spacerY   command_strr   job_propertiesfilters_msger   r   r   r:     sF    


 zPsCommand.runr   r9   c                 C   s   | j  D ]x\}}||kr  dS d|ks0d|krh|dddd}td| d|| tjs dS q
| ||  kr
 dS q
dS )	z+Check if job matches all specified filters.F*?.*rO   ^$Tr   r   replaceresearch
IGNORECASEr   rw   r   r   patternZregex_patternr   r   r   r   S  s    zPsCommand._matches_filtersc           	      C   s|   | j rh| j }|D ]T}|}tdddddgD ]0\}}d| d}||kr*||t|| }q*t| qntt||d d	S )
,Print output according to the chosen format.r   r;   rY   createdr   {{.}}r   Nr   	enumerater   r_   r   r   	rw   r   r   templater   lineifieldplaceholderr   r   r   r   f  s    zPsCommand._print_outputr4   r5   r6   r7   r   r,   r   rz   r:   r   r_   boolr   r   r   r   r   r   r.      s   "Hr.   c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r+   Nr8   c                 C   sN   | j ddd}|jdtdd |jdtdd |jd	d
dd |jtd d S )Ninspectz0Display detailed information on one or more Jobsr   rU   r   r=   rW   rX   job_idsrZ   zThe jobs to inspectr\   r&   )r(   r^   r_   r*   r+   rb   r   r   r   r,   }  s      z"InspectCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   )rt   ru   r   r   r   r   r   rz     s    zInspectCommand.__init__r{   c                    sD   t jd  fddjD }ttjdd |D dtd d S )Nr|   c                    s   g | ]} j |jd qS )r   )Zinspect_jobrt   )r   r   r   rw   r   r   r     s     z&InspectCommand.run.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   r   )r   r   r   r   r   r     s        indentr   )r   ru   r   r   jsondumpsr_   )rw   r   r   r   r   r:     s    zInspectCommand.runr   r   r   r   r   r+   |  s   r+   c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r0   Nr8   c                 C   sN   | j ddd}|jdtdd |jdtdd |jd	td
d |jtd d S )NcancelzCancel a Jobr   r   r   r=   rU   r   rW   rX   r&   )r(   r^   r_   r*   r0   rb   r   r   r   r,     s      z!CancelCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   r   r   r   r   r   rz     s    zCancelCommand.__init__r{   c                 C   s"   t | jd}|j| j| jd d S r   )r   ru   Z
cancel_jobr   rt   rw   r   r   r   r   r:     s    zCancelCommand.runr   r   r   r   r   r0     s   r0   c                   @   s:   e Zd ZdZedd ZeddddZddd	d
ZdS )r1   z.Run UV scripts on Hugging Face infrastructure.c                 C   sB  | j ddd}|jdddd}|j dd	d}|jd
dd |jdddg d |jdtdd |jddd |jdtddt dd |jddddd |jdddd d |jd!td"d |jd#td$d |jd%td&d |jd'd(d)d*d |jd+td,d |jd-td.d |jd/dd0d1d2 |jd3d4td5d |jtd6 d7S )8Register UV run subcommand.uvzERun UV scripts (Python with inline dependencies) on HF infrastructurer   
uv_commandUV commandsTdestr   requiredr:   8Run a UV script (local file or URL) on HF infrastructurescript$UV script to run (local file or URL)script_argsrZ   Arguments for the scriptr]   r   r   --image.Use a custom Docker image with `uv` installed.r=   --repoCRepository name for the script (creates ephemeral if not specified)rL   rM   rN   rO   r?   r@   rA   Environment variablesrC   rE   rF   rG   rH   rI   rJ   rK   rP    Max duration (e.g., 30s, 5m, 1h)rR   rS   rT   Run in backgroundrU   rV   rW   HF token--with%Run with the given packages installedwith_rD   r   r  -p--python5The Python interpreter to use for the run environmentr&   N)r(   r)   r^   r_   r`   ra   r*   r1   r   Z	uv_parserZ
subparsersrc   r   r   r   r,     sd    	   zUvCommand.register_subcommandNrd   c                 C   s
  |j | _ |j| _|j| _|j| _|j| _i | _|jrX| jt	t
|j tj d |jp`g D ]}| jt	|tj d qbi | _t }|jr| jt	t
|j |d |jpg D ]}| jt	||d q|j| _|j| _|j| _|j| _|j| _|j| _dS z-Initialize the command with parsed arguments.rf   N)r  r  r  dependenciespythonr;   rh   ri   rj   r   r   rk   rl   rg   rm   rn   ro   rp   rq   rr   rs   rt   ru   repo_reporv   r   r   r   rz     s,    $zUvCommand.__init__r{   c                 C   s   t t j t| jd}|j| j| j| j| j	| j
| j| j| j| j| j| jd}td|j  td|j  | jrxdS |j|jdD ]}t| qdS )zExecute UV command.r|   )r  r  r$  r%  r;   rh   rn   rq   rr   rt   r'  r}   r~   Nr   )r   set_verbosityINFOr   ru   Z
run_uv_jobr  r  r$  r%  r;   rh   rn   rq   rr   rt   r'  r   r   r   rs   r   r   r   r   r   r:     s*    zUvCommand.run	r4   r5   r6   __doc__r7   r,   r   rz   r:   r   r   r   r   r1     s
   
9r1   r{   c                  C   s$   t j } t  }d k	r || d< | S )NZHF_TOKEN)rl   rg   rm   r   )rx   ru   r   r   r   ro   #  s    
ro   c                   @   s   e Zd ZeedddZdS )r2   r   c                    sx   | j ddd}|jdd |j fddd t  t  t  t  t  t	  t
  d S )NZ	scheduledz,Create and manage scheduled Jobs on the Hub.r   z.huggingface.co scheduled jobs related commandsc                    s      S r   r   r!   Zscheduled_jobs_subparsersr   r   r$   3  r%   z;ScheduledJobsCommands.register_subcommand.<locals>.<lambda>r&   )r(   r)   r*   ScheduledRunCommandr,   ScheduledPsCommandScheduledInspectCommandScheduledDeleteCommandScheduledSuspendCommandScheduledResumeCommandScheduledUvCommand)r   Zscheduled_jobs_parserr   r,  r   r,   +  s    





z)ScheduledJobsCommands.register_subcommandNr3   r   r   r   r   r2   *  s   r2   c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r-  Nr8   c                 C   s  | j ddd}|jdtdd |jdtdd |jd	d
dd d |jdd
dd d |jddddd |jddddd |jdtdd |jdtdd |jdtddt dd |jdtd d |jd!td"d |jd#td$d |jd%d&d'd( |jtd) d S )*Nr:   zSchedule a Jobr   scheduleWOne of annually, yearly, monthly, weekly, daily, hourly, or a CRON schedule expression.r=   r;   r<   	--suspendrT   !Suspend (pause) the scheduled JobrD   r   r   --concurrency8Allow multiple instances of this Job to run concurrentlyr?   r@   rA   rB   rC   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rU   z`The namespace where the scheduled Job will be created. Defaults to the current user's namespace.rW   rX   rY   rZ   r[   r\   r&   )r(   r^   r_   r`   ra   r*   r-  rb   r   r   r   r,   @  sd    	z'ScheduledRunCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _|j| _|j| _i | _|jrX| jtt	|j
 tj d |jp`g D ]}| jt|tj d qbi | _t }|jr| jtt	|j
 |d |jpg D ]}| jt||d q|j| _|j| _|j| _|j| _d S re   )r4  r;   rY   suspendconcurrencyrh   ri   rj   r   r   rk   rl   rg   rm   rn   ro   rp   rq   rr   rt   ru   rv   r   r   r   rz   x  s(    $zScheduledRunCommand.__init__r{   c                 C   sR   t | jd}|j| j| j| j| j| j| j| j	| j
| j| jd
}td|j  d S )Nr|   )
r;   rY   r4  r;  r<  rh   rn   rq   rr   rt   Scheduled Job created with ID: )r   ru   Zcreate_scheduled_jobr;   rY   r4  r;  r<  rh   rn   rq   rr   rt   r   r   )rw   r   scheduled_jobr   r   r   r:     s    zScheduledRunCommand.runr   r   r   r   r   r-  ?  s   7r-  c                   @   s^   e Zd ZeeddddZeddddZddd	d
Ze	e
e
f edddZdd ZdS )r.  Nr8   c                 C   st   | j ddd}|jddddd |jd	td
d |jdtdd |jdddg dd |jdtdd |jtd d S )Nr   zList scheduled Jobsr   r   r   rT   z1Show all scheduled Jobs (default hides suspended)rC   rU   r   r=   rW   rX   r   r   rA   r   r   r   r   r&   )r(   r^   r_   r*   r.  rb   r   r   r   r,     s<    z&ScheduledPsCommand.register_subcommandrd   c                 C   sn   |j | _ |j| _|j| _|j| _i | _|jD ]<}d|krX|dd\}}|| j| < q,td| d q,d S r   r   r   r   r   r   rz     s    
zScheduledPsCommand.__init__r{   c              
   C   s  zDt | jd}|j| jd}ddddddd	g}g }|D ]}|j}| jsN|rNq8|j}|j}|jj	pdd
}	|jj
ppg }
|
rd|
nd
}|jjr|jjjdnd
}|jjr|jjdnd
}||	t||d}| |sq8||||	||||g q8|s8d}| jr$dddd | j D  }td|  W dS | || W n tjk
rz } ztd|  W 5 d}~X Y nt tttfk
r } ztd|  W 5 d}~X Y n> tk
r } ztdt|j d|  W 5 d}~X Y nX dS )z
        Fetch and display scheduked job information for the current user.
        Uses Docker-style filtering with -f/--filter flag and key=value pairs.
        r|   r   ZIDZSCHEDULEr   r   zLAST RUNzNEXT RUNZSUSPENDr   r   r   )r   r;   r;  rY   r   r   rN   c                 S   s   g | ]\}}| d | qS r   r   r   r   r   r   r   *  s     z*ScheduledPsCommand.run.<locals>.<listcomp>zNo scheduled jobs foundNz$Error fetching scheduled jobs data: z&Error processing scheduled jobs data: r   r   ) r   ru   Zlist_scheduled_jobsrt   r;  r   r   r4  Zjob_specr   rY   r`   r   Zlast_jobatr   next_job_run_atr_   r   rA   r   r   r   r   r   r   r   r   r   r   r>   r4   )rw   r   scheduled_jobsr   r   r>  r;  scheduled_job_idr4  r   rY   r   last_job_atr@  r   r   r   r   r   r   r:     sv    

 zScheduledPsCommand.runr   c                 C   s   | j  D ]x\}}||kr  dS d|ks0d|krh|dddd}td| d|| tjs dS q
| ||  kr
 dS q
dS )	z5Check if scheduled job matches all specified filters.Fr   r   r   rO   r   r   Tr   r   r   r   r   r   9  s    z#ScheduledPsCommand._matches_filtersc           	   	   C   s   | j rl| j }|D ]X}|}tdddddddgD ]0\}}d| d	}||kr.||t|| }q.t| qntt||d
 dS )r   r   r4  r;   rY   rC  r@  r;  r   r   r   Nr   r   r   r   r   r   L  s"    z ScheduledPsCommand._print_outputr   r   r   r   r   r.    s   "fr.  c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r/  Nr8   c                 C   sN   | j ddd}|jdtdd |jdtdd |jd	d
dd |jtd d S )Nr   z:Display detailed information on one or more scheduled Jobsr   rU   SThe namespace where the scheduled job is. Defaults to the current user's namespace.r=   rW   rX   scheduled_job_idsrZ   zThe scheduled jobs to inspectr\   r&   )r(   r^   r_   r*   r/  rb   r   r   r   r,   e  s      z+ScheduledInspectCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   )rt   ru   rE  r   r   r   r   rz   s  s    z ScheduledInspectCommand.__init__r{   c                    sD   t jd  fddjD }ttjdd |D dtd d S )Nr|   c                    s   g | ]} j |jd qS )rB  rt   )Zinspect_scheduled_jobrt   )r   rB  r   r   r   r   z  s   z/ScheduledInspectCommand.run.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   r   )r   r>  r   r   r   r   ~  s     r   r   )r   ru   rE  r   r  r  r_   )rw   rA  r   r   r   r:   x  s
    zScheduledInspectCommand.runr   r   r   r   r   r/  d  s   r/  c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r0  Nr8   c                 C   sN   | j ddd}|jdtdd |jdtdd |jd	td
d |jtd d S )NdeletezDelete a scheduled Jobr   rB  Scheduled Job IDr=   rU   rD  rW   rX   r&   )r(   r^   r_   r*   r0  rb   r   r   r   r,     s      z*ScheduledDeleteCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   rB  rt   ru   r   r   r   r   rz     s    zScheduledDeleteCommand.__init__r{   c                 C   s"   t | jd}|j| j| jd d S Nr|   rF  )r   ru   Zdelete_scheduled_jobrB  rt   r  r   r   r   r:     s    zScheduledDeleteCommand.runr   r   r   r   r   r0    s   r0  c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r1  Nr8   c                 C   sN   | j ddd}|jdtdd |jdtdd |jd	td
d |jtd d S )Nr;  zSuspend (pause) a scheduled Jobr   rB  rH  r=   rU   rD  rW   rX   r&   )r(   r^   r_   r*   r1  rb   r   r   r   r,     s      z+ScheduledSuspendCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   rI  r   r   r   r   rz     s    z ScheduledSuspendCommand.__init__r{   c                 C   s"   t | jd}|j| j| jd d S rJ  )r   ru   Zsuspend_scheduled_jobrB  rt   r  r   r   r   r:     s    zScheduledSuspendCommand.runr   r   r   r   r   r1    s   r1  c                   @   s>   e Zd ZeeddddZeddddZddd	d
ZdS )r2  Nr8   c                 C   sN   | j ddd}|jdtdd |jdtdd |jd	td
d |jtd d S )Nresumez Resume (unpause) a scheduled Jobr   rB  rH  r=   rU   rD  rW   rX   r&   )r(   r^   r_   r*   r2  rb   r   r   r   r,     s      z*ScheduledResumeCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   rI  r   r   r   r   rz     s    zScheduledResumeCommand.__init__r{   c                 C   s"   t | jd}|j| j| jd d S rJ  )r   ru   Zresume_scheduled_jobrB  rt   r  r   r   r   r:     s    zScheduledResumeCommand.runr   r   r   r   r   r2    s   r2  c                   @   s:   e Zd ZdZedd ZeddddZddd	d
ZdS )r3  z3Schedule UV scripts on Hugging Face infrastructure.c                 C   sv  | j ddd}|jdddd}|j dd	d}|jd
tdd |jddd |jdddg d |jddddd |jddddd |jdtdd |jddd |jdtdd t d!d |jd"d#d$d%d& |jd'd(d$d)d& |jd*td+d |jd,td-d |jd.td/d |jd0d1dd2d& |jd3td4d |jd5td6d |jd7d$d8d9d: |jd;d<td=d |jtd> dS )?r  r  zJSchedule UV scripts (Python with inline dependencies) on HF infrastructurer   r  r	  Tr
  r:   r  r4  r5  r=   r  r  r  rZ   r  r  r6  rT   r7  Nr8  r9  r:  r  r  r  r  rL   rM   rN   rO   r?   r@   rA   r  rC   rE   rF   rG   rH   rI   rJ   rK   rP   r  rR   rS   r  rU   rV   rW   r  r  r  r  r  r  r   r!  r&   )r(   r)   r^   r_   r`   ra   r*   r3  r"  r   r   r   r,     s    	   z&ScheduledUvCommand.register_subcommandNrd   c                 C   s"  |j | _ |j| _|j| _|j| _|j| _|j| _|j| _|j| _i | _	|j
rp| j	tt|j
 tj d |j	pxg D ]}| j	t|tj d qzi | _t }|jr| jtt|j |d |jpg D ]}| jt||d q|j| _|j| _|j| _|j| _|j| _|j| _dS r#  )r4  r  r  r;  r<  r  r$  r%  r;   rh   ri   rj   r   r   rk   rl   rg   rm   rn   ro   rp   rq   rr   rs   rt   ru   r&  r'  rv   r   r   r   rz     s2    $zScheduledUvCommand.__init__r{   c                 C   sn   t t j t| jd}|j| j| j| j| j	| j
| j| j| j| j| j| j| j| j| jd}td|j  dS )zSchedule UV command.r|   )r  r  r4  r;  r<  r$  r%  r;   rh   rn   rq   rr   rt   r'  r=  N)r   r(  r)  r   ru   Zcreate_scheduled_uv_jobr  r  r4  r;  r<  r$  r%  r;   rh   rn   rq   rr   rt   r'  r   r   )rw   r   r   r   r   r   r:   6  s&    zScheduledUvCommand.runr*  r   r   r   r   r3    s
   
Jr3  )2r+  r  rl   r   argparser   r   Zdataclassesr   pathlibr   typingr   r   r	   r
   r   Zhuggingface_hubr   r   r   Zhuggingface_hub.utilsr   Zhuggingface_hub.utils._dotenvr   r   r   Z
get_loggerr4   loggerra   r   r/   r-   r_   intr   r.   r+   r0   r1   ro   r2   r-  r.  r/  r0  r1  r2  r3  r   r   r   r   <module>   sB   
Y& %ta E