+
    &jb                     t   R t ^ RIt^ RIt^ RIt^ RIt^ RIHtHt ^ RIHt ^ RI	H
t
Ht ^ RIHtHtHt ^ RIt^ RIHt ^ RIHtHt ^ RIHt ^ R	IHt ^ R
IHt ^RIHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t&H't' ^RI(H)t)H*t* ]PV                  ! ],4      t-R R lt.Rt/]]0]Pb                  ! RR7      3,          t2]]0R,          ]Pf                  ! RR7      3,          t4]]0R,          ]Pf                  ! R]!! ]4      R7      3,          t5]]6]0,          R,          ]Pf                  ! RRRR7      3,          t7]]0R,          ]Pf                  ! RR7      3,          t8]]9]Pf                  ! RRRR7      3,          t:]]0R,          ]Pf                  ! RR7      3,          t;]]6]0,          R,          ]Pf                  ! RRR7      3,          t<]]0R,          ]Pf                  ! RR R!R7      3,          t=]]9R,          ]Pf                  ! R"R7      3,          t>]]9R,          ]Pf                  ! R#R7      3,          t?]]0]Pb                  ! R$R7      3,          t@]]0]Pb                  ! R%R7      3,          tA]]6]0,          R,          ]Pb                  ! R&R7      3,          tB]]6]0,          ]Pb                  ! R'R7      3,          tC]]0]Pb                  ! R(R7      3,          tD]]6]0,          R,          ]Pb                  ! R)R7      3,          tE]]0]Pb                  ! R*R7      3,          tF]'! R+R7      tG]GP                  R,R-R./. ROR/7      RR0 R1 ll4       tI]GP                  R2. ROR37      RR4 R5 ll4       tJR6 R7 ltKR8 R9 ltLR: R; ltM]GP                  R<R=.R37      RR> R? ll4       tN]GP                  R@RARB.R37      RRC RD ll4       tO]GP                  RERF.R37      RG RH l4       tP]GP                  RIRJ.R37      RRK RL ll4       tQ]GP                  RMRN.R37      RRO RP ll4       tR]GP                  RQRRRS.R37      RRT RU ll4       tS]'! RVR7      tT]GP                  ]TRWRX7       ]TP                  R,R-R./. ROR/7      RRY RZ ll4       tV]'! R[R7      tW]GP                  ]WR\RX7       ]WP                  R,R-R./R].R/7      RR^ R_ ll4       tX]WP                  R@R`.R37      RRa Rb ll4       tY]WP                  RIRc.R37      RRd Re ll4       tZ]WP                  RfRg.R37      RRh Ri ll4       t[]WP                  RjRk.R37      RRl Rm ll4       t\]WP                  RnRo.R37      RRp Rq ll4       t]]WP                  RQRrRs.R37      RRt Ru ll4       t^]'! RvR7      t_]WP                  ]_RWRX7       ]_P                  R,R-R./RwRx.R/7      RRy Rz ll4       t`R{ R| ltaR} R~ ltb]! R4      tcR R ltdR R lteR# )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]

    # 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]

    # 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)CallableIterable)fnmatch)EmptyQueue)	AnnotatedAnyTypeVar)JobHardware)CLIErrorHfHubHTTPError)logging)_format_size)format_duration)
