
    5pjt              .          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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Jr  SS	KJrJrJrJrJrJr  SS
KJr  SSKJr  SSK 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,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6  SSK7J8r8J9r9  SSK:J;r;J<r<  \!Rz                  " \>5      r?S\@S\@S-  S\A\@\@S-  4   4S jrBS\C\@   S-  S\S\@S-  S\C\   S-  4S jrDSrE\\@\8" SS94   rF\\@S-  \9" SS94   rG\\@S-  \9" S\." \5      S 94   rH\\C\@   S-  \9" S!S"S#S94   rI\\@S-  \9" S$S%S94   rJ\\@S-  \9" S&S94   rK\\L\9" S'S(S)S94   rM\\@S-  \9" S*S94   rN\\@S-  \9" S+S,S94   rO\\C\P   S-  \9" S-S.S94   rQ\\L\9" S/S0S94   rR\\C\@   S-  \9" S1S2S94   rS\\@S-  \9" S3S4S5S94   rT\\LS-  \9" S6S94   rU\\LS-  \9" S7S94   rV\\@\8" S8S94   rW\\@\8" S9S94   rX\\C\@   S-  \8" S:S94   rY\\C\@   \8" S;S94   rZ\\@\8" S<S94   r[\\C\@   S-  \8" S=S94   r\\\@\8" S>S94   r]\\C\@   S-  \9" S?S@SAS94   r^\6" SBS9r_S\SC\SS4SD jr`\_R                  SESFSG0/ SHQSI9               SSJ\FSK\ZSL\+SM\-SN\JSO\ISP\^SQ\*SR\,SS\HST\KSU\MSV\QSW\RSX\OS\NSY\1SS4$SZ jj5       rb\_R                  S[/ S\QS]9    SS\[S^\\L\9" S_S`SaS94   Sb\\PS-  \9" ScSdSeS94   S\NSY\1SS4Sf jj5       rcSg\d\@\@4   Sh\C\A\@\@\@4      S\L4Si jreSj\PSS4Sk jrfS\@Sl\\d\@\4      Sm\C\@   S\\A\L\@\C\C\@\P-        4      4Sn jrg\_R                  SoSp/S]9   SSq\\S\NSY\1SS4Sr jj5       rh\_R                  Ss/ StQS]9        SSu\\L\9" SvSwSxS94   Sy\\C\@   S-  \9" Sz\." \5      S{S|94   SO\\C\@   S-  \9" S!S"S}S94   SN\\@S-  \9" S$S~S94   S\\P\9" SSS94   S\NSY\1S\\C\@   S-  \9" S_SSS94   SS4S jj5       ri\_R                  SS/S]9SS j5       rj\_R                  SS/S]9  SSq\\C\@   \8" SS94   S\NSY\1SS4S jj5       rk\_R                  SS/S]9  SS\[S\NSY\1SS4S jj5       rl\_R                  S/ SQS]9   SSq\\C\@   \8" SS94   ST\\@S-  \9" SS94   S\NSY\1SS4
S jj5       rm\_R                  S/ SQS]9     SS\[SN\JSO\IS\\L\9" SSS94   S\NSY\1SS4S jj5       rn\_R                  SW/ SQS]9    SS\[S\0S\/S\NSY\1SS4S jj5       ro\6" SS9rp\_R                  \pSS9  \pR                  SESFSG0/ SQSI9                   SS\XS\YSJ\GSS\HSL\+SM\-SN\JSO\ISP\^SQ\*SR\,ST\KSU\MSV\QSW\RSX\OS\NSY\1S\SS\TSS4*S jj5       rr\6" SS9rs\_R                  \sSS9  \sR                  SESFSG0S/SI9               SS\WSJ\FSK\ZS\US\VSL\+SM\-SN\JSO\ISP\^SQ\*SR\,SS\HST\KSV\QSX\OS\NSY\1SS4&S jj5       rt\sR                  SsS/S]9    SSu\\L\9" SvSwSS94   S\NSY\1S\\C\@   S-  \9" S_SSS94   SS4
S jj5       ru\sR                  SS/S]9  SS\\C\@   \8" SS94   S\NSY\1SS4S jj5       rv\sR                  SS/S]9  SS\]S\NSY\1SS4S jj5       rw\sR                  SS/S]9  SS\]S\NSY\1SS4S jj5       rx\sR                  SS/S]9  SS\]S\NSY\1SS4S jj5       ry\sR                  SS/S]9  SS\]S\NSY\1SS4S jj5       rz\sR                  S/ SQS]9     SS\]SN\JSO\IS\\L\9" SSS94   S\NSY\1SS4S jj5       r{\6" SS9r|\sR                  \|SS9  \|R                  SESFSG0SS/SI9                   SS\WS\XS\YS\US\VSJ\GSS\HSL\+SM\-SN\JSO\ISP\^SQ\*SR\,ST\KSV\QSX\OS\NSY\1S\SS\TSS4,S jj5       r}S\d\@\4   S\d\@\@4   S-  S\d\@\4   4S jr~SN\@S-  SO\C\@   S-  S\L4S jrSS.S\C\@   S-  SN\@S-  S\d\@\@4   S-  4S jjrS\C\C\@\P-        S\C\@   S\@4S jr\" S5      rS\\   S\S\\   4   S\dSS4S jrS\GR                  GR
                  S\S\\   4   S\C\d   S\\   4S jrg)z@Contains commands to interact with jobs on the Hugging Face Hub.    N)CallableIterable)fnmatch)Path)EmptyQueue)	AnnotatedAnyTypeVar)urlsplit)HfApiJobHardwareJobInfoJobStageVolume	constants)TERMINAL_JOB_STAGES)CLIError)logging)_format_size)_split_mount)format_durationparse_duration   )
