
    Y j              (          S r SSKrSSKrSSKrSSKrSSKrSSKJ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  SSKJrJrJr  SSKrSS	KJ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#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.  \R^                  " \05      r1S\2S\2S-  S\3\2\2S-  4   4S jr4\ V s/ s H   o Rj                  S:w  d  M  U Rj                  PM"     sn r6Sr7\\2\Rp                  " SS94   r9\\2S-  \Rt                  " SS94   r;\\S-  \Rt                  " SS94   r<\\=\2   S-  \Rt                  " SSSS94   r>\\2S-  \Rt                  " SS94   r?\\@\Rt                  " SSSS94   rA\\2S-  \Rt                  " S S94   rB\\=\2   S-  \Rt                  " S!S"S94   rC\\2S-  \Rt                  " S#S$S%S94   rD\\@S-  \Rt                  " S&S94   rE\\@S-  \Rt                  " S'S94   rF\\2\Rp                  " S(S94   rG\\2\Rp                  " S)S94   rH\\=\2   S-  \Rp                  " S*S94   rI\\=\2   \Rp                  " S+S94   rJ\\2\Rp                  " S,S94   rK\\=\2   S-  \Rp                  " S-S94   rL\\2\Rp                  " S.S94   rM\." S/S9rN\NR                  S0S1S20/ S3QS49           SS5\9S6\JS7\!S8\%S9\>S:\'S;\ S<\$S=\<S>\?S?\AS\BS@\&SS4SA jj5       rP\NR                  SB/ SCQSD9    SS\KSE\\@\Rt                  " SFSGSHS94   SI\\QS-  \Rt                  " SJSKSLS94   S\BS@\&SS4SM jj5       rRSN\S\2\24   SO\=\3\2\2\24      S\@4SP jrTSQ\=\=\2\Q-        SR\=\2   SS\=\2   ST\2S-  SS4
SU jrUSV\QSS4SW jrVS\2SX\
\S\2\4      SY\=\2   S\
\3\@\2\=\=\2\Q-        4      4SZ jrW\NR                  S[S\/SD9   SS]\LS\BS@\&SS4S^ jj5       rX\NR                  S_S`Sa/SD9      SSb\\@\Rt                  " ScSdSeS94   S\BS@\&Sf\\=\2   S-  \Rt                  " SFSgShS94   Si\\2S-  \Rt                  " SjS94   Sk\#SS4Sl jj5       rY\NR                  SmSn/SD9SSo j5       rZ\NR                  SpSq/SD9  SS]\\=\2   \Rp                  " SrS94   S\BS@\&SS4Ss jj5       r[\NR                  StSu/SD9  SS\KS\BS@\&SS4Sv jj5       r\\." SwS9r]\NR                  \]SxSy9  \]R                  S0S1S20/ SzQS49               SS{\HS|\IS5\;S=\<S7\!S8\%S9\>S:\'S;\ S<\$S>\?S?\AS\BS@\&S}\CS~\DSS4"S jj5       r_\." SS9r`\NR                  \`SSy9  \`R                  S0S1S20S/S49            SS\GS5\9S6\JS\ES\FS7\!S8\%S9\>S:\'S;\ S<\$S=\<S>\?S\BS@\&SS4 S jj5       ra\`R                  S_S/SD9      SSb\\@\Rt                  " ScSdSS94   S\BS@\&Sf\\=\2   S-  \Rt                  " SFSgShS94   Si\\2S-  \Rt                  " SjS94   Sk\#SS4S jj5       rb\`R                  SpS/SD9  SS\\=\2   \Rp                  " SS94   S\BS@\&SS4S jj5       rc\`R                  SS/SD9  SS\MS\BS@\&SS4S jj5       rd\`R                  SS/SD9  SS\MS\BS@\&SS4S jj5       re\`R                  SS/SD9  SS\MS\BS@\&SS4S jj5       rf\." SS9rg\`R                  \gSxSy9  \gR                  S0S1S20SS/S49                SS\GS{\HS|\IS\ES\FS5\;S=\<S7\!S8\%S9\>S:\'S;\ S<\$S>\?S\BS@\&S}\CS~\DSS4&S jj5       rhS\=\2   S-  S\S\2\24   S-  4S jriSQ\=\=\2\Q-        SR\=\2   S\24S jrj\" S5      rkS\\k   S\	S\
\k   4   S\SSS4S jrlS\R                  R                  S\	S\
\k   4   S\=\S   S\
\k   4S jrogs  sn f )a  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 table|json|TEMPLATE] [-q]

    # Print logs from a job (non-blocking)
    hf jobs logs <job-id>

    # Stream logs from a job (blocking, like `docker logs -f`)
    hf jobs logs -f <job-id>

    # Stream resources usage stats and metrics from a job
    hf jobs stats <job-id>

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

    # Cancel a running job
    hf jobs cancel <job-id>

    # List available hardware options
    hf jobs hardware

    # Run a UV script
    hf jobs uv run <script>

    # Schedule a job
    hf jobs scheduled run <schedule> <image> <command>

    # List scheduled jobs
    hf jobs scheduled ps [-a] [-f key=value] [--format table|json] [-q]

    # Inspect a scheduled job
    hf jobs scheduled inspect <scheduled_job_id>

    # Suspend a scheduled job
    hf jobs scheduled suspend <scheduled_job_id>

    # Resume a scheduled job
    hf jobs scheduled resume <scheduled_job_id>

    # Delete a scheduled job
    hf jobs scheduled delete <scheduled_job_id>

    N)deque)CallableIterable)asdict)fnmatch)EmptyQueue)	AnnotatedAnyTypeVar)SpaceHardware)CLIErrorHfHubHTTPError)logging)_format_size   )
EnvFileOptEnvOptOutputFormatQuietOptSecretsFileOpt
SecretsOptTokenOpt
VolumesOpt_format_cellapi_object_to_dict
get_hf_apiparse_env_mapparse_volumesprint_list_outputtyper_factoryjob_id	namespacereturnc                    U (       d  [        S5      eU R                  S5      S:  a  [        SU  S35      eSU ;  a  X4$ U R                  SS5      u  p#U(       a  U(       d  [        SU  S35      eUb  X:w  a  [        SU SU S35      eX24$ )	a  Extract namespace from job_id if provided in 'namespace/job_id' format.

Allows users to pass job IDs copied from the Hub UI (e.g. 'username/job_id')
instead of only bare job IDs. If the namespace is also provided explicitly via
--namespace and conflicts, a CLIError is raised.
zJob ID cannot be empty./r   z<Job ID must be in the form 'job_id' or 'namespace/job_id': 'z'.z(Conflicting namespace: got --namespace='z ' but job ID implies namespace='')r   countsplit)r"   r#   extracted_namespaceparsed_job_ids       i/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/huggingface_hub/cli/jobs.py_parse_namespace_from_job_idr-   i   s     011||C1UV\U]]_`aa
&  )/c1)=&mUV\U]]_`aa!A6ykAabuavvwx
 	
 --    z	zero-a10gg?zThe Docker image to use.)helpz.Use a custom Docker image with `uv` installed.ztFlavor for the hardware, as in HF Spaces. Run 'hf jobs hardware' to list available flavors. Defaults to `cpu-basic`.z-lz--labelz3Set labels. E.g. --label KEY=VALUE or --label LABELzVMax duration: int/float with s (seconds, default), m (minutes), h (hours) or d (days).z-dz--detachz3Run the Job in the background and print the Job ID.zVThe namespace where the job will be running. Defaults to the current user's namespace.z--withz%Run with the given packages installedz-pz--pythonz5The Python interpreter to use for the run environmentz!Suspend (pause) the scheduled Jobz8Allow multiple instances of this Job to run concurrentlyzWOne of annually, yearly, monthly, weekly, daily, hourly, or a CRON schedule expression.z$UV script to run (local file or URL)zArguments for the scriptzThe command to run.zJob ID (or 'namespace/job_id')zJob IDs (or 'namespace/job_id')z2Scheduled Job ID (or 'namespace/scheduled_job_id')zRun and manage Jobs on the Hub.runignore_unknown_optionsT)z3hf jobs run python:3.12 python -c 'print("Hello!")'z3hf jobs run -e FOO=foo python:3.12 python script.pyz;hf jobs run --secrets HF_TOKEN python:3.12 python script.pyzVhf jobs run -v hf://gpt2:/data -v hf://buckets/org/b:/mnt python:3.12 python script.py)context_settingsexamplesimagecommandenvsecretslabelvolumeenv_filesecrets_fileflavortimeoutdetachtokenc                    [        X&5      n[        X75      n[        US9nUR                  U UUU[        U5      [	        U5      UU	US9	n[        SUR                   35        [        SUR                   35        U
(       a  gUR                  UR                  UR                  R                  SS9 H  n[        U5        M     g)z
Run a Job.r?   )	r4   r5   r6   r7   labelsvolumesr<   r=   r#   Job started with ID: 	View at: NTr"   r#   follow)r   r   run_job_parse_labels_mapr   printidurlfetch_job_logsownername)r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r#   r?   env_mapsecrets_mapapijoblogs                     r,   jobs_runrU     s    4 C*G6K
5
!C
++ 'f%  
C 
!#&&
*+	IcggY
 !!399>>RV!Wc
 Xr.   logs)zhf jobs logs <job_id>zhf jobs logs -f <job_id>zhf jobs logs --tail 20 <job_id>)r3   rG   z-fz--followzqFollow log output (stream until the job completes). Without this flag, only currently available logs are printed.tailz-nz--tailz1Number of lines to show from the end of the logs.c                    [        X5      u  pU(       a  Ub  [        S5      e[        US9n UR                  XUS9nUb	  [	        XbS9nU H  n[        U5        M     g! [         a]  nUR                  b  UR                  R                  OSn	U	S:X  a  [        S5      UeU	S:X  a  [        S	5      Ue[        S
U 35      UeSnAff = f)zFetch the logs of a Job.

By default, prints currently available logs and exits (non-blocking).
Use --follow/-f to stream logs in real-time until the job completes.
NzcCannot use --follow and --tail together. Use --follow to stream logs or --tail to show recent logs.rA   rF   )maxlen  'Job not found. Please check the job ID.  <Access denied. You may not have permission to view this job.zFailed to fetch job logs: )	r-   r   r   rM   r   rJ   r   responsestatus_code)
r"   rG   rW   r#   r?   rR   rV   rT   estatuss
             r,   	jobs_logsrb   G  s    : 5VGF$"q
 	
 5
!CD!!V!T+DC#J  D+,::+A''tS=DE1Ls]YZ`aa7s;<!CDs   0A 
C(AC  Cjob_propertiesfiltersc                     U Hj  u  p#nU R                  U5      nUc
  US:X  a  M"    g[        UR                  5       UR                  5       5      nUS:X  a  U(       a  US:X  d  Ma  U(       d  Mj    g   g)z5Check if scheduled job matches all specified filters.!=F=T)getr   lower)rc   rd   keyop_strpatternvaluematchs          r,   _matches_filtersro   {  sf     'W""3'=~w}}7cM%Vt^ !( r.   rowsheadersaliasesfmtc           	          U(       aW  UnU  HN  nUn[        U5       H/  u  pxSU S3n	X;   d  M  UR                  U	[        XW   5      5      nM1     [        U5        MP     g[        [	        XS95        g)z,Print output according to the chosen format.z{{.z}})rq   N)	enumeratereplacestrrJ   	_tabulate)
rp   rq   rr   rs   templaterowlineifieldplaceholders
             r,   _print_outputr     sl    
CD%g. %eWD1&<<S[AD / $K  	i./r.   nc                 B    SnSn[        U 5       H  n[        XS9  M     g )Nz[1Az[2K)end)rangerJ   )r   LINE_UP
LINE_CLEARr|   s       r,   _clear_liner     s"    GJ1Xg& r.   metrics_streamtable_headersc              #     #    U GHU  nU US    S3[        US   S-  S5      [        SUS   -  US   -  S	5       S3[        US   5       S
[        US   5       S3[        US   5       S[        US   5       S3/nUS   (       a  [        US   [        5      (       a  U/S/[	        U5      -  /[	        US   5      S-
  -  -   n[        U[        US   5      5       HR  u  pFUS   U   nUUS    S3[        SUS   -  US   -  S	5       S3[        US   5       S
[        US   5       S3/-  nMT     O!US/[	        U5      [	        U5      -
  -  -  nU/nSX4v   GMX     SU / 4v   g 7f)Ncpu_usage_pct%cpu_millicoresg     @@r   d   memory_used_bytesmemory_total_bytes   zB / Brx_bpszbps / tx_bpsbpsgpus utilizationN/AFT)roundr   
isinstancedictlenzipsorted)r"   r   r   metricsrz   rp   gpu_idgpus           r,   _get_jobs_stats_rowsr     s     "'(*'*+f4a8S7#677'BV:WWYZ[\\]^G$789:$|GThLi?j>kklmGH-./vl78CT6U5VVYZ
 6?z'&/4@@5RD3s8O,GFO0Dq0HIID"4)@Afof-=)*!,S3':#;;cBV>WWYZ[\\]^#C(;$<=>d<PSThPiCjBkklm   B E7c-03s8;<<C5DV!!+ ", 
s   E%E'statszhf jobs stats <job_id>job_idsc           
         U b+  / nU  H!  n[        XA5      u  pAUR                  U5        M#     Un [        US9nUc  UR                  5       S   nU cX  UR	                  US9 Vs/ s H>  nUR
                  (       a  UR
                  R                  OSS;   d  M2  UR                  PM@     n n[        U 5      S:X  a  [        S5        g/ S	Qn/ S
Qn [        R                  R                  [        U 5      5       n	0 n
U  H1  nU/nXSS  Vs/ s H  nSU;   d  SU;   a  SOSPM     sn-  nU/X'   M3     [        R                  " 5       nU
 VVs/ s H  oJU     H  oPM     M     nnn[        XUS5        U  Vs/ s H  nUUR                  XAS9US.PM     nn[!        U	["        US9 H  u  nnnU(       a  U
R%                  US5        OUX'   [        R                  " 5       nUU-
  [&        :  d  MI  [)        S[        U5      -   5        U
 VVs/ s H  oJU     H  oPM     M     nnn[        XUS5        UnM     SSS5        gs  snf s  snf s  snnf s  snf s  snnf ! , (       d  f       g= f! [*         a]  nUR,                  b  UR,                  R.                  OSnUS:X  a  [1        S5      UeUS:X  a  [1        S5      Ue[1        SU 35      UeSnAff = f)z7Fetch the resource usage statistics and metrics of JobsNrA   rO   r#   UNKNOWNRUNNINGUPDATINGr   zNo running jobs found)	JOB IDzCPU %zNUM CPUzMEM %z	MEM USAGEzNET I/Oz
GPU UTIL %z	GPU MEM %zGPU MEM USAGE)	rK   r   r   memory_used_bytes_pct!memory_used_bytes_and_total_bytesrx_bps_and_tx_bpsgpu_utilizationgpu_memory_used_bytes_pct%gpu_memory_used_bytes_and_total_bytesr   r&   USAGEz-- / --z--r"   r#   )r"   r   r   )kwargs_listr   rZ   r[   r\   r]   zFailed to fetch job stats: )r-   appendr   whoami	list_jobsra   stagerK   r   rJ   multiprocessingpool
ThreadPooltimer   fetch_job_metricsiflatmap_unorderedr   popSTATS_UPDATE_MIN_INTERVALr   r   r^   r_   r   )r   r#   r?   
parsed_idsr"   rR   rS   r   headers_aliasesr   rows_per_job_idrz   headerlast_update_time
total_rowsr   donerp   nowr`   ra   s                        r,   
jobs_statsr     s    
F <V OFf%  
5
!CJJL(	 }}y}9
9$'JJ

  IBYY CFF9 	 

 7|q%&
M
O%E!!,,S\:d@BO!(.xpqprbstbsX^cVmw&7H	tSbstt+.%' "  $yy{,;_O&W]G^#G^#OJ_*_dK & &F	 %&)&;&;6&;&_%2
 &   '9?Sal&m"fd#''5.2O+iik))-FFC
O 344C!gO&_eOf#Of#OJ!g!*_dS'*$ 'n% ;:?
F u `  "h5 ;::  E+,::+A''tS=DE1Ls]YZ`aa8<=1DEs   "1H=H=(I) 5II
!(I	I I4IAI+II
I4I) I
I&"I) &I) )
K3AKKpsz
hf jobs pszhf jobs ps -aallz-az--allz*Show all Jobs (default shows just running)filterz--filterz>Filter output based on conditions provided (format: key=value)formatzKOutput format: 'table' (default), 'json', or a Go template (e.g. '{{.id}}')quietc                 t   [        US9nUR                  US9n/ n/ n	U=(       d    /  GHk  n
U
R                  S5      (       d  U
R                  S5      (       a  U
R                  S5      (       a+  U
[        S5      S nSU;   a  [	        SU S35        Mk  US	S
pnOLU
[        S5      S nSU;   a  UR                  SS5      u  pOUS
pUR                  S5      (       a  S	nUSS nOSnU	R                  UR                  5       XR                  5       45        M  SU
;   ah  U
R                  SS5      u  nnUR                  S5      (       a  S	nUSS nOSnUR                  UR                  5       UUR                  5       45        GM\  [	        SU
 S35        GMn     / nU H  nUR                  (       a  UR                  R                  OSnU (       d  US;  a  M;  UR                  =(       d    SnUR                  =(       d    / nU(       a  SR                  U5      OSnUR                  UUR                  5       US.n[        UU5      (       d  M  [        UR                   =(       d    0 U	5      (       d  M  UR                  U5        M     U(       dj  U(       dQ  US:w  aK  U(       a3  SSR                  U VVVs/ s H  u  nnnU U U 3PM     snnn5       3OSn[	        SU 35        gUS:X  a  [	        S5        g/ SQn/ SQnU Vs/ s H  n[#        U5      PM     nnS[$        [&        [(        4   S[*        [&           4S jnU(       a,  US ;  a&  [-        U V s/ s H  n U" U 5      PM     sn UUU5        gUS:X  a  [.        R0                  O[.        R2                  n![5        UU!US!UUS"9  gs  snnnf s  snf s  sn f )#z
List Jobs.rA   r   zlabel!=zlabel=Nrg   z6Warning: Ignoring invalid label filter format 'label!=z'. Use label!=key format.rf   *r   !)Warning: Ignoring invalid filter format ''. Use key=value format.r   r   r    )rK   r4   ra   r5   json matching filters: , r   zNo jobs found[])r   IMAGE/SPACECOMMANDCREATEDSTATUS)rK   r4   r5   createdra   itemr$   c           
         U R                  S0 5      nU R                  S5      =(       d    / nU(       a  SR                  U5      OSn[        U R                  SS5      5      [        U R                  S5      =(       d    S5      [        U5      U R                  S5      (       a  U S   S S	 R	                  S
S5      OS[        UR                  SS5      5      /$ )Nra   r5   r   r   rK   r   docker_image
created_at   Tr   r   )rh   joinrw   r   rv   )r   ra   cmdcommand_strs       r,   row_fnjobs_ps.<locals>.row_fnt  s    (B'hhy!'R'*chhsmr"#.1:U;%9=,9O9ODs#++C5UZ

7I./
 	
r.   tabler   rK   itemsr   r   id_keyrq   r   )r   r   
startswithr   rJ   r)   endswithr   ri   ra   r   r   r5   r   rK   ro   rB   r   r   rw   r   listr   r   r   r   r    )"r   r#   r?   r   r   r   rR   jobsrd   labels_filtersf
label_part	label_keyoplabel_valuerj   rm   filtered_jobsrS   ra   image_or_spacer   r   propskovfilters_msgrq   rr   r   r   r   output_formats"                                     r,   jobs_psr    sy   6 5
!C==9=-D*,G13N\r\<<	""all8&<&<||I&&s9~/0
*$PQ[P\\uv -7s{	{s8}/
*$-7-=-=c1-E*I{-7{%%c**B )#2IB!!9??#4b:K:K:M"NOAXaJC||C  #2hNNCIIKU[[];<=aS@XYZC H M%(ZZ!!Yv%<<))2UkkR'*chhsmvv&,,.]hiw//

 0b.AAS!  6)fm/		W^:_W^GAqRSaSA3<W^:_0`/absuKM+/0 	 v$KGG=G0=>$E>

T#s(^ 

S	 

 & 116vd|6&Q-3v-=))<CUCU 	
7 ;` ?  7s   5N)N0N5hardwarezhf jobs hardwarec            
      t   [        5       n U R                  5       n/ SQn/ SQn/ nU H  nSnUR                  (       aG  UR                  R                   SUR                  R                   SUR                  R
                   S3nUR                  (       a  SUR                  S 3OS	nUR                  (       a  SUR                  S
-  S 3OS	nUR                  UR                  UR                  =(       d    SUR                  UR                  XgU/5        M     U(       d  [        S5        g[        XBUS5        g)z(List available hardware options for Jobs)NAMEzPRETTY NAMECPURAMACCELERATORzCOST/MINz	COST/HOUR)rO   
prettyNamecpuramacceleratorcostMincostHourr   zx z ()$z.4ffree<   z.2fzNo hardware options foundN)r   list_jobs_hardwarer  quantitymodelvramunit_cost_usdr   rO   pretty_namer	  r
  rJ   r   )	rR   hardware_listr   r   rp   hwaccelerator_infocost_min	cost_hours	            r,   jobs_hardwarer    s    ,C**,MaM`O"$D>>"$.."9"9!:"R^^=Q=Q<RRTUWUcUcUhUhTiijk131A1AQr'',-v797G7Ga((2-c23V	RWWbnn2BFFBFFDT`ijk  )*$=r.   inspectzhf jobs inspect <job_id>z*Job IDs to inspect (or 'namespace/job_id')c           
         / nU  H!  n[        XA5      u  pAUR                  U5        M#     Un [        US9n U  Vs/ s H  oER                  XAS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 ! [         a]  nUR                  b  UR                  R                  OSn	U	S:X  a  [        S5      UeU	S:X  a  [        S	5      Ue[        S
U 35      UeSnAff = f)z0Display detailed information on one or more JobsrA   r      indentdefaultNrZ   r[   r\   r]   zFailed to inspect job: )r-   r   r   inspect_jobrJ   r   dumpsr   rw   r   r^   r_   r   )
r   r#   r?   r   r"   rR   r   rS   r`   ra   s
             r,   jobs_inspectr&    s    J8K&!  G
5
!C
ARYZRYvCRYZdjj6#&+6q#NO [6 A+,::+A''tS=DE1Ls]YZ`aa4QC89q@As5   B BB -BB 
B 
D&AC>>Dcancelzhf jobs cancel <job_id>c                 $   [        X5      u  p[        US9n UR                  XS9  g! [         a]  nUR                  b  UR                  R
                  OSnUS:X  a  [        S5      UeUS:X  a  [        S5      Ue[        SU 35      UeSnAff = f)	zCancel a JobrA   r   NrZ   r[   r\   z>Access denied. You may not have permission to cancel this job.zFailed to cancel job: )r-   r   
cancel_jobr   r^   r_   r   )r"   r#   r?   rR   r`   ra   s         r,   jobs_cancelr*    s     5VGF
5
!C	@f: @+,::+A''tS=DE1Ls][\bcc3A378a?@s   ( 
BAB

BzFRun UV scripts (Python with inline dependencies) on HF infrastructure.uv)rO   )zhf jobs uv run my_script.pyz1hf jobs uv run ml_training.py --flavor a10g-smallz+hf jobs uv run --with transformers train.pyzFhf jobs uv run -v hf://gpt2:/data -v hf://buckets/org/b:/mnt script.pyscriptscript_argswith_pythonc                    [        XH5      n[        XY5      n[        US9nUR                  U U=(       d    / UUUUU[        U5      [	        U5      UU
US9n[        SUR                   35        [        SUR                   35        U(       a  gUR                  UR                  UR                  R                  SS9 H  n[        U5        M     g)8Run a UV script (local file or URL) on HF infrastructurerA   )r,  r-  dependenciesr/  r4   r6   r7   rB   rC   r<   r=   r#   rD   rE   NTrF   )r   r   
run_uv_jobrI   r   rJ   rK   rL   rM   rN   rO   )r,  r-  r4   r<   r6   r7   r8   r9   r:   r;   r=   r>   r#   r?   r.  r/  rP   rQ   rR   rS   rT   s                        r,   jobs_uv_runr4    s    : C*G6K
5
!C
..%2 'f%  C 
!#&&
*+	IcggY
 !!399>>RV!Wc
 Xr.   z,Create and manage scheduled Jobs on the Hub.	scheduledz>hf jobs scheduled run "0 0 * * *" python:3.12 python script.pyschedulesuspendconcurrencyc                     [        XY5      n[        Xj5      n[        US9nUR                  UUU UUUU[        U5      [	        U5      UUUS9n[        SUR                   35        g)zSchedule a Job.rA   )r4   r5   r6  r7  r8  r6   r7   rB   rC   r<   r=   r#   Scheduled Job created with ID: N)r   r   create_scheduled_jobrI   r   rJ   rK   )r6  r4   r5   r7  r8  r6   r7   r8   r9   r:   r;   r<   r=   r#   r?   rP   rQ   rR   scheduled_jobs                      r,   scheduled_runr=    s~    . C*G6K
5
!C,, 'f% - M 
+M,<,<+=
>?r.   zhf jobs scheduled psz1Show all scheduled Jobs (default hides suspended)c                 >   [        US9nUR                  US9n/ nU=(       d    /  H}  n	SU	;   ae  U	R                  SS5      u  pU
R                  S5      (       a  SnU
SS n
OSnUR	                  U
R                  5       XR                  5       45        Mn  [        S	U	 S
35        M     / nU H  nUR                  =(       d    SnU (       d	  U(       a  M(  UR                  R                  =(       d    SnUR                  R                  =(       d    / nU(       a  SR                  U5      OSnUR                  U[        U5      US.n[        UU5      (       d  M  UR	                  U5        M     U(       dj  U(       dQ  US:w  aK  U(       a3  SSR                  U VVVs/ s H  u  nnnU U U 3PM     snnn5       3OSn[        SU 35        gUS:X  a  [        S5        g/ SQn/ SQnU Vs/ s H  n[        U5      PM     nnS[         [        ["        4   S[$        [           4S jnU(       a,  US;  a&  ['        U Vs/ s H  nU" U5      PM     snUUU5        gUS:X  a  [(        R*                  O[(        R,                  n[/        UUUSUUS9  gs  snnnf s  snf s  snf )zList scheduled JobsrA   r   rg   r   r   rf   Nr   r   r   Fr   r   )rK   r4   r7  r5   r   r   r   r   zNo scheduled jobs foundr   )IDSCHEDULEr   r   zLAST RUNzNEXT RUNSUSPEND)rK   r6  r4   r5   lastnextr7  r   r$   c                    U R                  S0 5      nU R                  S0 5      nUR                  S5      nUR                  S5      =(       d    / nSnU(       a.  UR                  S5      (       a  US   S S R                  SS	5      nSnUR                  S
5      (       a  US
   S S R                  SS	5      nU(       a  S	R                  U5      OSn[        U R                  SS5      5      [        U R                  S5      =(       d    S5      [	        UR                  S5      =(       d    S5      [	        U5      UU[        U R                  SS5      5      /$ )Njob_specra   last_jobr5   r   atr   r   r   next_job_run_atrK   r   r6  r   r7  F)rh   rv   r   rw   r   )r   rE  ra   rF  r   last_job_atnext_runr   s           r,   r   scheduled_ps.<locals>.row_fn  s%   88J+(B'::j)ll9%+T**"4."-55c3?K::'((/0"5==c3GH'*chhsmr"#$-.n5>?%E*+
 	
r.   r   rK   r   )r   list_scheduled_jobsr)   r   r   ri   rJ   r7  rE  r   r5   r   rK   rw   ro   r   r   r   r   r   r   r   r   r    )r   r#   r?   r   r   r   rR   scheduled_jobsrd   r   rj   rm   r   r   r<  r7  r   r   r   r   r   r   r   r   rq   rr   sjr   r   r   r   s                                  r,   scheduled_psrO  G  so   6 5
!C,,y,AN*,G\r\!8aJC||C  #2hNNCIIK[[];<=aS@XYZ  M'''05w&//<<E$$,,2'*chhsm$''.SQX\fqrw//]+ ( 6)fm/		W^:_W^GAqRSaSA3<W^:_0`/absuK+K=9: 	 v$K]GOG.;<m#mE<
T#s(^ 
S	 
. & 116vd|6&Q-3v-=))<CUCU 	
K ;` =4 7s   J*J<Jzhf jobs scheduled inspect <id>scheduled_job_idsz>Scheduled Job IDs to inspect (or 'namespace/scheduled_job_id')c           
      8   / nU  H!  n[        XA5      u  pAUR                  U5        M#     Un [        US9nU  Vs/ s H  nUR                  XaS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 )z:Display detailed information on one or more scheduled JobsrA   scheduled_job_idr#   r   r!  N)	r-   r   r   inspect_scheduled_jobrJ   r   r%  r   rw   )	rP  r#   r?   r   r"   rR   rS  rM  r<  s	            r,   scheduled_inspectrU    s     J#8K&! $ #
5
!C !2 1 	!!3C!Y 1   
$**Pf]+PYZdg
hi	 Qs   B-Bdeletezhf jobs scheduled delete <id>rS  c                 N    [        X5      u  p[        US9nUR                  XS9  g)zDelete a scheduled Job.rA   rR  N)r-   r   delete_scheduled_jobrS  r#   r?   rR   s       r,   scheduled_deleterZ    /     #??O"[
5
!C.>Tr.   zhf jobs scheduled suspend <id>c                 N    [        X5      u  p[        US9nUR                  XS9  g)z Suspend (pause) a scheduled Job.rA   rR  N)r-   r   suspend_scheduled_jobrY  s       r,   scheduled_suspendr^    s/     #??O"[
5
!C/?Ur.   resumezhf jobs scheduled resume <id>c                 N    [        X5      u  p[        US9nUR                  XS9  g)z!Resume (unpause) a scheduled Job.rA   rR  N)r-   r   resume_scheduled_jobrY  s       r,   scheduled_resumerb    r[  r.   z)Schedule UV scripts on HF infrastructure.z.hf jobs scheduled uv run "0 0 * * *" script.pyz<hf jobs scheduled uv run "0 0 * * *" script.py --with pandasc                     [        X{5      n[        X5      n[        US9nUR                  UU=(       d    / U UUUUUUU[        U	5      [	        U
5      UUUS9n[        SUR                   35        g)r1  rA   )r,  r-  r6  r7  r8  r2  r/  r4   r6   r7   rB   rC   r<   r=   r#   r:  N)r   r   create_scheduled_uv_jobrI   r   rJ   rK   )r6  r,  r-  r7  r8  r4   r<   r6   r7   r8   r9   r:   r;   r=   r#   r?   r.  r/  rP   rQ   rR   rS   s                         r,   scheduled_uv_runre    s    : C*G6K
5
!C

%
%%2 'f% & C" 
+CFF8
45r.   rB   c                 p    U (       d  g0 nU  H%  nSU;   a  UR                  SS5      OUS4u  p4XAU'   M'     U$ )zParse label key-value pairs from CLI arguments.

Args:
    labels: List of label strings in KEY=VALUE format. If KEY only, then VALUE is set to empty string.

Returns:
    Dictionary mapping label keys to values, or None if no labels provided.
Nrg   r   r   )r)   )rB   
labels_map	label_varrj   rm   s        r,   rI   rI   *  sH     !#J	03y0@Y__S!,yRTo
3  r.   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N)r   rw   ).0xs     r,   	<genexpr>_tabulate.<locals>.<genexpr>C  s     /3ac#a&kk3s   !#   r   z{{:{}}} -N   z...
)r   maxshutilget_terminal_sizecolumnsr   sumindexr   r   rw   r   )rp   rq   col
col_widthsterminal_widthcol_to_minimize
row_formatlineswrz   rm  	col_widthrow_format_argss                r,   rx   rx   <  s    <?;N;Ng;NO;NC#/3//;NJO113;;S\B=NON
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 r   queuefunc.kwargsc                 D    U" S0 UD6 H  nU R                  U5        M     g )N )put)r  r  r  results       r,   _write_generator_to_queuer  Z  s    ..		& !r.   r   r   c          	   #   F  #    [        5       nU Vs/ s H  o@R                  [        X1U45      PM     nn   UR                  SS9v   M  s  snf ! [         a1    [        S U 5       5      (       a  UR                  5       (       a   O NAf = f! [         a     Of = f U Vs/ s H  ofR                  SS9PM     Os  snf   ng! [        R                   a     gf = f!  U Vs/ s H  ofR                  SS9PM     Os  snf   nf ! [        R                   a     f f = f= f7f)a#  
Takes a function that returns an iterable of items, and run it in parallel using threads to return the flattened iterable of items as they arrive.

This is inspired by those three `map()` variants, and is the mix of all three:

* `imap()`: like `map()` but returns an iterable instead of a list of results
* `imap_unordered()`: like `imap()` but the output is sorted by time of arrival
* `flatmap()`: like `map()` but given a function which returns a list, `flatmap()` returns the flattened list that is the concatenation of all the output lists
g?)r=   c              3   @   #    U  H  oR                  5       v   M     g 7frk  )ready)rl  async_results     r,   rn  %iflatmap_unordered.<locals>.<genexpr>u  s     N))++s   N)
r	   apply_asyncr  rh   r   r   emptyKeyboardInterruptr   TimeoutError)r   r  r   r  r  async_resultsr  s          r,   r   r   _  s     gEfqrfq\b%%&?%vAVWfqMriii--  s
  NNNNSXS^S^S`S`  	@MNd+N++ 			@MNd+N++ 		s   D!!A
D!B A B 
D!6B
B C B 	B

B 
BC BC C "B;:C D!CD!CD!DD#C<;DDDDDDD!)NNNNNNNNFNN)FNNN)NNN)FNNNNF)r$   N)NN)NNNNNNNNNNFNNNN)NNNNNNNNNNNN)NNNNNNNNNNNNNNNN)p__doc__r   r   multiprocessing.poolru  r   collectionsr   collections.abcr   r   dataclassesr   r   r  r   r	   typingr
   r   r   typerhuggingface_hubr   huggingface_hub.errorsr   r   huggingface_hub.utilsr   $huggingface_hub.utils._cache_managerr   
_cli_utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   
get_logger__name__loggerrw   tupler-   rm   SUGGESTED_FLAVORSr   ArgumentImageArgOptionImageOpt	FlavorOptr   	LabelsOpt
TimeoutOptbool	DetachOptNamespaceOptWithOpt	PythonOpt
SuspendOptConcurrencyOptScheduleArg	ScriptArgScriptArgsArg
CommandArgJobIdArg	JobIdsArgScheduledJobIdArgjobs_clir5   rU   intrb   r   ro   r   r   r   r   r  r  r&  r*  uv_app	add_typerr4  scheduled_appr=  rO  rU  rZ  r^  rb  scheduled_uv_appre  rI   rx   r   r  r   r   r   )r   s   0r,   <module>r     s  0d       .    * *  ) ; ) =    & 
		H	%. .t .cSVY]S]oH^ .8 -:WMDZZ;=VZTZZMW   	NN' $J	LL= D	LL D	 I	LLB	 $J	LLe
 	LLB	 $J	LLe I	LL4 $J	LLD	 4K	LL0
 4K	LLG 	NNf 	NN3	 I	NN' I	NN"
 	NN- I	NN.	 	NNA  ?@ 
	.5  	 #'"''' 
' 	'
 ' ' ' !' ' ' ' ' ' 
'	'T 

m   	 	"'.D.D E	
	.D d
D	
	.D$ %.D& '.D( 
).D.DbT#s(^ d5cSVCW>X ]a 0T#)_- 0S	 0DQTI 0\_bf\f 0ko 0"'3 '4 '!)$sCx.!9JNs)eD#tDsO44568 
'%=$>?"SESESE SE 
	SE @SEl 
$,!@A 	" 	 	/w
	=	
	
w
 w
 w
 S	DQ	
	w
& d
gh	j'w
. /w
0 
1w
 Bw
t 
*(:';<> =>, 
)'A&BC #AS	=	
	A A A 
A DA< 
(&?%@A #@@@ @ 
	@ B@( 
d	e   6  % 	.5  	 "&#'"!,,, , 	,
 
, , , , , !, , , , , ,  !," 
#,	,^ #QR   ={  3 	.5NO   "&#'"$@$@$@ $@ 	$@
  $@ 
$@ $@ $@ $@ $@ !$@ $@ $@ $@ $@  
!$@
$@N t'=&>? 	" 	 	/f
	D	
	
f
 f
 f
 S	DQ	
	f
& d
gh	j'f
. /f
0 
1f
 @f
R y,L+MN #j S	Q	
	j j j 
j Oj0 x+J*KL #U'UU U 
	U MU y,L+MN #V'VV V 
	V OV x+J*KL #U'UU U 
	U MU !&QR    (t  4 	.58F   "&"&#'"%*6*6*6 *6 	*6
  *6 *6 *6 
*6 *6 *6 *6 *6 !*6 *6 *6  !*6" #*6$ %*6& 
'*6*6`d3i$. 4S>D3H $DcCi) DI # 6 CLU1X Xc8A;>N5O Y] bf 




)
)
3#
$ d	
 a[u Xs   /^^