EnvFileOptEnvOptSecretsFileOpt
SecretsOpt
SoftChoiceTokenOpt
VolumesOpt
get_hf_apiparse_env_mapparse_volumestyper_factory)_dataclass_to_dictoutc          	      z    V ^8  d   QhR\         R\         R,          R\        \         \         R,          3,          /# )   job_id	namespaceNreturn)strtuple)formats   "p/Users/jameslopez/projects/CWCArchive/cwc-podcast/.venv/lib/python3.14/site-packages/huggingface_hub/cli/jobs.py__annotate__r&   d   s5     . . .t .cSVY]S]oH^ .    c                *   V '       g   \        R4      hV P                  R4      ^8  d   \        RV  R24      hRV 9  d   W3# V P                  R^4      w  r#V'       d	   V'       g   \        RV  R24      hVe   W8w  d   \        RV RV R24      hW23# )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./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   &&  r%   _parse_namespace_from_job_idr/   d   s     011||C1UV\U]]_`aa
&  )/c1)=&mUV\U]]_`aa!A6ykAabuavvwx
 	
 --r'   g?zThe Docker image to use.helpz.Use a custom Docker image with `uv` installed.zcFlavor for the hardware. Run 'hf jobs hardware' to list available flavors. Defaults to `cpu-basic`.)r1   
click_typez-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)context_settingsexamplesc                    V ^8  d   QhR\         R\        R\        R\        R\        R\
        R\        R\        R	\        R
\        R\        R\        R\        RR/# )r   imagecommandenvsecretslabelvolumeenv_filesecrets_fileflavortimeoutdetachr    tokenr!   N)ImageArg
CommandArgr   r   	LabelsOptr   r   r   	FlavorOpt
TimeoutOpt	DetachOptNamespaceOptr   )r$   s   "r%   r&   r&     s     $ $$$ 
$ 	$
 $ $ $ !$ $ $ $ $ $ 
$r'   c                   \        W&4      p\        W74      p\        VR7      pVP                  V VVV\        V4      \	        V4      VV	VR7	      p\
        P                  ! RVP                  VP                  R7       V
'       d'   \
        P                  ! RVP                   R24       R# VP                  VP                  VP                  P                  RR	7       F  p\
        P                  ! V4       K  	  R# )
z
Run a Job.rC   )	r8   r9   r:   r;   labelsvolumesr@   rA   r    Job startedidurlUse `hf jobs logs ` to fetch the logs.NTr   r    follow)r   r   run_job_parse_labels_mapr   r   resultrQ   rR   hintfetch_job_logsownernametext)r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   r    rC   env_mapsecrets_mapapijoblogs   &&&&&&&&&&&&&     r%   jobs_runrd     s    4 C*G6K
5
!C
++ 'f%  
C JJ}SWW5%cffX-ABC!!399>>RV!W Xr'   logs)r6   c                    V ^8  d   QhR\         R\        \        \        P                  ! RRRR7      3,          R\        \
        R,          \        P                  ! R	R
RR7      3,          R\        R\        RR/# )r   r   rV   -fz--followzqFollow log output (stream until the job completes). Without this flag, only currently available logs are printed.r0   tailNz-nz--tailzvNumber of lines to show from the end of the logs. When combined with --follow, starts streaming from the last N lines.r    rC   r!   )JobIdArgr   booltyperOptionintrJ   r   )r$   s   "r%   r&   r&   H  s     )D )D)D E	
	)D d
 J	
	)D$ %)D& ')D( 
))Dr'   c                z   \        W4      w  r\        VR7      p VP                  WWR7      pV F  p\        P                  ! V4       K  	  R#   \
         da   pTP                  e   TP                  P                  MRp	T	R8X  d   \        R4      ThT	R8X  d   \        R4      Th\        RT 24      ThRp?ii ; i)	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.
Use --tail/-n to limit the number of lines returned (server-side when supported).
rL   )r   r    rV   rh   N  '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[   r   r^   r   responsestatus_coder   )
r   rV   rh   r    rC   ra   re   rc   estatuss
   &&&&&     r%   	jobs_logsrw   ?  s    H 5VGF
5
!CD!!V!_CHHSM  D+,::+A''tS=DE1Ls]YZ`aa7s;<!CDs   2A B:AB55B:c                    V ^8  d   QhR\         \        \        3,          R\        \        \        \        \        3,          ,          R\        /# )r   job_propertiesfiltersr!   )dictr"   listr#   rj   )r$   s   "r%   r&   r&   t  s;      T#s(^ d5cSVCW>X ]a r'   c                    V Fr  w  r#pV P                  V4      pVf   VR8X  d   K$   R# \        VP                  4       VP                  4       4      pVR8X  d	   V'       d   VR8X  g   Kg  V'       g   Kq   R# 	  R# )z5Check if scheduled job matches all specified filters.!=F=T)getr   lower)ry   rz   keyop_strpatternvaluematchs   &&     r%   _matches_filtersr   t  sf     'W""3'=~w}}7cM%Vt^ !( r'   c                (    V ^8  d   QhR\         RR/# )r   nr!   N)rm   )r$   s   "r%   r&   r&     s     ' '3 '4 'r'   c                 J    R pRp\        V 4       F  p\        WR7       K  	  R# )z[1Az[2K)endN)rangeprint)r   LINE_UP
LINE_CLEARis   &   r%   _clear_liner     s"    GJ1Xg& r'   c                   V ^8  d   QhR\         R\        \        \         \        3,          ,          R\        \         ,          R\        \
        \        \         \        \        \         \        ,          ,          ,          3,          ,          /# )r   r   metrics_streamtable_headersr!   )r"   r   r{   r   r|   r#   rj   rm   )r$   s   "r%   r&   r&     s[      !)$sCx.!9JNs)eD#tDsO4456r'   c              #     "   V EF  pV VR ,           R2\        VR,          R,          ^4      \        ^dVR,          ,          VR,          ,          ^4       R2\        VR,          4       R\        VR,          4       R2\        VR,          4       R	\        VR
,          4       R2.pVR,          '       d   \        VR,          \        4      '       d   V.R.\	        V4      ,          .\	        VR,          4      ^,
          ,          ,           p\        V\        VR,          4      4       Fz  w  rFVR,          V,          pVVR,           R2\        ^dVR,          ,          VR,          ,          ^4       R2\        VR,          4       R\        VR,          4       R2.,          pK|  	  M-VR.\	        V4      \	        V4      ,
          ,          ,          pV.pRW3x  EK  	  RV . 3x  R# 5i)cpu_usage_pct%cpu_millicoresg     @@memory_used_bytesmemory_total_byteszB / Brx_bpszbps / tx_bpsbpsgpus utilizationN/AFTN)roundr   
isinstancer{   lenzipsorted)r   r   r   metricsrowrows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   G(G*statszhf jobs stats <job_id>c                @    V ^8  d   QhR\         R\        R\        RR/# )r   job_idsr    rC   r!   N)	JobIdsArgrJ   r   )r$   s   "r%   r&   r&     s<     JE JEJEJE JE 
	JEr'   c                N   V e,   . pV  F!  p\        WA4      w  rAVP                  V4       K#  	  Tp \        VR7      pVf   VP                  4       R,          pV f]   VP	                  VR7       Uu. uF@  pVP
                  '       d   VP
                  P                  MRR9   g   K4  VP                  NKB  	  p p\        V 4      ^ 8X  d   \        P                  ! R4       R# . ROp \        P                  P                  \        V 4      4      ;_uu_ 4       p/ p	V  F:  pV.p
YR,           Uu. uF  pRV9   g   R	V9   d   R
MRNK  	  up,          p
V
.W&   K<  	  \        P                  ! 4       pV	 UU
u. uF  qIV,           F  qNK  	  K  	  ppp
\        \!        WR7      4       V  Uu. uF  pRVRVP#                  WAR7      RV/NK  	  pp\%        V\&        VR7       F  w  rpV'       d   V	P)                  VR4       MVW&   \        P                  ! 4       pVV,
          \*        8  g   KN  \-        ^\        V4      ,           4       V	 UU
u. uF  qIV,           F  qNK  	  K  	  ppp
\        \!        WR7      4       TpK  	  RRR4       R# u upi u upi u up
pi u upi u up
pi   + '       g   i     R# ; i  \.         da   pTP0                  e   TP0                  P2                  MRpTR8X  d   \5        R4      ThTR8X  d   \5        R4      Th\5        RT 24      ThRp?ii ; i)z7Fetch the resource usage statistics and metrics of JobsNrL   r]   r    UNKNOWNzNo running jobs found:   NNr)   USAGEz-- / --z--)headersr   r   r   r    r   )kwargs_listro   rp   rq   rr   zFailed to fetch job stats: RUNNINGUPDATING)	zJOB IDzCPU %zNUM CPUzMEM %z	MEM USAGEzNET I/Oz
GPU UTIL %z	GPU MEM %zGPU MEM USAGE)r/   appendr   whoami	list_jobsrv   stagerQ   r   r   r^   multiprocessingpool
ThreadPooltimer   	_tabulatefetch_job_metricsiflatmap_unorderedr   popSTATS_UPDATE_MIN_INTERVALr   r   rs   rt   r   )r   r    rC   
parsed_idsr   ra   rb   r   r   rows_per_job_idr   headerlast_update_time
total_rowsr   doner   nowru   rv   s   &&&                 r%   
jobs_statsr     s    
F <V OFf%  
5
!CJJL(	 }}y}9
9$'JJJ

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

 7|q()