EnvFileOptEnvOptSecretsFileOpt
SecretsOpt
SoftChoiceSshDryRunOptSshIdentityFileOptTokenOptexec_ssh
get_hf_apiparse_env_mapparse_volumestyper_factory)ArgumentOption)_dataclass_to_dictout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       T/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/cli/jobs.py_parse_namespace_from_job_idr7   :   s     011||C1UV\U]]_`aa
&  )/c1)=&mUV\U]]_`aa!A6ykAabuavvwx
 	
 --    volumesapic                P   U (       d  g/ nU  GH  nUR                  [        R                  5      (       a&  UR                  [	        U/5      =(       d    / 5        MN  [        XDS9u  pVnUc  [        SU S35      e[        U5      R                  5       R                  5       (       d  [        SU S35      eUR                  UUUb  UOSUS9nUR                  S	L a6  [        R                  " S
U SUR                   SUR                   SU 35        UR!                  U5        GM     U$ )zParse `-v` specs for Jobs commands.

Same as [`parse_volumes`] but the source side can also be a local directory: it is synced to a
bucket via [`HfApi.sync_job_volume`] and the resulting bucket subfolder is mounted (read-only
unless ':rw' is specified).
N)rawz#Missing mount path in volume spec 'zC'. Expected 'LOCAL_DIR:/MOUNT_PATH[:ro|:rw]' (e.g. './data:/data').zVolume source 'z' is not an existing local directory. To mount a repo or bucket instead, use the 'hf://' syntax (e.g. 'hf://buckets/my-org/my-bucket:/data').T)	read_onlyr-   FzVolume 'zg' is mounted read-write. Once the job is over, pull back its data with:
  hf buckets sync hf://buckets/r0    )
startswithr   HF_PROTOCOLextendr&   r   r   r   
expanduseris_dirsync_job_volumer=   r+   hintsourcepathappend)	r9   r:   r-   resultraw_specrF   
mount_pathr=   volumes	            r6   _parse_and_sync_job_volumesrM   V   sH    Fy4455MM-
39r: )5X(L%I5hZ  @C  D  F|&&(//11!& *z z  $$#,#8id	 % 
 u$HH:, '228--&++aPVxY 	f7 8 Mr8   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`.)rN   
click_typez-lz--labelz3Set labels. E.g. --label KEY=VALUE or --label LABELz--namezName the Job. Stored as the `name` label. Names do not have to be unique. Defaults to the image or script name plus a short hash of the command.zPMax duration: int 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--resource-group-idzThe ID of the resource group to create the Job in. Used to control access to resources within an organization and for cost attribution/spending-limit features.z--exposezExpose a container port through the jobs proxy. Repeat the flag for multiple ports (e.g. `--expose 8000 --expose 8001`). Each exposed port is reachable on the public jobs domain; access requires an HF token with read access to the job's namespace.z--sshzMake the job's container reachable over SSH. Connect with `hf jobs ssh <job_id>`. Requires an SSH public key registered on https://huggingface.co/settings/keys.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-vz--volumea  Mount one or more volumes. Format: hf://[TYPE/]SOURCE:/MOUNT_PATH[:ro|:rw] or LOCAL_DIR:/MOUNT_PATH[:ro|:rw]. TYPE is one of: models, datasets, spaces, buckets. TYPE defaults to models if omitted. models, datasets and spaces are always mounted read-only. buckets are read+write by default. A local directory source is first synced to a bucket and mounted read-only by default. E.g. -v hf://datasets/org/ds:/data or -v hf://buckets/org/b:/mnt:ro or -v ./inputs:/inputszRun and manage Jobs on the Hub.jobc                 `   U R                  UR                  UR                  R                  SS9 H  n[        R
                  " U5        M     U R                  UR                  UR                  R                  S9nUR                  R                  [        R                  :w  ah  UR                  R                  (       a  SUR                  R                   3OSn[        SUR                   SUR                  R                   SU 35      e[        R
                  " SUR                   S	35        g
)zcStream Job logs until the Job ends, then fail the command if the Job did not complete successfully.T)r,   r-   followr,   r-   z:  zJob z finished with stage 'r1   z
 completedN)fetch_job_logsidownernamer+   textwait_for_jobstatusstager   	COMPLETEDmessager   )r:   rP   logfinalr^   s        r6   _stream_logs_and_check_statusra   >  s    !!399>>RV!W X CFFciinnEE||X///161E1EBu||++,-2ehhZ'=ell>P>P=QQRSZR[\]]HHtEHH:Z()r8   runignore_unknown_optionsT)zFhf jobs run --name hello-world python:3.12 python -c 'print("Hello!")'z1hf jobs run --detach python:3.12 python script.pyz3hf 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)context_settingsexamplesimagecommandenvsecretsrX   labelrL   env_filesecrets_fileflavortimeoutdetachexposesshresource_group_idtokenc                    [        X'5      n[        X85      n[        US9nUR                  U UUU[        XTS9[	        UUUS9U	U
UUUUS9n[
        R                  " SUR                  UR                  =(       d    0 R                  S5      UR                  S9  [        XE5      (       db  UR                  =(       d    0 R                  S5      n[
        R                  " SU S	UR                  R                   S
UR                   S35        [        UR                   R"                  [$        5      (       aE  SR'                  S UR                   R"                   5       5      n[
        R                  " SU 35        [        UR                   R(                  [*        5      (       a;  [
        R                  " SUR                  R                   S
UR                   S35        U(       a]  UR                  R                   S
UR                   3n[
        R                  " SU SU S35        [
        R                  " SU S35        g[-        UU5        g)z
Run a Job.rs   rX   r:   r-   )rf   rg   rh   ri   labelsr9   rm   rn   rp   rq   rr   r-   Job startedrX   rV   rX   urlJob auto-named '('. Pass `--name` or run `hf jobs labels r0    --name NAME` to rename it.
c              3   ,   #    U  H
  nS U 3v   M     g7fz  N .0r{   s     r6   	<genexpr>jobs_run.<locals>.<genexpr>       F/E2cU/E   SExposed ports are reachable at (requires an HF token with read access to the job):
Use `hf jobs ssh &` to open an SSH session into the job.Use `hf jobs logs -f &` to stream logs, or `hf jobs inspect ` to check status.Use `hf jobs wait ` to block until it finishes.N)r%   r$   run_job_parse_labels_maprM   r+   rI   rV   rx   getr{   _has_explicit_namerE   rW   rX   
isinstancer[   expose_urlslistjoinssh_urlstrra   )rf   rg   rh   ri   rX   rj   rL   rk   rl   rm   rn   ro   rp   rq   rr   r-   rs   env_mapsecrets_mapr:   rP   	auto_nameurlsjob_refs                           r6   jobs_runr   J  s   > C*G6K
5
!C
++ 2+FyQ+  C JJ}szz/?R.D.DV.LRURYRYZd**ZZ%2**62	yk *"yy~~.ax7RT	
 #**(($//yyFszz/E/EFFghlgmno#**$$c**$SYY^^$4AcffX=cdeYY^^$AcffX.(	1WX_W``rst%gY.KLM!#s+r8   logs)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>)re   rR   z-fz--followzqFollow log output (stream until the job completes). Without this flag, only currently available logs are printed.tailz-nz--tailzvNumber of lines to show from the end of the logs. When combined with --follow, starts streaming from the last N lines.c                     [        X5      u  p[        US9nUR                  XXS9nU H  n[        R                  " U5        M     U(       a+  U(       a  U SU  3OU n[        R
                  " SU S35        gg)a  Fetch 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).

Note: following exits when the log stream ends, regardless of whether the Job
succeeded or failed. Run `hf jobs inspect <job_id>` to check the final status.
ru   )r,   r-   rR   r   r0   z#Stream ended. Run `hf jobs inspect z6` to check the final status (e.g. COMPLETED or ERROR).N)r7   r$   rU   r+   rY   rE   )	r,   rR   r   r-   rs   r:   r   r_   r   s	            r6   	jobs_logsr     sy    N 5VGF
5
!CV[D -6YKq)F6wi?uvw r8   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)r   r   lower)r   r   keyop_strpatternvaluematchs          r6   _matches_filtersr     sf     'W""3'=~w}}7cM%Vt^ !( r8   nc                 B    SnSn[        U 5       H  n[        XS9  M     g )Nz[1Az[2K)end)rangeprint)r   LINE_UP
LINE_CLEARis       r6   _clear_liner     s"    GJ1Xg& r8   metrics_streamtable_headersc              #     #    U GHk  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/[	        [        US   5      S-
  5       Vs/ s H  nS/[        U5      -  PM     sn-   n[        U[        US   5      5       HR  u  pGU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Mn     SU / 4v   g s  snf 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gpusrT   utilizationN/AFT)roundr   r   dictr   lenzipsorted)	r,   r   r   metricsrow_rowsgpu_idgpus	            r6   _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@@5U3wv;ORS;S5TU5TRD3s8O5TUUD"4)@Afof-=)*!,S3':#;;cBV>WWYZ[\\]^#C(;$<=>d<PSThPiCjBkklm   B E7c-03s8;<<C5DV!!+ ", 
 Vs   B:F<E=B-F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  [        R                  " S5        g/ 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  oIU     H  oPM     M     nnn
[        [!        XS95        U  Vs/ s H  nUUR#                  XAS9US.PM     nn[%        U[&        US9 H  u  pnU(       a  U	R)                  US5        OUX'   [        R                  " 5       nUU-
  [*        :  d  MH  [-        S[        U5      -   5        U	 VV
s/ s H  oIU     H  oPM     M     nnn
[        [!        XS9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)z7Fetch the resource usage statistics and metrics of JobsNru   rX   r-   UNKNOWN)RUNNINGUPDATINGr   zNo running jobs found)	zJOB IDzCPU %zNUM CPUzMEM %z	MEM USAGEzNET I/Oz
GPU UTIL %z	GPU MEM %zGPU MEM USAGEr   r0   USAGEz-- / --z--)headersrS   )r,   r   r   )kwargs_listr   )r7   rH   r$   whoami	list_jobsr[   r\   rV   r   r+   rY   multiprocessingpool
ThreadPooltimer   	_tabulatefetch_job_metricsiflatmap_unorderedr   popSTATS_UPDATE_MIN_INTERVALr   )r   r-   rs   
parsed_idsr,   r:   rP   r   r   rows_per_job_idr   headerlast_update_time
total_rowsr   doner   nows                     r6   
jobs_statsr     s    
F <V OFf%  
5
!CJJL(	 }}y}9
9$'JJ

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

 7|q()
M 
			(	(W	6$<>F$*8Clmln^op^oTZ#-7f3DI4O^oppC'*eO#   99;(7[fSYCZCcCZc
[ 	i
:; "
 "	 !"%"7"7v"7"[!.
 " 	 
 #5T;O]h"iD$##FD1*.'))+C%%)BBAJ/00?cf[aKbCcKbc
ci
BC#&  #j) 
7	6'
. q \

  d9 
7	6sU   "1II;I'I
'(I'I&I'?IAI'5I'I!
(I'I''
I5zlist | ls | ps)z
hf jobs lszhf jobs ls -az&hf jobs ls --status running,schedulingzhf jobs ls --name training-v2z+hf jobs ls --label env=prod --label team=mlz%hf jobs ls --all --label hf-sandbox=1allz-az--allzWShow all Jobs (default shows running and scheduling). Cannot be combined with --status.r[   z--statuszfOnly show Jobs with the given status. Comma-separated or repeated, e.g. `--status running,scheduling`.)rO   rN   z{Only show Jobs with the given `key=value` label. Repeat to require several labels, e.g. `--label env=prod --label team=ml`.zFOnly show Jobs with the given name (shortcut for `--label name=NAME`).limitz--limitzCMaximum number of Jobs to display. Set to 0 to show all (no limit).filterz--filterz2(Deprecated) Use `--status` and `--label` instead.c                 6   [        US9nU(       a  [        R                  " SU S35        U (       a  U(       a  [        S5      e/ n	U=(       d    /  H*  n
U	R	                  S U
R                  S5       5       5        M,     U	(       a  U	nO>U (       a  SnO4[        R                  R                  [        R                  R                  /n0 nU=(       d    /  H/  nSU;  a  [        S	U S
35      eUR                  S5      u  pXU'   M1     Ub  SU;   a  [        S5      eX<S'   UR                  X[U=(       d    SS9nSnUS:  a9  [        [        R                  " XS-   5      5      n[        U5      U:  a  SnUSU nO[        U5      n/ nU GHU  n[        U5      nUR!                  S5      =(       d    0 nUR!                  S5      =(       d    / nUR!                  SS5      US'   UR!                  S5      =(       d    0 R!                  S5      =(       d    SUS'   UR!                  S5      =(       d    SUS'   U(       a  SR#                  U5      OSUS'   UR!                  S5      (       a  US   SS R%                  SS5      OSUS'   UR!                  S 5      =(       d    0 R!                  S!S"5      US '   ['        UR!                  S#5      5      US$'   UR)                  U5        GMX     [        R*                  " U/ S%QSS&9  U(       a  [        R,                  " S'U S(35        U(       dx  U	(       d  U(       aK  S)R#                  / S* U	 5       QS+ UR/                  5        5       Q5      n[        R0                  " S,U 35        gU (       d  [        R,                  " S-5        ggg).zList Jobs.

Use `--status` to filter by status (see [`JobStage`] for possible values) and `--label` to filter by `key=value`
labels. A Job must match every filter to be listed.
ru   zIgnoring filter 'zc'. `-f`/`--filter` is deprecated and will be removed in a future release. Use `--status`/`--label`.z0`-a`/`--all` cannot be combined with `--status`.c              3   n   #    U  H+  oR                  5       (       d  M  UR                  5       v   M-     g 7fN)strip)r   parts     r6   r   jobs_ps.<locals>.<genexpr>  s"     V5ETLDJJLL5Es   55,Nr   zInvalid label filter 'z"': must be in the form 'key=value'rX   z6Cannot filter by both `--name` and `--label name=...`.)r-   r[   rx   Fr   r   T	durationsrg   rV   rT   r,   rx   r   docker_imageimage/spacer>   
created_at   Tcreatedr[   r\   r   running_secsruntime)r,   rX   r   rg   r  r[   r  r   id_keyzOutput truncated to z4 Jobs. Use `--limit 0` to show all (or `--limit N`)., c              3   ,   #    U  H
  nS U 3v   M     g7f)zstatus=Nr   )r   ss     r6   r   r     s     7,QWQC=,r   c              3   6   #    U  H  u  pS U SU 3v   M     g7f)zlabel=r   Nr   )r   kvs      r6   r   r     s#     :gXfPTPQVA3as;KXf   zNo jobs matched filters: zHNo running jobs. Use `-a`/`--all` to include finished (and failed) jobs.)r$   r+   warningr   rA   r3   r   r   r   
SCHEDULINGr   r   	itertoolsislicer   r*   r   r   replacer   rH   tablerE   itemsrY   )r   r[   rj   rX   r   r-   rs   r   r:   raw_statusesr   server_statusesrx   itemr   	jobs_iter	truncatedjobs	job_itemsrP   job_itemr   cmdfilters_msgs                           r6   jobs_psr!  7  sG   D 5
!Cx (p p	

 vIJJ !L2VU[[5EVV  &	#++1183F3F3L3LM  Fd?3D69[\]]ZZ_
s	  VSTTv	RXR`\`aI IqyI$$Y	:;t9uI<DI ')I%c*LL-3	ll9%+%\\$3$LL28b==fEN"*,,~">"G%/2chhsmOW||\hOiOih|4Sb9AA#sKot&ll84:??S-immN.KL"  II\
 'w.bcd6))h7,7h:gX^XdXdXf:ghK HH0>?HH_`  r8   hardwarezhf jobs hardwarec                     [        5       n U R                  5       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                  UR                  UR                  UR                  UUUS
.5        M     [        R                  " U5        [        R                  " S5        g)z(List available hardware options for JobsrT   zx  ()$z.4ffree<   z.2f)rX   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_usdrH   rX   pretty_namer)  r*  ephemeral_storager+   r  rE   )r:   hardware_listr  hwaccelerator_infocost_min	cost_hours          r6   jobs_hardwarer9    s    ,C**,ME>>"$.."9"9!:"R^^=Q=Q<RRTUWUcUcUhUhTiijk131A1AQr'',-v797G7Ga((2-c23V	!~~vvvv///$&		
 $ IIeHH[\r8   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      UR                  S9PM"     snSS9  gs  snf s  snf )z0Display detailed information on one or more Jobsru   rS   rx   rV   r  N)	r7   rH   r$   inspect_jobr+   r  _surface_namer*   rx   )r   r-   rs   r   r,   r:   r  rP   s           r6   jobs_inspectr@    s     J8K&!  G
5
!CNUVgFOO6O?gDVIITXYTXS}/4SZZHTXYbfg WYs   B''Bcancelzhf jobs cancel <job_id>c                 x    [        X5      u  p[        US9nUR                  XS9  [        R                  " SU S9  g)zCancel a Jobru   rS   zJob cancelledrV   N)r7   r$   
cancel_jobr+   rI   )r,   r-   rs   r:   s       r6   jobs_cancelrE    s7     5VGF
5
!CNN&N6JJ6*r8   wait)zhf jobs wait <job_id>z"hf jobs wait <job_id_1> <job_id_2>z"hf jobs ls -q | xargs hf jobs waitz,Job IDs to wait for (or 'namespace/job_id').zTMax time to wait: int with s (seconds, default), m (minutes), h (hours) or d (days).c                 6   / n[        5       nU  H2  n[        Xb5      u  pxUR                  U5        UR                  U5        M4     [	        U5      S:  a0  [        SSR                  S [        U[        S9 5       5      -   5      eUR                  5       nUb  [        U5      OSn	[        US9n
[        R                  " S[	        U5       S	35      n U
R                  XIUS
9nUR!                  [	        U5       S35        [        R"                  " U Vs/ s HC  oR$                  [        UR                  R&                  5      UR                  R(                  S.PME     sn5        U Vs/ s H.  oR                  R&                  [*        R,                  :w  d  M,  UPM0     nnU(       a<  [        [	        U5       S[	        U5       S3SR                  S U 5       5      -   5      eg! [         a"    UR!                  S5        [        SU S35      Sef = fs  snf s  snf )a  Wait for one or more Jobs to reach a terminal state.

Blocks until every Job has finished, then exits with code 0 if all Jobs completed
successfully, or a non-zero exit code if any Job was canceled, errored or deleted.

All Jobs must belong to the same namespace.
r   z0All Job IDs must be in the same namespace, got: r	  c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r   )r   nss     r6   r   jobs_wait.<locals>.<genexpr>2  s     F*EBB*Es   )r   Nru   zWaiting for z Job(s) to finish...)rn   r-   z
Timed out.zTimed out after z waiting for Job(s) to finish.z Job(s) finished.)rV   r\   r^   z of z' Job(s) did not complete successfully: c              3   l   #    U  H*  oR                    S UR                  R                   S3v   M,     g7f)r$  r%  N)rV   r[   r\   )r   rP   s     r6   r   rJ  E  s*     KFS66("SZZ%5%5$6a8Fs   24)setr7   rH   addr   r   r   r   r   r   r   r$   r+   r[   rZ   TimeoutErrorr   r  rV   r\   r^   r   r]   )r   rn   r-   rs   r   
namespacesr,   	parsed_idparsed_namespacetimeout_secsr:   r[   r  rP   faileds                  r6   	jobs_waitrT  
  s   > JJ&B6&U#	)$'(  :>iiF&*EFFG
 	
  I.5.A>'*tL
5
!CZZ,s:&77KLMF]
IV KK3t9+./0IIhlmhladffs3::+;+;'<I[I[\hlmn!LTcZZ%5%59K9K%KcTFL6{m4D	{*QRiiKFKKL
 	
   ]L!)'2PQRX\\]
 nLs   G" A
H'+HH",Hrx   )z*hf jobs labels <job_id> --name training-v2z8hf jobs labels <job_id> --label env=prod --label team=mlzhf jobs labels <job_id> --clearclearz--clearzRemove all labels from the job.c                    U(       d  Uc  U(       d  [        S5      eU(       d  Ub  U(       a  [        S5      e[        X5      u  p[        US9nUb2  U(       d+  UR                  XS9R                  =(       d    0 n0 UESU0EnO[        X!S9=(       d    0 nUR                  XUS9n	[        R                  " S	U	R                  UR                  S5      S
9  g)zfUpdate labels on a Job. Passing --label replaces all existing labels; passing --name alone keeps them.NePlease set a name with --name or at least one label with --label. To remove all labels, pass --clear.lCannot set a name or labels and clear them at the same time. Please use --name/--label or --clear, not both.ru   rS   rX   rv   )r,   rx   r-   Labels updatedrV   rX   )r   r7   r$   r>  rx   r   update_job_labelsr+   rI   rV   r   )
r,   rX   rj   rU  r-   rs   r:   current_labelsrx   rP   s
             r6   jobs_labelsr]  I  s    " T\%s
 	
 	!uz
 	
 5VGF
5
!CLSSYWY1N1FD1"54:


v	

RCJJCFFF1CDr8   )zhf jobs ssh <job_id>zhf jobs ssh <job_id> --dry-runz)hf jobs ssh <job_id> -i ~/.ssh/id_ed25519identity_filedry_runc                    [        X5      u  p[        US9nUR                  XS9nUR                  R                  c  [        S5      eUR                  R                  [        ;   a0  [        SUR                   SUR                  R                   S35      eUR                  R                  [        R                  :w  a  [        R                  " SUR                   S	UR                  R                   S
35      nUR                  UR                  U[        R                  /S9nUR                  R                  [        R                  :w  aA  UR                  S5        [        SUR                   SUR                  R                   S35      eUR                  S5        [        UR                  R                  5      n[        UR                    SUR"                   3UR$                  UUS9  g)a  SSH into a running Job.

If the Job is not yet running, waits until it reaches the RUNNING state before
connecting. Requires the Job to be started with SSH enabled (`hf jobs run --ssh ...`)
and your SSH public key to be registered at https://huggingface.co/settings/keys.
ru   rS   Nz[SSH is not enabled on this job. Start a job with SSH support using `hf jobs run --ssh ...`.zCannot SSH into job 'z%': job has already finished (stage: 'z').zWaiting for job 'z' to be running (stage: 'z')...)r,   r-   stageszJob finished.z1': job finished before reaching RUNNING (stage: 'zJob is running.@)portr^  r_  )r7   r$   r>  r[   r   r   r\   r   rV   r   r   r+   rZ   r   r   r#   usernamehostnamerc  )	r,   r^  r_  r-   rs   r:   rP   r[   r   s	            r6   jobs_sshrf  n  s   * 5VGF
5
!C
///
=C
zz!tuu
zz...svvh6[\_\f\f\l\l[mmpqrr
zz8+++/x7PQTQ[Q[QaQaPbbghicff	8K[K[J\]::x///KK('x/`adakakaqaq`rruv  	%&szz))*G
Ag../0\\#	r8   zFRun UV scripts (Python with inline dependencies) on HF infrastructure.uvrv   )z,hf jobs uv run --name my-script my_script.pyz$hf jobs uv run --detach 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scriptscript_argswith_pythonc                    [        XI5      n[        XZ5      n[        US9nUR                  U U=(       d    / UUUUU[        XvS9[	        UUUS9UUUUUUS9n[
        R                  " SUR                  UR                  =(       d    0 R                  S5      UR                  S9  [        Xg5      (       db  UR                  =(       d    0 R                  S5      n[
        R                  " SU S	UR                  R                   S
UR                   S35        [        UR                   R"                  [$        5      (       aE  SR'                  S UR                   R"                   5       5      n[
        R                  " SU 35        [        UR                   R(                  [*        5      (       a;  [
        R                  " SUR                  R                   S
UR                   S35        U(       a]  UR                  R                   S
UR                   3n[
        R                  " SU SU S35        [
        R                  " SU S35        g[-        UU5        g)8Run a UV script (local file or URL) on HF infrastructureru   rv   rw   )rh  ri  dependenciesrk  rf   rh   ri   rx   r9   rm   rn   rp   rq   rr   r-   ry   rX   rz   r|   r}   r0   r~   r   c              3   ,   #    U  H
  nS U 3v   M     g7fr   r   r   s     r6   r   jobs_uv_run.<locals>.<genexpr>  r   r   r   r   r   r   r   r   r   r   N)r%   r$   
run_uv_jobr   rM   r+   rI   rV   rx   r   r{   r   rE   rW   rX   r   r[   r   r   r   r   r   ra   )rh  ri  rf   rm   rh   ri   rX   rj   rL   rk   rl   rn   ro   rp   rq   rr   r-   rs   rj  rk  r   r   r:   rP   r   r   r   s                              r6   jobs_uv_runrr    s   D C*G6K
5
!C
..%2 2+FyQ+  C" JJ}szz/?R.D.DV.LRURYRYZd**ZZ%2**62	yk *"yy~~.ax7RT	
 #**(($//yyFszz/E/EFFghlgmno#**$$c**$SYY^^$4AcffX=cdeYY^^$AcffX.(	1WX_W``rst%gY.KLM!#s+r8   z,Create and manage scheduled Jobs on the Hub.	scheduledzRhf jobs scheduled run "0 0 * * *" --name daily-script python:3.12 python script.pyschedulesuspendconcurrencyc                    [        XZ5      n[        Xk5      n[        US9nUR                  UUU UUUU[        XS9[	        U	UUS9UUUUUS9n[
        R                  " SUR                  UR                  R                  =(       d    0 R                  S5      S9  [        Xx5      (       dl  UR                  R                  =(       d    0 R                  S5      n[
        R                  " SU S	UR                  R                   S
UR                   S35        [
        R                  " SUR                  R                   S
UR                   S35        g)zSchedule a Job.ru   rv   rw   )rf   rg   rt  ru  rv  rh   ri   rx   r9   rm   rn   rp   rr   r-   Scheduled Job createdrX   rZ  Scheduled Job auto-named '2'. Pass `--name` or run `hf jobs scheduled labels r0   r~   Use `hf jobs scheduled inspect ` to view its details.N)r%   r$   create_scheduled_jobr   rM   r+   rI   rV   job_specrx   r   r   rE   rW   rX   )rt  rf   rg   ru  rv  rh   ri   rX   rj   rL   rk   rl   rm   rn   rp   rr   r-   rs   r   r   r:   scheduled_jobr   s                          r6   scheduled_runr    sE   4 C*G6K
5
!C,, 2+FyQ+ - M  JJ&=+;+;=CYCYC`C`CfdfBkBklrBstd**"++228b==fE	( 4))6)<)<)A)A(B!MDTDTCUUpr	
 HH.}/B/B/G/G.H-JZJZI[[qrsr8   zhf jobs scheduled lsz1Show all scheduled Jobs (default hides suspended)z>Filter output based on conditions provided (format: key=value)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  [        R                  " 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                  R                  =(       d    0 R                  S5      =(       d    SnUR                  UU[!        U5      US.n[#        UU5      (       d  M  UR	                  U5        M     / nU GHx  n[%        U5      nUR                  S5      =(       d    0 nUR                  S5      =(       d    0 nUR                  S5      nUR                  S5      =(       d    / nUR                  S5      =(       d    0 R                  S5      =(       d    SUS'   UR                  S5      =(       d    SUS'   U(       a  SR                  U5      OSUS'   U(       a.  UR                  S5      (       a  US   SS R'                  SS5      OSUS'   UR                  S5      (       a  US   SS R'                  SS5      OSUS'   UR                  S5      =(       d    SUS'   UR	                  U5        GM{     [        R(                  " U/ SQSS 9  U(       d8  U(       a1  S!R                  S" U 5       5      n[        R*                  " S#U 35        U(       a=  US$   S   n[        R,                  " S%U S&35        [        R,                  " S'U S(35        gg))zList scheduled Jobsru   r   r   r   !r   Nz Ignoring invalid filter format 'z'. Use key=value format.Fr   r>   rX   )rV   rX   rf   ru  rg   r~  r[   last_jobrg   rx   r   r   atr  r  last_runnext_job_run_atnext_runru  )rV   rX   rt  r   rg   r  r  ru  rV   r  r	  c              3   6   #    U  H  u  po1 U U 3v   M     g 7fr   r   )r   r  or  s       r6   r   scheduled_ps.<locals>.<genexpr>z  s     DGq#aSGr  z#No scheduled jobs matched filters: r   r{  z(` to view details about a scheduled job.zUse `hf jobs scheduled trigger z)` to trigger a scheduled job immediately.)r$   list_scheduled_jobsr3   endswithrH   r   r+   r  ru  r~  r   rg   r   rx   r   rV   r   r   r*   r  r  rY   rE   )r   r-   rs   r   r:   scheduled_jobsr   fr   r   opfiltered_jobsr  ru  image_or_spacer  command_strjob_namepropsr  sjr  r~  status_dictr  r   first_item_ids                              r6   scheduled_psr  '  sH   , 5
!C,,y,AN*,G\r\!8aJC||C  #2hNNCIIK[[];<KK:1#=UVW  M'''05w&//<<E$$,,2'*chhsm!**117R<<VDM""#7|"
  w//]+# (( #%E!"%88J'-2hhx(.B??:.ll9%+ X.4"99&AJUV&ll>:Ce]+.#((3-EYDLQYQ]Q]^bQcQc8D>#2.66sC@inZEP__UfEgEgK)*3B/77SAmr 	Z ((9-6YT   IIg
 WiiDGDD6{mDEa2=/Aijk2=/Ajkl r8   zhf jobs scheduled inspect <id>scheduled_job_idsz>Scheduled Job IDs to inspect (or 'namespace/scheduled_job_id')c           
      T   / 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      UR                  R                  S9PM,     snSS9  gs  snf s  snf )z:Display detailed information on one or more scheduled Jobsru   scheduled_job_idr-   r<  rV   r=  N)
r7   rH   r$   inspect_scheduled_jobr+   r  r?  r*   r~  rx   )	r  r-   rs   r   r,   r:   r  r  r  s	            r6   scheduled_inspectr    s     J#8K&! $ #
5
!C !2 1 	!!3C!Y 1   IIZhiZhTV}/3BKK<N<NOZhirvw	 js   B (1B%deletezhf jobs scheduled delete <id>r  c                 x    [        X5      u  p[        US9nUR                  XS9  [        R                  " SU S9  g)zDelete a scheduled Job.ru   r  zScheduled Job deletedrC  N)r7   r$   delete_scheduled_jobr+   rI   r  r-   rs   r:   s       r6   scheduled_deleter    ?     #??O"[
5
!C.>TJJ&+;<r8   zhf jobs scheduled suspend <id>c                     [        X5      u  p[        US9nUR                  XS9  [        R                  " SU S9  [        R
                  " SU  S35        g)z Suspend (pause) a scheduled Job.ru   r  zScheduled Job suspendedrC  zUse `hf jobs scheduled resume z` to resume it.N)r7   r$   suspend_scheduled_jobr+   rI   rE   r  s       r6   scheduled_suspendr    sW     #??O"[
5
!C/?UJJ(-=>HH-.>-?OPr8   resumezhf jobs scheduled resume <id>c                 x    [        X5      u  p[        US9nUR                  XS9  [        R                  " SU S9  g)z!Resume (unpause) a scheduled Job.ru   r  zScheduled Job resumedrC  N)r7   r$   resume_scheduled_jobr+   rI   r  s       r6   scheduled_resumer    r  r8   triggerzhf jobs scheduled trigger <id>c                    [        X5      u  p[        US9nUR                  XS9n[        R                  " SUR
                  UR                  S9  [        R                  " SUR                  R                   SUR
                   S35        g)	zJTrigger a scheduled Job to run immediately (does not change the schedule).ru   r  zScheduled Job triggered)rV   r{   r   r0   z` to stream logs.N)
r7   r$   trigger_scheduled_jobr+   rI   rV   r{   rE   rW   rX   )r  r-   rs   r:   rP   s        r6   scheduled_triggerr    st     #??O"[
5
!C

#
#5E
#
[CJJ(SVVAHH$SYY^^$4AcffX=NOPr8   )z1hf jobs scheduled labels <id> --name daily-scriptz>hf jobs scheduled labels <id> --label env=prod --label team=mlz%hf jobs scheduled labels <id> --clearz)Remove all labels from the scheduled job.c                    U(       d  Uc  U(       d  [        S5      eU(       d  Ub  U(       a  [        S5      e[        X5      u  p[        US9nUb<  U(       d5  UR                  XS9R                  R
                  =(       d    0 n0 UESU0EnO[        X!S9=(       d    0 nUR                  XUS9n	[        R                  " S	U	R                  UR                  S5      S
9  g)zpUpdate labels on a scheduled Job. Passing --label replaces all existing labels; passing --name alone keeps them.NrW  rX  ru   r  rX   rv   )r  rx   r-   rY  rZ  )r   r7   r$   r  r~  rx   r   update_scheduled_job_labelsr+   rI   rV   r   )
r  rX   rj   rU  r-   rs   r:   r\  rx   r  s
             r6   scheduled_labelsr    s    " T\%s
 	
 	!uz
 	
 #??O"[
5
!C %%7G%]ffmmsqs 	 2N1FD1"54:33)I 4 M JJM$4$46::f;MNr8   z)Schedule UV scripts on HF infrastructure.zBhf jobs scheduled uv run "0 0 * * *" --name daily-script 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[        XS9[	        UUUS9UUUUUS9n[
        R                  " SUR                  UR                  R                  =(       d    0 R                  S5      S9  [        X5      (       dl  UR                  R                  =(       d    0 R                  S5      n[
        R                  " SU S	UR                  R                   S
UR                   S35        [
        R                  " SUR                  R                   S
UR                   S35        g)rm  ru   rv   rw   )rh  ri  rt  ru  rv  rn  rk  rf   rh   ri   rx   r9   rm   rn   rp   rr   r-   rx  rX   rZ  ry  rz  r0   r~   r{  r|  N)r%   r$   create_scheduled_uv_jobr   rM   r+   rI   rV   r~  rx   r   r   rE   rW   rX   )rt  rh  ri  ru  rv  rf   rm   rh   ri   rX   rj   rL   rk   rl   rn   rp   rr   r-   rs   rj  rk  r   r   r:   rP   r   s                             r6   scheduled_uv_runr    s@   @ C*G6K
5
!C

%
%%2 2+FyQ+# & C& JJ&3669L9L9RPR8W8WX^8_`d**\\((.B33F;	( 4)),(8#&&A\^	
 HH.syy~~.>axG]^_r8   r  c                L    U=(       d    0 R                  S5      nUc  U $ SU0U E$ )zPromote the `name` label to a top-level `name` field for display.

The `name` is kept inside `labels` too (the dataclasses and API payloads are unchanged); this
only makes it a first-class column/field in command outputs. No-op when there is no name.
rX   )r   )r  rx   rX   s      r6   r?  r?  B  s2     Lbf%D|D!D!!r8   c                 N    U SL=(       d    [        S U=(       d    /  5       5      $ )zLWhether the user explicitly named the Job (via `--name` or a `name=` label).Nc              3   P   #    U  H  oR                  S S5      S   S:H  v   M     g7f)r   r   r   rX   N)r3   )r   r  s     r6   r   %_has_explicit_name.<locals>.<genexpr>P  s#     "[{t::c1#5a#8F#B{s   $&)any)rX   rj   s     r6   r   r   N  s$    t[s"[u{XZ{"[[[r8   c                    U (       d  Uc  g0 nU =(       d    /  H%  nSU;   a  UR                  SS5      OUS4u  pEXRU'   M'     Ub  SU;   a  [        S5      eXS'   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 or name provided.
Nr   r   rT   rX   z4--name and --label name=... cannot both be provided.)r3   r   )rx   rX   
labels_map	label_varr   r   s         r6   r   r   S  st     dl!#J\r\	03y0@Y__S!,yRTo
3 " ZQRR!6r8   r   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r   )r   r   )r   xs     r6   r   _tabulate.<locals>.<genexpr>p  s     /3ac#a&kk3s   !#   r   z{{:{}}} -N   z...r   )r   maxshutilget_terminal_sizecolumnsr   sumindexformatrH   r   r   )r   r   col
col_widthsterminal_widthcol_to_minimize
row_formatlineswr   r  	col_widthrow_format_argss                r6   r   r   i  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 )Nr   )put)r  r  r  rI   s       r6   _write_generator_to_queuer    s    ..		& !r8   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?)rn   c              3   @   #    U  H  oR                  5       v   M     g 7fr   )ready)r   async_results     r6   r   %iflatmap_unordered.<locals>.<genexpr>  s     N))++s   N)
r   apply_asyncr  r   r   r   emptyKeyboardInterruptr   rN  )r   r  r   r  r  async_resultsr  s          r6   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!)NNNNNNNNNFNFNNN)FNNN)NNN)FNNNr   NNN)r.   N)NN)NNFNN)NFNN)NNNNNNNNNNNFNFNNNNN)NNNNNNNNNNNNNNN)NNNNNNNNNNNNNNNNNNN)__doc__r  r   multiprocessing.poolr  r   collections.abcr   r   r   pathlibr   r  r   r   typingr	   r
   r   urllib.parser   huggingface_hubr   r   r   r   r   r   huggingface_hub._jobs_apir   huggingface_hub.errorsr   huggingface_hub.utilsr   $huggingface_hub.utils._cache_managerr   huggingface_hub.utils._hf_urisr   huggingface_hub.utils._parsingr   r   
_cli_utilsr   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   
_frameworkr(   r)   _outputr*   r+   
get_logger__name__loggerr   tupler7   r   rM   r   ImageArgImageOpt	FlavorOpt	LabelsOptNameOpt
TimeoutOptbool	DetachOptNamespaceOptResourceGroupIdOptint	ExposeOptSshEnabledOptWithOpt	PythonOpt
SuspendOptConcurrencyOptScheduleArg	ScriptArgScriptArgsArg
CommandArgJobIdArg	JobIdsArgScheduledJobIdArgJobVolumesOptjobs_clira   rg   r   r   r   r   r   r   r   r!  r9  r@  rE  rT  r]  rf  uv_app	add_grouprr  scheduled_appr  r  r  r  r  r  r  r  scheduled_uv_appr  r?  r   r   r   r  r  r   r   r   r   r8   r6   <module>r     sL   G      .    * * ! T T 9 + ) = 7 J    ) , 
		H	%. .t .cSVY]S]oH^ .8)#Y)',)9<t)	&\D)X    ' $J
= $J
rk*	 I
B	 $J
 ` $J
_
 
B	 $J
e $J
 o  I
 G	 
 p I
4 $J
D	 4K
0
 4K
G f 3	 I' I"
 - I.	 A  I
e	
 ?@	*u 	*7 	*t 	* 
	.5  
  #',0"#7,7,7, 
7, 	7,
 7, 7, 7, 7, !7, 7, 7, 7, 7, 
7, *7,  !7," #7,$ 
%7,
7,t 

  $ 	 	"'&x&x E	
	&x d
 J	
	&x$ %&x& '&x( 
)&x&xRT#s(^ d5cSVCW>X ]a '3 '4 '!)$sCx.!9JNs)eD#tDsO44568 
'%=$>?"A'A'A' A' 
	A' @A'H 
  
& 	 	 	 	 	" 	aFa	j	
	
Fa S	D!(+y	
	Fa" S	D O	
	#Fa2 d
Y	
	3Fa@ V	
	AFaN OFaP QFaR S	DE	
	SFab 
cFa
FaR 
*(:';<] =]6 
)'A&BC #hS	=	
	h h h 
h Dh* 
(&?%@A #	+	+	+ 	+ 
		+ B	+ 

  ( 	"4
S	?	
	4
 d
g	
	4
 4
 4
 
4
4
n 
   X]"EE
E E T6)2STTU	E
 E E 
EE: 
	   )-!"##%# # 	#
 # 
##L 
d	e   6  % 	.5  
 "& #',0")=,=,=, =, 	=,
 
=, =, =, =, =, =, !=, =, =, =, 
=,  *!=," #=,$ %=,& '=,( )=,* 
+=,
=,@ #QR   ={  3 	.5bc   "& #',0"%0t0t0t 0t 	0t
  0t 
0t 0t 0t 0t 0t 0t !0t 0t 0t 0t  *!0t" #0t$ %0t& 
'0t
0tf '3I2JK 	" 	%Wm	D	
	
Wm Wm Wm S	DQ	
	Wm& 
'Wm LWmt y,L+MN #x S	Q	
	x x x 
x Ox0 x+J*KL #	='	=	= 	= 
		= M	= y,L+MN #
Q'
Q
Q 
Q 
	
Q O
Q x+J*KL #	='	=	= 	= 
		= M	= y,L+MN #
Q'
Q
Q 
Q 
	
Q O
Q    bg"O'O
O O T6)2]^^_	O
 O O 
OOB !&QR    (t  4 	.5LF   "&"& #',0"+6`6`6` 6` 	6`
  6` 6` 6` 
6` 6` 6` 6` 6` 6` !6` 6`  !6`" *#6`$ %6`& '6`( )6`* +6`, 
-6`6`x	"S#X 	"4S>D3H 	"TRUWZRZ^ 	"\S4Z \S	D0@ \T \
 GK d3i$. t tTWY\T\~`dOd ,DcCi) DI # 6 CLU1X Xc8A;>N5O Y] bf 




)
)
3#
$ d	
 a[r8   