U
    ”Ê¹j­  ã                   @   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   úW/var/www/html/bwave/python/venv/lib/python3.8/site-packages/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ú	--secretsúvSet 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.ú--flavorúTFlavor for the hardware, as in HF Spaces. Defaults to `cpu-basic`. Possible values: ú, Ú.ú	--timeoutúVMax 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.ú--namespaceúVThe namespace where the Job will be created. Defaults to the current user's namespace.ú--tokenúIA 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p¢g 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|Ž ¡ qÜd 
|¡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_widthsÚ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 }	|	r‚d 
|	¡nd
}
|jr˜|j d¡nd
}||| ¡ |
dœ}|  |¡sºq4| |||
||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=   ú--repoúCRepository 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ú--pythonú5The 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pºg 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|ƒ q†d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   ÚscheduleúWOne of annually, yearly, monthly, weekly, daily, hourly, or a CRON schedule expression.r=   r;   r<   ú	--suspendrT   ú!Suspend (pause) the scheduled Job©rD   r   r°   ú--concurrencyú8Allow 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pºg D ]}| j t||d�¡ q¼|j| _|j| _|j| _|j| _d S re   )r5  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   r5  r<  r=  rh   rn   rq   rr   rt   úScheduled Job created with ID: )r   ru   Zcreate_scheduled_jobr;   rY   r5  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 }
|
r€d |
¡nd
}|jjrœ|jjj d¡nd
}|jjr¶|jj d¡nd
}||	t|ƒ|dœ}|  |¡sØq8| |||	||||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‚   r5  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_idr5  rÜ   rY   rÝ   Úlast_job_atrA  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‚   r5  r;   rY   rD  rA  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 )r0  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*   r0  rb   r   r   r   r,   e  s    ý  ÿz+ScheduledInspectCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   )rt   ru   rF  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 )©rC  rt   )Zinspect_scheduled_jobrt   )r   rC  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   rF  r�   r  r  r_   )rw   rB  r   rÿ   r   r:   x  s
    þzScheduledInspectCommand.runr‰   r   r   r   r   r0  d  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 )NÚdeletezDelete a scheduled Jobr   rC  úScheduled Job IDr=   rU   rE  rW   rX   r&   )r(   r^   r_   r*   r1  rb   r   r   r   r,   ‚  s    ý  ÿz*ScheduledDeleteCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   ©rC  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|   rG  )r   ru   Zdelete_scheduled_jobrC  rt   r  r   r   r   r:   •  s    zScheduledDeleteCommand.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 )Nr<  zSuspend (pause) a scheduled Jobr   rC  rI  r=   rU   rE  rW   rX   r&   )r(   r^   r_   r*   r2  rb   r   r   r   r,   ›  s    ý  ÿz+ScheduledSuspendCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   rJ  r�   r   r   r   rz   ©  s    z ScheduledSuspendCommand.__init__r{   c                 C   s"   t | jd�}|j| j| jd� d S rK  )r   ru   Zsuspend_scheduled_jobrC  rt   r  r   r   r   r:   ®  s    zScheduledSuspendCommand.runr‰   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 )r3  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   rC  rI  r=   rU   rE  rW   rX   r&   )r(   r^   r_   r*   r3  rb   r   r   r   r,   ´  s    ý  ÿz*ScheduledResumeCommand.register_subcommandrd   c                 C   s   |j | _ |j| _|j| _d S r   rJ  r�   r   r   r   rz   Â  s    zScheduledResumeCommand.__init__r{   c                 C   s"   t | jd�}|j| j| jd� d S rK  )r   ru   Zresume_scheduled_jobrC  rt   r  r   r   r   r:   Ç  s    zScheduledResumeCommand.runr‰   r   r   r   r   r3  ³  s   r3  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 )r4  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  r5  r6  r=   r  r  r  rZ   r  r  r7  rT   r8  Nr9  r:  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*   r4  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pÒg D ]}| j t||d�¡ qÔ|j| _|j| _|j| _|j| _|j| _|j| _dS r$  )r5  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  r5  r<  r=  r%  r&  r;   rh   rn   rq   rr   rt   r(  r>  N)r   r)  r*  r   ru   Zcreate_scheduled_uv_jobr  r  r5  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   r4  Ì  s
   
Jr4  )2r,  r  rl   ré   Úargparser   r   Ú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/  r0  r1  r2  r3  r4  r   r   r   r   Ú<module>   sB   
Y& %ta E