M'E!!,,S\::d@BO!(.xprbstbsX^cVmw&7H	tSbstt+.%' "  $yy{,;_O&W]G^G^#G^#OJ_ )J>? & &F	 f$c&;&;6&;&_#]
 &   '9?Sal&m"d#''5.2O+iik))-FFC
O 344C!gO&_eOfOf#Of#OJ!g)JFG'*$ 'n) ;:)
0 u `
  "h9 ;::>  E+,::+A''tS=DE1Ls]YZ`aa8<=1DEs   /J
J
%J
$0J9 J%*J,J%1J

J%&!JAJ%) J%	J"J% J9 J%%J6	0J9 6J9 9L$ALL$psz
hf jobs pszhf jobs ps -ac                    V ^8  d   QhR\         \        \        P                  ! RRRR7      3,          R\        R\
        R\         \        \        ,          R	,          \        P                  ! R
RRR7      3,          RR	/# )r   all-a--allz*Show all Jobs (default shows just running)r0   r    rC   filterNrg   --filter>Filter output based on conditions provided (format: key=value)r!   r   rj   rk   rl   rJ   r   r|   r"   )r$   s   "r%   r&   r&     s     `< `<	=	
	
`< `< `< S	DQ	
	`<& 
'`<r'   c           	        \        VR7      pVP                  VR7      p. p. pT;'       g    .  EF  pVP                  R4      '       g   VP                  R4      '       d   VP                  R4      '       d8   V\        R4      R p	RV	9   d   \        P
                  ! RV	 R24       Kz  T	R	R
rp
MNV\        R4      R p	RV	9   d   V	P                  R^4      w  rMT	R
rV
P                  R4      '       d	   R	pV
RR% p
MRpVP                  V
P                  4       WP                  4       34       K  RV9   dh   VP                  R^4      w  rVP                  R4      '       d	   R	pVRR% pMRpVP                  VP                  4       WP                  4       34       EKm  \        P
                  ! RV R24       EK  	  . pV F  pVP                  '       d   VP                  P                  MRpV '       g
   VR&9  d   K>  VP                  ;'       g    RpVP                  ;'       g    . pV'       d   RP                  V4      MRpRVP                  RVRVP                  4       RV/p\!        VV4      '       g   K  \!        VP"                  ;'       g    / V4      '       g   K  VP                  V4       K  	  . pV EF.  p\%        V4      pVP'                  R4      ;'       g    / pVP'                  R4      ;'       g    . pVP'                  RR4      VR&   VP'                  R4      ;'       g    RVR&   V'       d   RP                  V4      MRVR&   VP'                  R4      '       d!   VR,          R,          P)                  RR4      MRVR&   VP'                  R4      ;'       g    / P'                  RR4      VR&   \+        VP'                  R4      4      VR &   VP                  V4       EK1  	  \        P,                  ! V. R'ORR!7       V'       g>   V'       d4   R"P                  R# V 4       4      p\        P.                  ! R$V 24       R# R# R# )(z
