
    RX9i                        S r SSKrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
  SSKJrJrJrJr  SSKrSSKJrJrJr  SSKJr  SS	KJr  S
SKJr  \R6                  " \5      r\ V s/ s H   o R<                  S:w  d  M  U R<                  PM"     sn r " S S\5      r  " S S\5      r! " S S\5      r"S\\\\#\$4         S\\#   S\#4S jr% " S S\5      r& " S S\5      r' " S S\5      r( " S S\5      r)S\\#\#4   4S jr* " S  S!\5      r+ " S" S#\5      r, " S$ S%\5      r- " S& S'\5      r. " S( S)\5      r/ " S* S+\5      r0 " S, S-\5      r1 " S. S/\5      r2gs  sn f )0a  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   )BaseHuggingfaceCLICommandz	zero-a10gc                   ,    \ rS rSr\S\4S j5       rSrg)JobsCommands7   parserc                   ^ U R                  SSS9mTR                  SS9nTR                  U4S jS9  [        R	                  U5        [
        R	                  U5        [        R	                  U5        [        R	                  U5        [        R	                  U5        [        R	                  U5        [        R	                  U5        g )NjobszRun and manage Jobs on the Hub.helpz$huggingface.co jobs related commandsc                 $   > TR                  5       $ N
print_help)argsjobs_parsers    X/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/huggingface_hub/cli/jobs.py<lambda>2JobsCommands.register_subcommand.<locals>.<lambda>>   s    ;3I3I3K    func)
add_parseradd_subparsersset_defaultsInspectCommandregister_subcommandLogsCommand	PsCommand
RunCommandCancelCommand	UvCommandScheduledJobsCommands)r   jobs_subparsersr   s     @r    r*    JobsCommands.register_subcommand8   s    ''5V'W%44:`4a 	  &K L 	**?;''8%%o6&&7))/:%%o611/Br#    N__name__
__module____qualname____firstlineno__staticmethodr   r*   __static_attributes__r3   r#   r    r   r   7   s    C$5 C Cr#   r   c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r-   J   r   returnNc                 ,   U R                  SSS9nUR                  S[        SS9  UR                  SSS	S
S9  UR                  SSS	SS9  UR                  S[        SS9  UR                  S[        SS9  UR                  S[        SSR                  [        5       S3S9  UR                  S[        SS9  UR                  SSSSS9  UR                  S[        SS9  UR                  S[        S S9  UR                  S!S"S#S$9  UR                  [        S%9  g )&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_parsers     r    r*   RunCommand.register_subcommandK   s   &&u;&?
c8RSghEvwK 	  	
 	3=gh 0sArsghlhqhq  sD  iE  hF  FG  H 	  	

 	i 	  	

 	F	 	  	
 	i 	  	

 	\ 	  	

 		=RSZ0r#   r   c                    UR                   U l         UR                  U l        0 U l        UR                  (       a`  U R                  R	                  [        [        UR                  5      R                  5       [        R                  R                  5       S95        UR                  =(       d    /  HB  nU R                  R	                  [        U[        R                  R                  5       S95        MD     0 U l        [        5       nUR                  (       aD  U R                  R	                  [        [        UR                  5      R                  5       US95        UR                  =(       d    /  H%  nU R                  R	                  [        XCS95        M'     UR                  U l        UR                  U l        UR                   U l        UR"                  U l        UR$                  U l        g Nenviron)r@   r^   envenv_fileupdater   r   	read_textosrm   copysecrets_get_extended_environsecrets_fileflavortimeoutdetach	namespacetokenselfr   	env_valueextended_environsecrets        r    __init__RunCommand.__init__x   s@   **
"&,,-/==HHOOKT]](;(E(E(GQSQ[Q[Q`Q`QbcdRIHHOOK	2::??;LMN (1302LLD1B1B,C,M,M,OYi jkll(b(FLLF MN )/3{{&*ll KK(,$(JJ
r#   c           
         [        U R                  S9nUR                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  S9n[        SUR                   35        [        SUR                   35        U R                  (       a  g UR                  UR                  S9 H  n[        U5        M     g )Nr{   )r@   r^   rn   rt   rw   rx   rz   Job started with ID: 	View at: job_id)r   r{   run_jobr@   r^   rn   rt   rw   rx   rz   printidurlry   fetch_job_logsr}   apijoblogs       r    r?   RunCommand.run   s    $**%kk**LLLL;;LLnn  
 	%cffX./	#''#$;; %%SVV%4C#J 5r#   )	r^   ry   rn   rw   r@   rz   rt   rx   r{   r=   Nr5   r6   r7   r8   r9   r   r*   r   r   r?   r:   r3   r#   r    r-   r-   J   s<    *1$5 *1$ *1 *1X/Y /4 /(r#   r-   c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r+      r   r=   Nc                     U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  UR                  S	[        S
S9  UR                  [        S9  g )NlogszFetch the logs of a Jobr   r   Job IDrB   rZ   QThe namespace where the job is running. Defaults to the current user's namespace.r\   r]   r$   )r&   rc   rd   r(   r+   rg   s     r    r*   LogsCommand.register_subcommand   sy    &&v4M&N
sBd 	  	

 	C&q 	  	
 	[1r#   r   c                 j    UR                   U l         UR                  U l        UR                  U l        g r   r   rz   r{   r}   r   s     r    r   LogsCommand.__init__   s#    ;;(,$(JJ
r#   c                     [        U R                  S9nUR                  U R                  U R                  S9 H  n[        U5        M     g Nr   r   rz   )r   r{   r   r   rz   r   )r}   r   r   s      r    r?   LogsCommand.run   s:    $**%%%T[[DNN%SC#J Tr#   r   r   r   r3   r#   r    r+   r+      s;    2$5 2$ 2 2/Y /4 /
r#   r+   rowsheadersr=   c           
         [        / U QUP76  Vs/ s H  n[        S U 5       5      PM     nn[        [        R                  " 5       R                  [        U5      S-  5      n[        U5      [        U5      -   U:  a  UR                  [        U5      5      nX5==   S-  ss'   [        U5      [        U5      -   U::  a!  U[        U5      -
  [        U5      -
  X5   -   X5'   [        U5      [        U5      -   U:  a  M  S[        U5      -  R                  " U6 n/ nUR                  UR                  " U6 5        UR                  UR                  " U Vs/ s H  nSU-  PM
     sn6 5        U  Hu  n	[        X5       V
Vs/ s H<  u  p[        [        U
5      5      U:  a  [        U
5      SUS-
   S-   O
[        U
5      PM>     nn
nUR                  UR                  " U6 5        Mw     S	R                  U5      $ s  snf s  snf s  snn
f )
zy
Inspired by:

- stackoverflow.com/a/8356620/593036
- stackoverflow.com/questions/9535954/printing-lists-as-tabular-data
c              3   J   #    U  H  n[        [        U5      5      v   M     g 7fr   )lenrd   ).0xs     r    	<genexpr>_tabulate.<locals>.<genexpr>   s     /3ac#a&kk3s   !#      z{{:{}}} -N   r_   
)zipmaxrr   get_terminal_sizecolumnsr   sumindexformatrF   rd   re   )r   r   col
col_widthsterminal_widthcol_to_minimize
row_formatlineswrowr   	col_widthrow_format_argss                r    	_tabulater      s    <?;N;Ng;NO;NC#/3//;NJO--/77W9JKN
g,Z
(>
9$**3z?;#)#w<#j/)^;*83z?*JSQX\*Y\f\w*wJ'	 g,Z
(>
9
 s7|+33Z@JE	LL""G,-	LL""j$AjS1Wj$ABC !$C 4
 4 033q6{Y/FCF?Y]#e+CPQFR 4 	 
 	Z&&89  99U# P %B
s   G6G;=AH c                   n    \ rS rSr\S\SS4S j5       rS\SS4S jrSS jr	S	\
\\4   S\4S
 jrS rSrg)r,      r   r=   Nc                    U R                  SSS9nUR                  SSSSS9  UR                  S	[        S
S9  UR                  S[        SS9  UR                  SSS/ SS9  UR                  S[        SS9  UR                  [        S9  g )Npsz	List Jobsr   -a--allrY   z*Show all Jobs (default shows just running)rH   rZ   UThe namespace from where it lists the jobs. Defaults to the current user's namespace.rB   r\   r]   -f--filterrF   >Filter output based on conditions provided (format: key=value)rI   defaultr   --format%Format output using a custom templater$   )r&   rc   rd   r(   r,   rg   s     r    r*   PsCommand.register_subcommand   s    &&t+&>
=	 	  	
 	h 	  	

 	\ 	  	
 	Q 	  	
 	8 	  	

 	Y/r#   r   c                 N   UR                   U l         UR                  U l        UR                  U l        UR                  U l        0 U l        UR
                   HJ  nSU;   a2  UR                  SS5      u  p4X@R                  UR                  5       '   M;  [        SU S35        ML     g N=r   z)Warning: Ignoring invalid filter format 'z'. Use key=value format.	allrz   r{   r   filtersfiltersplitlowerr   r}   r   fkeyvalues        r    r   PsCommand.__init__       (,$(JJ
%)[[') AaxWWS!_
,1SYY[)A!D\]^ r#   c           
          [        U R                  S9nUR                  U R                  S9n/ SQn/ nU GH  nUR                  (       a  UR                  R
                  OSnU R                  (       d  US;  a  MF  UR                  nUR                  =(       d    SnUR                  =(       d    / n	U	(       a  SR                  U	5      OSn
UR                  (       a  UR                  R                  S5      OSnUUUR                  5       U
S	.nU R                  U5      (       d  M  UR                  XxXU/5        GM     U(       dh  S
nU R                   (       aF  SSR                  U R                   R#                  5        VVs/ s H  u  pU SU 3PM     snn5       3n[%        SU 35        gU R'                  XC5        gs  snnf ! [(        R*                   a  n[%        SU 35         SnAgSnAf[,        [.        [0        4 a  n[%        SU 35         SnAgSnAf[2         a.  n[%        S[5        U5      R6                   SU 35         SnAgSnAff = f)z
Fetch and display job information for the current user.
Uses Docker-style filtering with -f/--filter flag and key=value pairs.
r   rz   )zJOB IDIMAGE/SPACECOMMANDCREATEDSTATUSUNKNOWN)RUNNINGUPDATINGN/A %Y-%m-%d %H:%M:%S)r   r@   statusr^     matching filters: rS   r   zNo jobs foundNzError fetching jobs data: zError processing jobs data: Unexpected error - : )r   r{   	list_jobsrz   r   stager   r   docker_imager^   re   
created_atstrftimer   _matches_filtersrF   r   itemsr   _print_outputrequestsRequestExceptionKeyError
ValueError	TypeError	ExceptionrC   r5   )r}   r   r   table_headersr   r   r   r   image_or_spacer^   command_strr   job_propertiesfilters_msgkves                    r    r?   PsCommand.run  s   
A	Adjj)C ==4>>=:D VM D-0ZZ))Y xxF2I$I  "%!1!1!:U +++3:chhw/ NQ^^S^^445HIaf
 !+$lln*	" ,,^<< V[fUVE J  <<$7		Z^ZfZfZlZlZnBoZnRVRSaS!:ZnBo8p7q"rKk]34 t3 Cp (( 	4.qc233*i0 	60455 	A'Q(8(8'9A3?@@	AsH   FG GG /G G IG..IHI&$IIr  c                 j   U R                   R                  5        H  u  p#X!;  a    gSU;   d  SU;   aW  UR                  SS5      R                  SS5      n[        R                  " SU S3X   [        R
                  5      (       d    gMo  UR                  5       X   R                  5       ;  d  M    g   g)	z+Check if job matches all specified filters.F*?.*rT   ^$Tr   r   replaceresearch
IGNORECASEr   r}   r  r   patternregex_patterns        r    r   PsCommand._matches_filtersS       LL..0LC( g~ 'T : B B3 Lyy1]O1!5~7JBMMZZ  [ (;(A(A(CC 1 r#   c           	         U R                   (       ac  U R                   nU HP  nUn[        / SQ5       H/  u  pgSU S3nX;   d  M  UR                  U[        XF   5      5      nM1     [	        U5        MR     g[	        [        UUS95        g),Print output according to the chosen format.)r   r@   r^   createdr   {{.}}r   Nr   	enumerater  rd   r   r   	r}   r   r   templater   lineifieldplaceholders	            r    r   PsCommand._print_outputf  s    ;;{{H )*Y ZHA$)%"5K"*#||KSVE ![ d  #r#   r   r   r   rz   r{   r   r5   r6   r7   r8   r9   r   r*   r   r   r?   r   rd   boolr   r   r:   r3   r#   r    r,   r,      sb     0$5  0$  0  0D_Y _4 _FAPtCH~ $ &r#   r,   c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r)   i|  r   r=   Nc                     U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  UR                  S	S
SS9  UR                  [        S9  g )Ninspectz0Display detailed information on one or more Jobsr   rZ   r   rB   r\   r]   job_idsr_   zThe jobs to inspectra   r$   )r&   rc   rd   r(   r)   rg   s     r    r*   "InspectCommand.register_subcommand}  sz    &&y7i&j
d 	  	

 	C&q 	  	
 		=RS^4r#   r   c                 j    UR                   U l         UR                  U l        UR                  U l        g r   )rz   r{   r/  r   s     r    r   InspectCommand.__init__  s#    (,$(JJ
"&,,r#   c           
         [        U R                  S9nU R                   Vs/ s H  o!R                  X R                  S9PM     nn[        [        R                  " U Vs/ s H  n[        U5      PM     snS[        S95        g s  snf s  snf )Nr   r      indentr   )
r   r{   r/  inspect_jobrz   r   jsondumpsr   rd   )r}   r   r   r   r   s        r    r?   InspectCommand.run  sj    $**%W[WcWcdWcVvHWcddjj6#&+6q#NO e6s   "BB	)r/  rz   r{   r   r   r3   r#   r    r)   r)   |  s<    5$5 5$ 5 5/Y /4 /
Pr#   r)   c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r.   i  r   r=   Nc                     U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  UR                  S	[        S
S9  UR                  [        S9  g )NcancelzCancel a Jobr   r   r   rB   rZ   r   r\   r]   r$   )r&   rc   rd   r(   r.   rg   s     r    r*   !CancelCommand.register_subcommand  sx    &&xn&E
sBd 	  	

 	C&q 	  	
 	]3r#   r   c                 j    UR                   U l         UR                  U l        UR                  U l        g r   r   r   s     r    r   CancelCommand.__init__  s#    ;;$(JJ
r#   c                 r    [        U R                  S9nUR                  U R                  U R                  S9  g r   )r   r{   
cancel_jobr   rz   r}   r   s     r    r?   CancelCommand.run  s(    $**%dkkT^^Dr#   r   r   r   r3   r#   r    r.   r.     s<    4$5 4$ 4 4/Y /4 /
Er#   r.   c                   D    \ rS rSrSr\S 5       rS\SS4S jrS
S jr	S	r
g)r/   i  z.Run UV scripts on Hugging Face infrastructure.c                     U R                  SSS9nUR                  SSSS9nUR                  SS	S9nUR                  S
SS9  UR                  SSS/ S9  UR                  S[        SS9  UR                  SSS9  UR                  S[        SSR	                  [
        5       S3S9  UR                  SSSSS9  UR                  SSSS S9  UR                  S![        S"S9  UR                  S#[        S$S9  UR                  S%[        S&S9  UR                  S'S(S)S*S9  UR                  S+[        S,S9  UR                  S-[        S.S9  UR                  S/SS0S1S29  UR                  S3S4[        S5S9  UR                  [        S69  g7)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_argsr_   Arguments for the scriptrb   r   r   --image.Use a custom Docker image with `uv` installed.rB   --repoCRepository name for the script (creates ephemeral if not specified)rQ   rR   rS   rT   rD   rE   rF   Environment variablesrH   rJ   rK   rL   rM   rN   rO   rP   rU    Max duration (e.g., 30s, 5m, 1h)rW   rX   rY   Run in backgroundrZ   r[   r\   HF token--with%Run with the given packages installedwith_rI   r   rL  -p--python5The Python interpreter to use for the run environmentr$   N)r&   r'   rc   rd   re   rf   r(   r/   r   	uv_parser
subparsersrh   s       r    r*   UvCommand.register_subcommand  s    %%X & 
	
 --<m^b-c
  **K + 

 	/UVUA[egh	:jkV 	  	
 	ghlhqhq  sD  iE  hF  FG  H 	  	

 	ghE\]K 	  	
 	3=ghB 	  	

 	#<^_jL_`i 	  	

 		*E@gnuv*3-d 	  	
 	Y/r#   r   r=   Nc                 h   UR                   U l         UR                  U l        UR                  U l        UR                  U l        UR
                  U l        0 U l        UR                  (       a`  U R                  R                  [        [        UR                  5      R                  5       [        R                  R                  5       S95        UR                  =(       d    /  HB  nU R                  R                  [        U[        R                  R                  5       S95        MD     0 U l        [!        5       nUR"                  (       aD  U R                  R                  [        [        UR"                  5      R                  5       US95        UR                  =(       d    /  H%  nU R                  R                  [        XCS95        M'     UR$                  U l        UR&                  U l        UR(                  U l        UR*                  U l        UR,                  U l        UR.                  U l        gz-Initialize the command with parsed arguments.rl   N)rO  rQ  r^  dependenciespythonr@   rn   ro   rp   r   r   rq   rr   rm   rs   rt   ru   rv   rw   rx   ry   rz   r{   repo_repor|   s        r    r   UvCommand.__init__  sp   kk++ JJkkZZ
-/==HHOOKT]](;(E(E(GQSQ[Q[Q`Q`QbcdRIHHOOK	2::??;LMN (1302LLD1B1B,C,M,M,OYi jkll(b(FLLF MN )/3{{&*ll KK(,$(JJ
YY
r#   c                 Z   [         R                  " [         R                  5        [        U R                  S9nUR                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   S9n[#        SUR$                   35        [#        SUR&                   35        U R(                  (       a  gUR+                  UR$                  S9 H  n[#        U5        M     g)zExecute UV command.r   )rO  rQ  ri  rj  r@   rn   rt   rw   rx   rz   rl  r   r   Nr   )r   set_verbosityINFOr   r{   
run_uv_jobrO  rQ  ri  rj  r@   rn   rt   rw   rx   rz   rl  r   r   r   ry   r   r   s       r    r?   UvCommand.run  s    gll+$**%nn;;((**;;**LL;;LLnn**  
 	%cffX./	#''#$;; %%SVV%4C#J 5r#   )rl  ri  ry   rn   rw   r@   rz   rj  rO  rQ  rt   rx   r{   r   r5   r6   r7   r8   __doc__r9   r*   r   r   r?   r:   r3   r#   r    r/   r/     s0    870 70rY 4 2r#   r/   c                  d    [         R                  R                  5       n [        5       =nb  XS'   U $ )NHF_TOKEN)rr   rm   rs   r   )r   r{   s     r    ru   ru   #  s.    zz()',$r#   c                   ,    \ rS rSr\S\4S j5       rSrg)r0   i*  r   c                   ^ U R                  SSS9nUR                  SS9mUR                  U4S jS9  [        R	                  T5        [
        R	                  T5        [        R	                  T5        [        R	                  T5        [        R	                  T5        [        R	                  T5        [        R	                  T5        g )N	scheduledz,Create and manage scheduled Jobs on the Hub.r   z.huggingface.co scheduled jobs related commandsc                 $   > TR                  5       $ r   r   )r   scheduled_jobs_subparserss    r    r!   ;ScheduledJobsCommands.register_subcommand.<locals>.<lambda>3  s    =V=a=a=cr#   r$   )r&   r'   r(   ScheduledRunCommandr*   ScheduledPsCommandScheduledInspectCommandScheduledDeleteCommandScheduledSuspendCommandScheduledResumeCommandScheduledUvCommand)r   scheduled_jobs_parserr{  s     @r    r*   )ScheduledJobsCommands.register_subcommand+  s     & 1 1+Dr 1 s$9$H$HA %I %
!
 	**0c*d 	//0IJ../HI334MN223LM334MN223LM../HIr#   r3   Nr4   r3   r#   r    r0   r0   *  s    J$5 J Jr#   r0   c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r}  i?  r   r=   Nc                 z   U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  UR                  S	S
SS S9  UR                  SS
SS S9  UR                  SSSSS9  UR                  SSSSS9  UR                  S[        SS9  UR                  S[        SS9  UR                  S[        SSR                  [        5       S3S9  UR                  S[        S S9  UR                  S![        S"S9  UR                  S#[        S$S9  UR                  S%S&S'S(9  UR                  [        S)9  g )*Nr?   zSchedule a Jobr   scheduleWOne of annually, yearly, monthly, weekly, daily, hourly, or a CRON schedule expression.rB   r@   rA   	--suspendrY   !Suspend (pause) the scheduled JobrI   r   r   --concurrency8Allow multiple instances of this Job to run concurrentlyrD   rE   rF   rG   rH   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rZ   z`The namespace where the scheduled Job will be created. Defaults to the current user's namespace.r\   r]   r^   r_   r`   ra   r$   )r&   rc   rd   re   rf   r(   r}  rg   s     r    r*   'ScheduledRunCommand.register_subcommand@  s   &&u3C&D
j 	  	

 	c8RS4	 	  	
 	K	 	  	
 	ghEvwK 	  	
 	3=gh 0sArsghlhqhq  sD  iE  hF  FG  H 	  	

 	i 	  	

 	s 	  	

 	\ 	  	

 		=RS%89r#   r   c                 $   UR                   U l         UR                  U l        UR                  U l        UR                  U l        UR                  U l        0 U l        UR                  (       a`  U R
                  R                  [        [        UR                  5      R                  5       [        R                  R                  5       S95        UR
                  =(       d    /  HB  nU R
                  R                  [        U[        R                  R                  5       S95        MD     0 U l        [        5       nUR                   (       aD  U R                  R                  [        [        UR                   5      R                  5       US95        UR                  =(       d    /  H%  nU R                  R                  [        XCS95        M'     UR"                  U l        UR$                  U l        UR&                  U l        UR(                  U l        g rk   )r  r@   r^   suspendconcurrencyrn   ro   rp   r   r   rq   rr   rm   rs   rt   ru   rv   rw   rx   rz   r{   r|   s        r    r   ScheduledRunCommand.__init__x  sY   !]]**
"&,,'+||+/+;+;-/==HHOOKT]](;(E(E(GQSQ[Q[Q`Q`QbcdRIHHOOK	2::??;LMN (1302LLD1B1B,C,M,M,OYi jkll(b(FLLF MN )/3{{&*ll(,$(JJ
r#   c                 R   [        U R                  S9nUR                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9
n[        SUR                   35        g )Nr   )
r@   r^   r  r  r  rn   rt   rw   rx   rz   Scheduled Job created with ID: )r   r{   create_scheduled_jobr@   r^   r  r  r  rn   rt   rw   rx   rz   r   r   )r}   r   scheduled_jobs      r    r?   ScheduledRunCommand.run  s    $**%00**LL]]LL((LL;;LLnn 1 
 	/0@0@/ABCr#   )r^   r  rn   rw   r@   rz   r  rt   r  rx   r{   r   r   r3   r#   r    r}  r}  ?  s=    5:$5 5:$ 5: 5:n/Y /4 /,Dr#   r}  c                   n    \ rS rSr\S\SS4S j5       rS\SS4S jrSS jr	S	\
\\4   S\4S
 jrS rSrg)r~  i  r   r=   Nc                    U R                  SSS9nUR                  SSSSS9  UR                  S	[        S
S9  UR                  S[        SS9  UR                  SSS/ SS9  UR                  S[        SS9  UR                  [        S9  g )Nr   zList scheduled Jobsr   r   r   rY   z1Show all scheduled Jobs (default hides suspended)rH   rZ   r   rB   r\   r]   r   r   rF   r   r   r   r   r$   )r&   rc   rd   r(   r~  rg   s     r    r*   &ScheduledPsCommand.register_subcommand  s    &&t2G&H
D	 	  	
 	h 	  	

 	\ 	  	
 	Q 	  	
 	8 	  	

 	%78r#   r   c                 N   UR                   U l         UR                  U l        UR                  U l        UR                  U l        0 U l        UR
                   HJ  nSU;   a2  UR                  SS5      u  p4X@R                  UR                  5       '   M;  [        SU S35        ML     g r   r   r   s        r    r   ScheduledPsCommand.__init__  r   r#   c           
      x    [        U R                  S9nUR                  U R                  S9n/ SQn/ nU GHi  nUR                  nU R
                  (       d	  U(       a  M*  UR                  nUR                  nUR                  R                  =(       d    Sn	UR                  R                  =(       d    / n
U
(       a  SR                  U
5      OSnUR                  R                  (       a/  UR                  R                  R                  R                  S5      OSnUR                  R                   (       a%  UR                  R                   R                  S5      OSnUU	[#        U5      US.nU R%                  U5      (       d  GMQ  UR'                  UUU	UUUU/5        GMl     U(       di  SnU R(                  (       aG  S	S
R                  U R(                  R+                  5        VVs/ s H  u  nnU SU 3PM     snn5       3n[-        SU 35        gU R/                  XC5        gs  snnf ! [0        R2                   a  n[-        SU 35         SnAgSnAf[4        [6        [8        4 a  n[-        SU 35         SnAgSnAf[:         a.  n[-        S[=        U5      R>                   SU 35         SnAgSnAff = f)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   )IDSCHEDULEr   r   zLAST RUNzNEXT RUNSUSPENDr   r   r   )r   r@   r  r^   r   r   rS   r   zNo scheduled jobs foundNz$Error fetching scheduled jobs data: z&Error processing scheduled jobs data: r   r   ) r   r{   list_scheduled_jobsrz   r  r   r   r  job_specr   r^   re   r   last_jobatr   next_job_run_atrd   r   rF   r   r   r   r   r   r   r   r   r   r   rC   r5   )r}   r   scheduled_jobsr  r   r  r  scheduled_job_idr  r  r^   r  last_job_atr  r  r  r  r  r  s                      r    r?   ScheduledPsCommand.run  s   
_	Adjj)C !44t~~4NNM D!/'// xxG $1#3#3  )11 "/!7!7!D!D!M (0088>B3:chhw/
 %++44 "((1144==>QR  %++;; "((88AABUV   ++"7|*	" ,,^<< ( &##'
] "0v  <<$7		Z^ZfZfZlZlZnBoZnRVRSUVaS!:ZnBo8p7q"rK/}=> t3 Cp (( 	>8<==*i0 	@:1#>?? 	A'Q(8(8'9A3?@@	AsH   G%H, 'H&;H, H, &H, ,J9 IJ9+I>>J9$J44J9r  c                 j   U R                   R                  5        H  u  p#X!;  a    gSU;   d  SU;   aW  UR                  SS5      R                  SS5      n[        R                  " SU S3X   [        R
                  5      (       d    gMo  UR                  5       X   R                  5       ;  d  M    g   g)	z5Check if scheduled job matches all specified filters.Fr  r  r  rT   r  r  Tr  r  s        r    r   #ScheduledPsCommand._matches_filters9  r  r#   c           	         U R                   (       ac  U R                   nU HP  nUn[        / SQ5       H/  u  pgSU S3nX;   d  M  UR                  U[        XF   5      5      nM1     [	        U5        MR     g[	        [        UUS95        g)r  )r   r  r@   r^   r  r  r  r  r  r  Nr   r"  s	            r    r    ScheduledPsCommand._print_outputL  s    ;;{{H )g!HA %*%"5K"*#||KSVE! d  #r#   r)  r   r*  r3   r#   r    r~  r~    sb     9$5  9$  9  9D_Y _4 _dALtCH~ $ &r#   r~  c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r  id  r   r=   Nc                     U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  UR                  S	S
SS9  UR                  [        S9  g )Nr.  z:Display detailed information on one or more scheduled Jobsr   rZ   SThe namespace where the scheduled job is. Defaults to the current user's namespace.rB   r\   r]   scheduled_job_idsr_   zThe scheduled jobs to inspectra   r$   )r&   rc   rd   r(   r  rg   s     r    r*   +ScheduledInspectCommand.register_subcommande  s|    &&y7s&t
f 	  	

 	C&q 	  	
 	 35Gfg%<=r#   r   c                 j    UR                   U l         UR                  U l        UR                  U l        g r   )rz   r{   r  r   s     r    r    ScheduledInspectCommand.__init__s  s&    (,$(JJ
,0,B,Br#   c           
         [        U R                  S9nU R                   Vs/ s H  nUR                  X R                  S9PM     nn[        [        R                  " U Vs/ s H  n[        U5      PM     snS[        S95        g s  snf s  snf )Nr   r  rz   r4  r5  )
r   r{   r  inspect_scheduled_jobrz   r   r8  r9  r   rd   )r}   r   r  r  r  s        r    r?   ScheduledInspectCommand.runx  s    $**% %)$:$:
$:  %%7GSaSa%b$: 	 
 	djj^T^M&/^T]^hklm	
 Us   #B B
)rz   r  r{   r   r   r3   r#   r    r  r  d  s?    >$5 >$ > >CY C4 C
nr#   r  c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r  i  r   r=   Nc                     U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  UR                  S	[        S
S9  UR                  [        S9  g )NdeletezDelete a scheduled Jobr   r  Scheduled Job IDrB   rZ   r  r\   r]   r$   )r&   rc   rd   r(   r  rg   s     r    r*   *ScheduledDeleteCommand.register_subcommand  s|    &&x6N&O
 2CUVf 	  	

 	C&q 	  	
 	%;<r#   r   c                 j    UR                   U l         UR                  U l        UR                  U l        g r   r  rz   r{   r   s     r    r   ScheduledDeleteCommand.__init__  &    %)%:%:$(JJ
r#   c                 r    [        U R                  S9nUR                  U R                  U R                  S9  g Nr   r  )r   r{   delete_scheduled_jobr  rz   rC  s     r    r?   ScheduledDeleteCommand.run  0    $**%  $2G2GSWSaSa br#   rz   r  r{   r   r   r3   r#   r    r  r    <    =$5 =$ = =/Y /4 /
cr#   r  c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r  i  r   r=   Nc                     U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  UR                  S	[        S
S9  UR                  [        S9  g )Nr  zSuspend (pause) a scheduled Jobr   r  r  rB   rZ   r  r\   r]   r$   )r&   rc   rd   r(   r  rg   s     r    r*   +ScheduledSuspendCommand.register_subcommand  s|    &&y7X&Y
 2CUVf 	  	

 	C&q 	  	
 	%<=r#   r   c                 j    UR                   U l         UR                  U l        UR                  U l        g r   r  r   s     r    r    ScheduledSuspendCommand.__init__  r  r#   c                 r    [        U R                  S9nUR                  U R                  U R                  S9  g r  )r   r{   suspend_scheduled_jobr  rz   rC  s     r    r?   ScheduledSuspendCommand.run  s0    $**%!!43H3HTXTbTb!cr#   r  r   r   r3   r#   r    r  r    s<    >$5 >$ > >/Y /4 /
dr#   r  c                   L    \ rS rSr\S\SS4S j5       rS\SS4S jrS
S jr	S	r
g)r  i  r   r=   Nc                     U R                  SSS9nUR                  S[        SS9  UR                  S[        SS9  UR                  S	[        S
S9  UR                  [        S9  g )Nresumez Resume (unpause) a scheduled Jobr   r  r  rB   rZ   r  r\   r]   r$   )r&   rc   rd   r(   r  rg   s     r    r*   *ScheduledResumeCommand.register_subcommand  s|    &&x6X&Y
 2CUVf 	  	

 	C&q 	  	
 	%;<r#   r   c                 j    UR                   U l         UR                  U l        UR                  U l        g r   r  r   s     r    r   ScheduledResumeCommand.__init__  r  r#   c                 r    [        U R                  S9nUR                  U R                  U R                  S9  g r  )r   r{   resume_scheduled_jobr  rz   rC  s     r    r?   ScheduledResumeCommand.run  r  r#   r  r   r   r3   r#   r    r  r    r  r#   r  c                   D    \ rS rSrSr\S 5       rS\SS4S jrS
S jr	S	r
g)r  i  z3Schedule UV scripts on Hugging Face infrastructure.c                 r   U R                  SSS9nUR                  SSSS9nUR                  SS	S9nUR                  S
[        SS9  UR                  SSS9  UR                  SSS/ S9  UR                  SSSSS9  UR                  SSSSS9  UR                  S[        SS9  UR                  SSS9  UR                  S[        SS R	                  [
        5       S!3S9  UR                  S"S#S$S%S&9  UR                  S'S(S$S)S&9  UR                  S*[        S+S9  UR                  S,[        S-S9  UR                  S.[        S/S9  UR                  S0S1SS2S&9  UR                  S3[        S4S9  UR                  S5[        S6S9  UR                  S7S$S8S9S:9  UR                  S;S<[        S=S9  UR                  [        S>9  g)?rG  rH  zJSchedule UV scripts (Python with inline dependencies) on HF infrastructurer   rI  rJ  TrK  r?   rN  r  r  rB   rO  rP  rQ  r_   rR  rS  r  rY   r  Nr  r  r  rT  rU  rV  rW  rQ   rR   rS   rT   rD   rE   rF   rX  rH   rJ   rK   rL   rM   rN   rO   rP   rU   rY  rW   rX   rZ  rZ   r[   r\   r[  r\  r]  r^  r_  r`  ra  rb  r$   )r&   r'   rc   rd   re   rf   r(   r  rc  s       r    r*   &ScheduledUvCommand.register_subcommand  sz    %%] & 
	
 --<m^b-c
  **K + 

 	j 	  	

 	/UVUA[egh4	 	  	
 	K	 	  	
 		:jkV 	  	
 	ghlhqhq  sD  iE  hF  FG  H 	  	

 	ghE\]K 	  	
 	3=ghB 	  	

 	#<^_jL_`i 	  	

 		*E@gnuv*3-d 	  	
 	%78r#   r   r=   Nc                    UR                   U l         UR                  U l        UR                  U l        UR                  U l        UR                  U l        UR
                  U l        UR                  U l        UR                  U l        0 U l	        UR                  (       a`  U R                  R                  [        [        UR                  5      R                  5       [        R                   R#                  5       S95        UR                  =(       d    /  HB  nU R                  R                  [        U[        R                   R#                  5       S95        MD     0 U l        ['        5       nUR(                  (       aD  U R$                  R                  [        [        UR(                  5      R                  5       US95        UR$                  =(       d    /  H%  nU R$                  R                  [        XCS95        M'     UR*                  U l        UR,                  U l        UR.                  U l        UR0                  U l        UR2                  U l        UR4                  U l        grh  )r  rO  rQ  r  r  r^  ri  rj  r@   rn   ro   rp   r   r   rq   rr   rm   rs   rt   ru   rv   rw   rx   ry   rz   r{   rk  rl  r|   s        r    r   ScheduledUvCommand.__init__  s   !]]kk++'+||+/+;+; JJkkZZ
-/==HHOOKT]](;(E(E(GQSQ[Q[Q`Q`QbcdRIHHOOK	2::??;LMN (1302LLD1B1B,C,M,M,OYi jkll(b(FLLF MN )/3{{&*ll KK(,$(JJ
YY
r#   c                    [         R                  " [         R                  5        [        U R                  S9nUR                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                   U R"                  U R$                  U R&                  S9n[)        SUR*                   35        g)zSchedule UV command.r   )rO  rQ  r  r  r  ri  rj  r@   rn   rt   rw   rx   rz   rl  r  N)r   ro  rp  r   r{   create_scheduled_uv_jobrO  rQ  r  r  r  ri  rj  r@   rn   rt   rw   rx   rz   rl  r   r   )r}   r   r   s      r    r?   ScheduledUvCommand.run6  s    gll+$**%));;((]]LL((**;;**LL;;LLnn** * 
$ 	/x89r#   )rl  r  ri  ry   rn   rw   r@   rz   rj  r  rO  rQ  rt   r  rx   r{   r   rs  r3   r#   r    r  r    s2    =H9 H9TY 4 8:r#   r  )3rt  r8  rr   r  argparser   r   dataclassesr   pathlibr   typingr   r   r	   r
   r   huggingface_hubr   r   r   huggingface_hub.utilsr   huggingface_hub.utils._dotenvr   r   r   
get_loggerr5   loggerr   rf   r   r-   r+   rd   intr   r,   r)   r.   r/   ru   r0   r}  r~  r  r  r  r  r  )items   0r    <module>r     s  &  	 	 1   . .  ; ; ) 5 ' 
		H	%,9WMDZZ;=VZTZZMW C, C&V* Vr+ 4DeCHo./ $s)  6a) aHP. P4E- E2q) qhtCH~ J5 J*^D3 ^DBA2 AHn7 n:c6 c2d7 d2c6 c2@:2 @:q Xs   %E<E