List Jobs.rL   r   zlabel!=zlabel=Nr   z-Ignoring invalid label filter format 'label!=z'. Use label!=key format.r~   *! Ignoring invalid filter format ''. Use key=value format.r   r    rQ   r8   rv   r9   	durationsr   r   docker_imageimage/space
created_atN   NTcreatedr   running_secsruntimer   id_key, c              3   6   "   T F  w  rq1 V V 2x  K  	  R # 5iN .0kovs   &   r%   	<genexpr>jobs_ps.<locals>.<genexpr>S       DGq#aSG   zNo jobs matched filters: r   )r   r   r9   r   rv   r   )r   r   
startswithr   r   warningr,   endswithr   r   rv   r   r   r9   joinrQ   r   rM   r   r   replacer   tabler^   )r   r    rC   r   ra   jobsrz   labels_filtersf
label_part	label_keyoplabel_valuer   r   filtered_jobsrb   rv   image_or_spacecmdcommand_strpropsitemsitemr   filters_msgs   &&&&                      r%   jobs_psr    s   , 5
!C==9=-D*,G13N\\r\<<	""all8&<&<||I&&s9~/0
*$KK"OPZ|[t 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[[];<KK:1#=UVW? D M%(ZZZ!!Yv%<<))22UkkR'*chhsmsvvw&,,.R[]hiw//

 0 0b.AAS!  #%E!#&HH[)//R	hhy!''R$+X"hh~6??%]+.#((3-EYGKxxP\G]G]$|,S199#sCchY((8,2277KX))--*GHYT  IIT
 WiiDGDD,[M:; 5r'   hardwarezhf jobs hardwarec                    V ^8  d   QhRR/# )r   r!   Nr   )r$   s   "r%   r&   r&   X  s     ] ]t ]r'   c                    \        4       p V P                  4       p. pV EF  pRpVP                  '       dH   VP                  P                   RVP                  P                   RVP                  P
                   R2pVP                  '       d   RVP                  R 2MRpVP                  '       d   RVP                  ^<,          R 2MRpVP                  R	VP                  R
VP                  RVP                  RVP                  RVP                  RVRVRV/4       EK  	  \        P                  ! V4       \        P                  ! R4       R# )z(List available hardware options for Jobsr   zx z ()$z.4ffreez.2fr]   zpretty namecpuramstorageacceleratorzcost/minz	cost/hourzLUse `hf jobs run --flavor <name> ...` to request a specific hardware flavor.N)r   list_jobs_hardwarer  quantitymodelvramunit_cost_usdr   r]   pretty_namer  r  ephemeral_storager   r   rZ   )ra   hardware_listr  hwaccelerator_infocost_min	cost_hours          r%   jobs_hardwarer'  W  s*    ,C**,ME>>>"$.."9"9!:"R^^=Q=Q<RRTUWUcUcUhUhTiijk131A1A1AQr'',-v797G7G7Ga((2-c23V	r~~rvvrvv2///HY		
 $ IIeHH[\r'   inspectzhf jobs inspect <job_id>c                    V ^8  d   QhR\         \        \        ,          \        P                  ! RR7      3,          R\
        R\        RR/# )r   r   z*Job IDs to inspect (or 'namespace/job_id')r0   r    rC   r!   Nr   r|   r"   rk   ArgumentrJ   r   )r$   s   "r%   r&   r&   t  sR     9 9S	=	
	9 9 9 
9r'   c                   . pV  F!  p\        WA4      w  rAVP                  V4       K#  	  Tp \        VR7      p V  Uu. uF  qEP                  WAR7      NK  	  pp\        P                  ! T U	u. uF  p	\        T	4      NK  	  up	4       R# u upi   \         da   pTP
                  e   TP
                  P                  MRpTR8X  d   \        R4      ThTR8X  d   \        R4      Th\        RT 24      ThRp?ii ; iu up	i )	z0Display detailed information on one or more JobsrL   r   Nro   rp   rq   rr   zFailed to inspect job: )r/   r   r   inspect_jobr   rs   rt   r   r   r   r   )
r   r    rC   r   r   ra   r  ru   rv   rb   s
   &&&       r%   jobs_inspectr.  s  s     J8K&!  G
5
!C	ARYZRYvCRYZ II$7$3!#&$78 [ A+,::+A''tS=DE1Ls]YZ`aa4QC89q@A 8s/   B B
B -C=
B C:AC55C:cancelzhf jobs cancel <job_id>c                @    V ^8  d   QhR\         R\        R\        RR/# )r   r   r    rC   r!   N)ri   rJ   r   )r$   s   "r%   r&   r&     s0     + +++ + 
	+r'   c                j   \        W4      w  r\        VR7      p VP                  WR7       \        P                  ! R	T R
7       R#   \         da   pTP                  e   TP                  P
                  MRpTR8X  d   \        R4      ThTR8X  d   \        R4      Th\        RT 24      ThRp?ii ; i)zCancel a JobrL   r   Nro   rp   rq   z>Access denied. You may not have permission to cancel this job.zFailed to cancel job: zJob cancelledrQ   )	r/   r   
cancel_jobr   rs   rt   r   r   rY   )r   r    rC   ra   ru   rv   s   &&&   r%   jobs_cancelr4    s     5VGF
5
!C	@f: JJ6*  @+,::+A''tS=DE1Ls][\bcc3A378a?@s   A B2AB--B2rM   z8hf jobs labels <job_id> --label env=prod --label team=mlzhf jobs labels <job_id> --clearc                    V ^8  d   QhR\         R\        R\        \        \        P
                  ! RRR7      3,          R\        R\        R	R
/# )r   r   r<   clear--clearzRemove all labels from the job.r0   r    rC   r!   N)ri   rF   r   rj   rk   rl   rJ   r   )r$   s   "r%   r&   r&     sZ     , ,,, T5<<	8YZZ[, 	,
 , 
,r'   c                8   V'       g   V'       g   \        R4      hV'       d   V'       d   \        R4      h\        W4      w  r\        V4      ;'       g    / p\        VR7      pVP	                  WVR7      p\
        P                  ! RVP                  R7       R# )z5Update labels on a Job. Replaces all existing labels.OPlease set at least one label with --label. To remove all labels, pass --clear.bCannot set labels and clear them at the same time. Please use either --label or --clear, not both.rL   )r   rM   r    Labels updatedr2  N)r   r/   rX   r   update_job_labelsr   rY   rQ   )r   r<   r6  r    rC   rM   ra   rb   s   &&&&&   r%   jobs_labelsr=    s}     hiip
 	
 5VGFu%++F
5
!C


v	

RCJJCFF+r'   zFRun UV scripts (Python with inline dependencies) on HF infrastructure.uv)r]   c          "          V ^8  d   QhR\         R\        R\        R\        R\        R\
        R\        R\        R	\        R
\        R\        R\        R\        R\        R\        R\        RR/# )r   scriptscript_argsr8   r@   r:   r;   r<   r=   r>   r?   rA   rB   r    rC   with_pythonr!   N)	ScriptArgScriptArgsArgImageOptrG   r   r   rF   r   r   r   rH   rI   rJ   r   WithOpt	PythonOpt)r$   s   "r%   r&   r&     s     * *** * 	*
 
* * * * * !* * * * * *  !*" 
#*r'   c                   \        WH4      p\        WY4      p\        VR7      pTP                  T T;'       g    . VVVVV\        V4      \	        V4      VV
VR7      p\
        P                  ! RVP                  VP                  R7       V'       d'   \
        P                  ! RVP                   R24       R# VP                  VP                  VP                  P                  RR	7       F  p\
        P                  ! V4       K  	  R# )
8Run a UV script (local file or URL) on HF infrastructurerL   )r@  rA  dependenciesrC  r8   r:   r;   rM   rN   r@   rA   r    rO   rP   rS   rT   NTrU   )r   r   
run_uv_jobrX   r   r   rY   rQ   rR   rZ   r[   r\   r]   r^   )r@  rA  r8   r@   r:   r;   r<   r=   r>   r?   rA   rB   r    rC   rB  rC  r_   r`   ra   rb   rc   s   &&&&&&&&&&&&&&&&     r%   jobs_uv_runrM    s    : C*G6K
5
!C
..%%2 'f%  C JJ}SWW5%cffX-ABC!!399>>RV!W Xr'   z,Create and manage scheduled Jobs on the Hub.	scheduledz>hf jobs scheduled run "0 0 * * *" python:3.12 python script.pyc                     V ^8  d   QhR\         R\        R\        R\        R\        R\
        R\        R\        R	\        R
\        R\        R\        R\        R\        R\        RR/# )r   scheduler8   r9   suspendconcurrencyr:   r;   r<   r=   r>   r?   r@   rA   r    rC   r!   N)ScheduleArgrD   rE   
SuspendOptConcurrencyOptr   r   rF   r   r   r   rG   rH   rJ   r   )r$   s   "r%   r&   r&     s     %Y %Y%Y%Y %Y 	%Y
  %Y 
%Y %Y %Y %Y %Y !%Y %Y %Y %Y %Y  
!%Yr'   c                4   \        WY4      p\        Wj4      p\        VR7      pVP                  VVV VVVV\        V4      \	        V4      VVVR7      p\
        P                  ! RVP                  R7       \
        P                  ! RVP                   R24       R# )zSchedule a Job.rL   )r8   r9   rP  rQ  rR  r:   r;   rM   rN   r@   rA   r    Scheduled Job createdr2  Use `hf jobs scheduled inspect ` to view its details.N)	r   r   create_scheduled_jobrX   r   r   rY   rQ   rZ   )rP  r8   r9   rQ  rR  r:   r;   r<   r=   r>   r?   r@   rA   r    rC   r_   r`   ra   scheduled_jobs   &&&&&&&&&&&&&&&    r%   scheduled_runr\    s    . C*G6K
5
!C,, 'f% - M JJ&=+;+;<HH.}/?/?.@@VWXr'   zhf jobs scheduled psc                    V ^8  d   QhR\         \        \        P                  ! RRRR7      3,          R\        R\
        R\         \        \        ,          R	,          \        P                  ! R
RRR7      3,          RR	/# )r   r   r   r   z1Show all scheduled Jobs (default hides suspended)r0   r    rC   r   Nrg   r   r   r!   r   )r$   s   "r%   r&   r&   1  s     KF KF	D	
	
KF KF KF S	DQ	
	KF& 
'KFr'   c           	        \        VR7      pVP                  VR7      p. pT;'       g    .  F  pRV9   dg   VP                  R^4      w  rVP                  R4      '       d	   Rp
VRR pMRp
VP	                  VP                  4       WP                  4       34       Kp  \        P                  ! RV R24       K  	  . pV F  pVP                  ;'       g    R	pV '       g   V'       d   K+  VP                  P                  ;'       g    R
pVP                  P                  ;'       g    . pV'       d   RP                  V4      MR
pRVP                  RVR\        V4      RV/p\        VV4      '       g   K  VP	                  V4       K  	  . pV EF\  p\!        V4      pVP#                  R4      ;'       g    / pVP#                  R4      ;'       g    / pVP#                  R4      pVP#                  R4      ;'       g    . pVP#                  R4      ;'       g    R
VR&   V'       d   RP                  V4      MR
VR&   V'       d8   VP#                  R4      '       d!   VR,          R,          P%                  RR4      MR
VR&   VP#                  R4      '       d!   VR,          R,          P%                  RR4      MR
VR&   VP#                  R4      ;'       g    R	VR&   VP	                  V4       EK_  	  \        P&                  ! V. R ORR7       V'       g>   V'       d4   RP                  R V 4       4      p\        P(                  ! RV 24       R# R# R# )!zList scheduled JobsrL   r   r   r   r~   Nr   r   Fr   r   rQ   r8   rQ  r9   job_specrv   last_jobr   r   atr   r   last_runnext_job_run_atnext_runr   r   c              3   6   "   T F  w  rq1 V V 2x  K  	  R # 5ir   r   r   s   &   r%   r   scheduled_ps.<locals>.<genexpr>{  r   r   z#No scheduled jobs matched filters: r   )rQ   rP  r   r9   rb  rd  rQ  )r   list_scheduled_jobsr,   r   r   r   r   r   rQ  r_  r   r9   r   rQ   r"   r   r   r   r   r   r^   )r   r    rC   r   ra   scheduled_jobsrz   r  r   r   r  r  r[  rQ  r	  r
  r  r  r  sjr  r_  status_dictr`  r  s   &&&&                     r%   scheduled_psrk  0  s   , 5
!C,,y,AN*,G\\r\!8aJC||C  #2hNNCIIK[[];<KK:1#=UVW  M'''005w&//<<EE$$,,22'*chhsm}''.)SQX\[dfqrw//]+ ( #%E!"%88J'--2hhx(..B??:.ll9%++&ll>:CCe]+.#((3-EYDLQYQ]Q]^bQcQc8D>#.66sC@inZEP__UfEgEgK)*3/77SAmr 	Z ((9-66YT  II_
 WiiDGDD6{mDE 5r'   zhf jobs scheduled inspect <id>c                    V ^8  d   QhR\         \        \        ,          \        P                  ! RR7      3,          R\
        R\        RR/# )r   scheduled_job_idsz>Scheduled Job IDs to inspect (or 'namespace/scheduled_job_id')r0   r    rC   r!   Nr*  )r$   s   "r%   r&   r&     sX     W W S	Q	
	W W W 
Wr'   c                (   . pV  F!  p\        WA4      w  rAVP                  V4       K#  	  Tp \        VR7      pV  Uu. uF  pVP                  WaR7      NK  	  pp\        P
                  ! V Uu. uF  p\        V4      NK  	  up4       R# u upi u upi )z:Display detailed information on one or more scheduled JobsrL   scheduled_job_idr    N)r/   r   r   inspect_scheduled_jobr   r   r   )	rm  r    rC   r   r   ra   rp  rh  r[  s	   &&&      r%   scheduled_inspectrr    s     J#8K&! $ #
5
!C !2 1 	!!3C!Y 1   IInUn]!-0nUV	 Vs   B
-Bdeletezhf jobs scheduled delete <id>c                @    V ^8  d   QhR\         R\        R\        RR/# r   rp  r    rC   r!   NScheduledJobIdArgrJ   r   )r$   s   "r%   r&   r&     0     	= 	='	=	= 	= 
		=r'   c                    \        W4      w  r\        VR7      pVP                  WR7       \        P                  ! RV R7       R# )zDelete a scheduled Job.rL   ro  zScheduled Job deletedr2  N)r/   r   delete_scheduled_jobr   rY   rp  r    rC   ra   s   &&& r%   scheduled_deleter|    ?     #??O"[
5
!C.>TJJ&+;<r'   rQ  zhf jobs scheduled suspend <id>c                @    V ^8  d   QhR\         R\        R\        RR/# ru  rv  )r$   s   "r%   r&   r&     s6     
Q 
Q'
Q
Q 
Q 
	
Qr'   c                    \        W4      w  r\        VR7      pVP                  WR7       \        P                  ! RV R7       \        P
                  ! RV  R24       R# )z Suspend (pause) a scheduled Job.rL   ro  zScheduled Job suspendedr2  zUse `hf jobs scheduled resume z` to resume it.N)r/   r   suspend_scheduled_jobr   rY   rZ   r{  s   &&& r%   scheduled_suspendr    sW     #??O"[
5
!C/?UJJ(-=>HH-.>-?OPr'   resumezhf jobs scheduled resume <id>c                @    V ^8  d   QhR\         R\        R\        RR/# ru  rv  )r$   s   "r%   r&   r&     rx  r'   c                    \        W4      w  r\        VR7      pVP                  WR7       \        P                  ! RV R7       R# )z!Resume (unpause) a scheduled Job.rL   ro  zScheduled Job resumedr2  N)r/   r   resume_scheduled_jobr   rY   r{  s   &&& r%   scheduled_resumer    r}  r'   z>hf jobs scheduled labels <id> --label env=prod --label team=mlz%hf jobs scheduled labels <id> --clearc                    V ^8  d   QhR\         R\        R\        \        \        P
                  ! RRR7      3,          R\        R\        R	R
/# )r   rp  r<   r6  r7  z)Remove all labels from the scheduled job.r0   r    rC   r!   N)rw  rF   r   rj   rk   rl   rJ   r   )r$   s   "r%   r&   r&     sZ     6 6'66 T5<<	8cdde6 	6
 6 
6r'   c                8   V'       g   V'       g   \        R4      hV'       d   V'       d   \        R4      h\        W4      w  r\        V4      ;'       g    / p\        VR7      pVP	                  WVR7      p\
        P                  ! RVP                  R7       R# )z?Update labels on a scheduled Job. Replaces all existing labels.r9  r:  rL   )rp  rM   r    r;  r2  N)r   r/   rX   r   update_scheduled_job_labelsr   rY   rQ   )rp  r<   r6  r    rC   rM   ra   r[  s   &&&&&   r%   scheduled_labelsr    s     hiip
 	
 #??O"[u%++F
5
!C33)I 4 M JJM$4$45r'   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          &          V ^8  d   QhR\         R\        R\        R\        R\        R\
        R\        R\        R	\        R
\        R\        R\        R\        R\        R\        R\        R\         R\"        RR/# )r   rP  r@  rA  rQ  rR  r8   r@   r:   r;   r<   r=   r>   r?   rA   r    rC   rB  rC  r!   N)rS  rD  rE  rT  rU  rF  rG   r   r   rF   r   r   r   rH   rJ   r   rG  rH  )r$   s   "r%   r&   r&     s     +O +O+O+O +O 	+O
  +O +O +O 
+O +O +O +O +O !+O +O +O  !+O" #+O$ %+O& 
'+Or'   c                N   \        W{4      p\        W4      p\        VR7      pTP                  TT;'       g    . V VVVVVVV\        V	4      \	        V
4      VVVR7      p\
        P                  ! RVP                  R7       \
        P                  ! RVP                   R24       R# )rJ  rL   )r@  rA  rP  rQ  rR  rK  rC  r8   r:   r;   rM   rN   r@   rA   r    rW  r2  rX  rY  N)	r   r   create_scheduled_uv_jobrX   r   r   rY   rQ   rZ   )rP  r@  rA  rQ  rR  r8   r@   r:   r;   r<   r=   r>   r?   rA   r    rC   rB  rC  r_   r`   ra   rb   s   &&&&&&&&&&&&&&&&&&    r%   scheduled_uv_runr    s    : C*G6K
5
!C

%
%%%2 'f% & C" JJ&3662HH.svvh6LMNr'   c                    V ^8  d   QhR\         \        ,          R,          R\        \        \        3,          R,          /# )r   rM   Nr!   )r|   r"   r{   )r$   s   "r%   r&   r&     s0      d3i$. 4S>D3H r'   c                v    V '       g   R# / pV  F&  pRV9   d   VP                  R^4      MVR3w  r4WAV&   K(  	  V# )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.
Nr   r   )r,   )rM   
labels_map	label_varr   r   s   &    r%   rX   rX     sH     !#J	03y0@Y__S!,yRTo
3  r'   c                    V ^8  d   QhR\         \         \        \        ,          ,          ,          R\         \        ,          R\        /# )r   r   r   r!   )r|   r"   rm   )r$   s   "r%   r&   r&   -  s2      DcCi) DI # r'   c           
     L   \        . V OVN5!   Uu. uF  p\        R V 4       4      NK  	  pp\        \        P                  ! 4       P                  \        V4      ^,          4      p\        V4      \        V4      ,           V8  d   VP                  \        V4      4      pW5;;,          ^,          uu&   \        V4      \        V4      ,           V8:  g   Kp  V\        V4      ,
          \        V4      ,
          W5,          ,           W5&   K  R\        V4      ,          P                  ! V!  p. pVP                  VP                  ! V!  4       TP                  VP                  ! V Uu. uF  pRV,          NK  	  up!  4       V  F~  p	\        W4       U
Uu. uFE  w  r\        \        V
4      4      V8  d   \        V
4      RV^,
           R,           M
\        V
4      NKG  	  pp
pVP                  VP                  ! V!  4       K  	  RP                  V4      # u upi u upi u upp
i )zy
Inspired by:

- stackoverflow.com/a/8356620/593036
- stackoverflow.com/questions/9535954/printing-lists-as-tabular-data
c              3   J   "   T F  p\        \        V4      4      x  K  	  R # 5ir   )r   r"   )r   xs   & r%   r   _tabulate.<locals>.<genexpr>4  s     /3ac#a&kk3s   !#z{{:{}}} -Nz...
)r   maxshutilget_terminal_sizecolumnsr   sumindexr$   r   r"   r   )r   r   col
col_widthsterminal_widthcol_to_minimize
row_formatlineswr   r  	col_widthrow_format_argss   &&           r%   r   r   -  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's7|+33Z@JE	LL""G,-	LL""j$AjS1WWj$ABC !$C 4
 4 033q6{Y/FCF?Y]#e+CPQFR 4 	 
 	Z&&89  99U# P %B
s   H&HAH r   c                    V ^8  d   QhR\         \        ,          R\        R\        \        ,          3,          R\        RR/# )r   queuefunc.kwargsr!   N)r   r   r   r   r{   )r$   s   "r%   r&   r&   K  s<      U1X Xc8A;>N5O Y] bf r'   c                 F    V! R/ VB  F  pV P                  V4       K  	  R # )Nr   )put)r  r  r  rY   s   &&& r%   _write_generator_to_queuer  K  s    ..		& !r'   c          	          V ^8  d   QhR\         P                  P                  R\        R\        \
        ,          3,          R\        \        ,          R\        \
        ,          /# )r   r   r  .r   r!   )r   r   r   r   r   r   r|   r{   )r$   s   "r%   r&   r&   P  sR      



)
)
3#
$ d	
 a[r'   c          	   #    "   \        4       pV Uu. uF  q@P                  \        W1V34      NK  	  pp   VP                  RR7      x  K  u upi   \         dZ    \
        ;QJ d    R T 4       F  '       d   K   RM	  RM! R T 4       4      '       d   TP                  4       '       d    M K}   K  i ; i  \         d     Mi ; i T Uu. uF  qfP                  RR7      NK  	  Mu upi  pR#   \        P                   d     R# i ; i   T Uu. uF  qfP                  RR7      NK  	  Mu upi  pi   \        P                   d     i i ; i; i5i)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
Tg?)rA   c              3   @   "   T F  qP                  4       x  K  	  R # 5ir   )ready)r   async_results   & r%   r   %iflatmap_unordered.<locals>.<genexpr>f  s     N))++s   FN)
r   apply_asyncr  r   r   r   emptyKeyboardInterruptr   TimeoutError)r   r  r   r  r  async_resultsr  s   &&$    r%   r   r   P  s0     gEfqrfq\b%%&?%vAVWfqMriii--	 s
  3NN333NNNNSXS^S^S`S` TaN  	@MNd+N++ 			@MNd+N++ 		s   E AEB8 A 
B8 EB5'B5;B5B5,B8 -D .B8 4B55B8 8CD CD 
C2 C)(C2 0E2DE
DEED7D/.D76E7EEEEE)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.pyz^hf jobs run -v hf://org/my-model:/data -v hf://buckets/org/b:/mnt python:3.12 python script.py)NNNNNNNNFNN)zhf jobs logs <job_id>zhf jobs logs -f <job_id>zhf jobs logs --tail 20 <job_id>z#hf jobs logs -f --tail 100 <job_id>)FNNN)NNN)NN)NFNN)zhf jobs uv run my_script.pyz1hf jobs uv run ml_training.py --flavor a10g-smallz+hf jobs uv run --with transformers train.pyzNhf jobs uv run -v hf://org/my-model:/data -v hf://buckets/org/b:/mnt script.py)NNNNNNNNNNFNNNN)NNNNNNNNNNNN)NNNNNNNNNNNNNNNN)f__doc__r   multiprocessing.poolr  r   collections.abcr   r   r   r  r   r   typingr   r   r	   rk   huggingface_hubr
   huggingface_hub.errorsr   r   huggingface_hub.utilsr   $huggingface_hub.utils._cache_managerr   huggingface_hub.utils._parsingr   
_cli_utilsr   r   r   r   r   r   r   r   r   r   r   _outputr   r   
get_logger__name__loggerr/   r   r"   r+  rD   rl   rF  rG   r|   rF   rH   rj   rI   rJ   rG  rH  rT  rU  rS  rD  rE  rE   ri   r   rw  jobs_clir9   rd   rw   r   r   r   r   r  r'  r.  r4  r=  uv_app	add_typerrM  scheduled_appr\  rk  rr  r|  r  r  r  scheduled_uv_appr  rX   r   r   r  r   r   r'   r%   <module>r     s  0d     .   * *  ' ; ) = :    - 
		H	%.8    	NN' $J	LL= $J	LLrk*	 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  	$	$N 

  )D)DX'8 
'%=$>?JE @JEZ 
$,!@A`< B`<F 
*(:';<] =]6 
)'A&BC9 D9< 
(&?%@A+ B+* 
B)  ,,* 
d	e   6  % 	.5  	*	*Z #QR   ={  3 	.5NO  
%Y
%YP t'=&>?KF @KF\ y,L+MNW OW0 x+J*KL	= M	= y,L+MN
Q O
Q x+J*KL	= M	= H/  66. !&QR    (t  4 	.58F  +O+Ob$6 CL
r'   