Ë
    rPêjµ$  ã                   ón  — d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlZdd	lmZ dd
lmZ ddlmZmZ  ej2                  d«      ZdZe G d„ d«      «       Z ed„  e
e«      D «       «      Ze G d„ d«      «       Zede deeddf   fd„«       Z!de dedz  fd„Z"de dedefd„Z#de de dz  fd„Z$de de%e ef   fd„Z&de ded e defd!„Z'd"e%e ef   de de dz  fd#„Z(d"e%e ef   de dz  fd$„Z)d"e%e ef   de de%e e f   fd%„Z*d"e%e ef   de de+e    fd&„Z,d"e%e ef   de+e    fd'„Z-y)(z¡Read launch defaults from a UV script's optional `[tool.hf-jobs]` PEP 723 table.

See the CLI guide for the header format and `cli/jobs.py` for the merge rules.
é    N)Ú	Generator)Úcontextmanager)Ú	dataclassÚfieldÚfields)ÚPath)ÚAny)Úurlsplit)Ú	constants)ÚCLIError)ÚSoftTemporaryDirectoryÚget_sessionzG(?m)^# /// (?P<type>[a-zA-Z0-9-]+)$\s(?P<content>(^#(| .*)$\s)+)^# ///$ztool.hf-jobsc                   óP  — e Zd ZU dZdZedz  ed<   dZedz  ed<   dZedz  ed<   dZ	edz  ed<   dZ
edz  ed<   dZedz  ed<   dZedz  ed	<    ee¬
«      Zeeef   ed<    ee¬
«      Zee   ed<    ee¬
«      Zeeef   ed<    ee¬
«      Zee   ed<    ee¬
«      Zee   ed<   y)ÚUvScriptHeaderzWThe `[tool.hf-jobs]` table of a UV script: the launch configuration the script carries.NÚimageÚflavorÚpythonÚtimeoutÚnameÚ	namespaceÚnetwork_group)Údefault_factoryÚenvÚsecretsÚlabelsÚvolumesÚnetwork_aliases)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚstrÚ__annotations__r   r   r   r   r   r   r   Údictr   Úlistr   r   r   r   © ó    új/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/huggingface_hub/cli/_uv_script_header.pyr   r   )   sÎ   … áaà€Eˆ3�‰:ÓØ€FˆC�$‰JÓØ€FˆC�$‰JÓØ€GˆS�4‰ZÓØ€Dˆ#�‰*ÓØ €Iˆs�T‰zÓ Ø $€M�3˜‘:Ó$Ù°Ô5€Cˆˆc�3ˆh‰Ó5Ù¨tÔ4€GˆT�#‰YÓ4Ù"°4Ô8€FˆD��c�‰NÓ8Ù¨tÔ4€GˆT�#‰YÓ4Ù!&°tÔ!<€O�T˜#‘YÔ<r'   r   c              #   ó4   K  — | ]  }|j                   –— Œ y ­w©N)r   )Ú.0Úfs     r(   ú	<genexpr>r-   ;   s   è ø€ Ò:˜a�1—6•6Ñ:ùs   ‚c                   ó2   — e Zd ZU dZeed<   	 dZedz  ed<   y)ÚUvScriptzNA UV script ready to be submitted, with the launch config it carries (if any).ÚscriptNÚheader)r   r   r    r!   r"   r#   r1   r   r&   r'   r(   r/   r/   >   s   … áXàƒKØià$(€FˆN˜TÑ!Ó(ØJr'   r/   r0   Úreturnc           	   #   ó¢  K  — | j                  d«      r\t        d¬«      5 }t        | t        |«      «      }t	        t        |«      t        |j                  d¬«      «      ¬«      –— ddd«       yt        | «      }|j                  «       r)t	        | t        |j                  d¬«      «      ¬«      –— yt	        | ¬«      –— y# 1 sw Y   yxY w­w)	a‹  Resolve a `hf jobs uv run` script argument and read its `[tool.hf-jobs]` header.

    - a local file is read in place
    - an `http(s)` URL is downloaded to a temporary directory and from there shipped to the Job like
      any local script: the URL is fetched exactly once, at submit time, instead of being fetched
      again by the container (the header has to be read client-side anyway, since `image`, `flavor`,
      `secrets`, ... are all decided before the container exists). The download lives until the
      `with` block exits, i.e. until the Job is submitted.
    - anything else is a command (e.g. `lighteval`) and carries no header
    )zhttp://zhttps://zhf-jobs-uv-)Úprefixzutf-8)Úencoding)r0   r1   N)r0   )	Ú
startswithr   Ú_download_scriptr   r/   r"   Úparse_uv_script_headerÚ	read_textÚis_file)r0   Útmp_dirÚ
local_pathÚpaths       r(   Úload_uv_scriptr>   I   s´   è ø€ ð ×ÑÐ0Ô1Ü#¨=Ô9ð 	¸WÜ)¨&´$°w³-Ó@ˆJÜÜ˜:“Ô/EÀj×FZÑFZÐdkÐFZÓFlÓ/môò ÷	ð
 	Ü�‹<€DØ‡|�|„~Ü˜fÔ-CÀDÇNÁNÐ\cÀNÓDdÓ-eÔfÒfØÜ
˜&Ô
!Ó!÷	ð
 	üs   ‚C ACÁ'ACÃCÃCÚtextc                 óš  — t        | «      }|�d|vryt        |«      j                  di «      j                  d«      }|€yt        |t        «      st        dt        › dt        › d�«      ‚t        d„ |D «       «      x}rBt        dd	j                  d
„ |D «       «      › dt        › dd	j                  t        «      › d�«      ‚t        t        |d«      t        |d«      t        |d«      t        |«      t        |d«      t        |d«      t        |d«      t        |d«      t        |«      t        |d«      t        |d«      t        |d«      ¬«      S )z\Parse the `[tool.hf-jobs]` table out of a script's PEP 723 header. Returns `None` if absent.Nzhf-jobsÚtoolú'z9' must be a table in the script's PEP 723 header (i.e. `[z]`).c              3   ó2   K  — | ]  }|t         vsŒ|–— Œ y ­wr*   )Ú
VALID_KEYS©r+   Úkeys     r(   r-   z)parse_uv_script_header.<locals>.<genexpr>q   s   è ø€ ÒG °¼JÒ1FœÑGùs   ‚�zUnknown key(s) z, c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr*   )ÚreprrE   s     r(   r-   z)parse_uv_script_header.<locals>.<genexpr>s   s   è ø€ Ò'E°c¬¨S¯	Ñ'Eùs   ‚z in the script's [z] table. Valid keys are: ú.r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )Ú_extract_pep_723_blockÚ
_load_tomlÚgetÚ
isinstancer$   r   Ú
TABLE_NAMEÚsortedÚjoinrD   r   Ú_as_strÚ_as_timeoutÚ_as_str_tableÚ_as_secret_namesÚ_as_str_list)r?   ÚcontentÚtableÚunknowns       r(   r8   r8   e   sP  € ä$ TÓ*€Gà€˜)¨7Ñ2ØÜ�wÓ×#Ñ# F¨BÓ/×3Ñ3°IÓ>€EØ€}ØÜ�eœTÔ"Ü˜œ:˜,Ð&_Ô`jÐ_kÐkoÐpÓqÐqäÑG¨ÔGÓGÐG€wÐGÜØ˜dŸi™iÑ'E¸WÔ'EÓEÐFÐFXÔYcÐXdð e Ø $§	¡	¬*Ó 5Ð6°að9ó
ð 	
ô Ü�e˜WÓ%Ü�u˜hÓ'Ü�u˜hÓ'Ü˜EÓ"Ü�U˜FÓ#Ü˜% Ó-Ü˜e _Ó5Ü˜% Ó'Ü  Ó'Ü˜U HÓ-Ü˜U IÓ.Ü$ UÐ,=Ó>ôð r'   ÚurlÚdest_dirc                 óŠ  — t        t        | «      j                  «      j                  }||j	                  d«      r|ndz  }	 t        «       j                  | t        j                  ¬«      }|j                  «        |j                  |j                  «       |S # t        j                  $ r}t        d| › d|› �«      |‚d}~ww xY w)zFDownload a remote UV script into `dest_dir` and return its local path.z.pyz	script.py)r   z'Could not download the UV script from 'z': N)r   r
   r=   r   Úendswithr   rL   r   ÚDEFAULT_REQUEST_TIMEOUTÚraise_for_statusÚhttpx2Ú	HTTPErrorr   Úwrite_bytesrV   )rY   rZ   r   r<   ÚresponseÚes         r(   r7   r7   †   s´   € ä”˜“×"Ñ"Ó#×(Ñ(€DØ T§]¡]°5Ô%9™T¸{ÑK€JðUä“=×$Ñ$ S´)×2SÑ2SÐ$ÓTˆØ×!Ñ!Ô#ð ×Ñ˜8×+Ñ+Ô,ØÐøô ×Ñò UÜÐ@ÀÀÀSÈÈÐLÓMÐSTÐTûðUús   Á9B ÂCÂ+B=Â=Cc                 ó  — | j                  dd«      j                  dd«      } t        j                  | «      D ]O  }|j                  d«      dk(  sŒdj	                  d„ |j                  d«      j                  d	¬
«      D «       «      c S  y)zXReturn the content of the first PEP 723 `script` block, with the `# ` prefixes stripped.z
ú
úÚtyper0   Ú c              3   óR   K  — | ]  }|j                  d «      r|dd n|dd –— Œ! y­w)z# é   Né   )r6   )r+   Úlines     r(   r-   z)_extract_pep_723_block.<locals>.<genexpr>›   s4   è ø€ ò àð !ŸO™O¨DÔ1��Q�R‘°t¸A¸B°xÓ?ñùs   ‚%'rV   T)ÚkeependsN)ÚreplaceÚ_PEP_723_REGEXÚfinditerÚgrouprP   Ú
splitlines)r?   Úmatchs     r(   rJ   rJ   ”   s†   € ð �<‰<˜ Ó%×-Ñ-¨d°DÓ9€DÜ×(Ñ(¨Ó.ò ˆØ�;‰;�vÓ (Ó*Ø—7‘7ñ à!ŸK™K¨	Ó2×=Ñ=ÀtÐ=ÓLôó ò ðð r'   rV   c                 óö   — t         j                  dk\  rdd l}n	 dd l}	 |j                  | «      S # t        $ r}t        dt        › d�«      |‚d }~ww xY w# |j                  $ r}t        d|› �«      |‚d }~ww xY w)N)é   é   r   zReading the [zo] table of a UV script requires a TOML parser. Upgrade to Python 3.11+ or install one with `pip install tomli`.z-Invalid TOML in the script's PEP 723 header: )	ÚsysÚversion_infoÚtomllibÚtomliÚImportErrorr   rN   ÚloadsÚTOMLDecodeError)rV   ry   rc   s      r(   rK   rK   ¢   s–   € Ü
×Ñ˜7Ò"Üð	Û#ðSØ�}‰}˜WÓ%Ð%øô ò 	ÜØ¤
˜|ð ,Tð Tóð ðûð	ûð ×"Ñ"ò SÜÐFÀqÀcÐJÓKÐQRÐRûðSús+   š0 ŸA °	A¹AÁAÁA8Á$A3Á3A8rF   ÚvalueÚexpectedc                 ó:   — t        d| › dt        › d|› d|›d�	«      S )NrB   z' in the script's [z] table must be z, got: rI   )r   rN   )rF   r~   r   s      r(   Ú_type_errorr�   ³   s.   € Ü�a˜�uÐ/´
¨|Ð;KÈHÈ:ÐU\Ð]bÐ\eÐefÐgÓhÐhr'   rW   c                 óh   — | j                  |«      }|€y t        |t        «      st        ||d«      ‚|S )Núa string)rL   rM   r"   r�   ©rW   rF   r~   s      r(   rQ   rQ   ·   s5   € Ø�I‰I�c‹N€EØ€}ØÜ�eœSÔ!Ü˜#˜u jÓ1Ð1Ø€Lr'   c                 ó¦   — | j                  d«      }|€y t        |t        «      st        |t        t        f«      st        d|d«      ‚t        |«      S )Nr   z5a duration string (e.g. "30m") or a number of seconds)rL   rM   Úboolr"   Úintr�   )rW   r~   s     r(   rR   rR   À   sI   € Ø�I‰I�iÓ €EØ€}ØÜ�%œÔ¤j°¼¼c¸
Ô&CÜ˜) UÐ,cÓdÐdÜˆu‹:Ðr'   c                 óÞ   — | j                  |«      }|€i S t        |t        «      st        ||d«      ‚|j	                  «       D ]'  \  }}t        |t
        «      rŒt        |› d|› �|d«      ‚ |S )Nza table of stringsrI   rƒ   )rL   rM   r$   r�   Úitemsr"   )rW   rF   r~   r   Úitems        r(   rS   rS   É   sx   € Ø�I‰I�c‹N€EØ€}Øˆ	Ü�eœTÔ"Ü˜#˜uÐ&:Ó;Ð;Ø—k‘k“mò A‰
ˆˆdä˜$¤Õ$Ü   Q t f˜o¨t°ZÓ@Ð@ðAð €Lr'   c                 óŽ   — | j                  |«      }|€g S t        |t        «      rt        d„ |D «       «      rt	        ||d«      ‚|S )Nc              3   ó>   K  — | ]  }t        |t        «       –— Œ y ­wr*   )rM   r"   )r+   rŠ   s     r(   r-   z_as_str_list.<locals>.<genexpr>Ú   s   è ø€ Ò)VÈ¬j¸¼sÓ.CÔ*CÑ)Vùs   ‚za list of strings)rL   rM   r%   Úanyr�   r„   s      r(   rU   rU   Ö   sF   € Ø�I‰I�c‹N€EØ€}Øˆ	Ü�eœTÔ"¤cÑ)VÐPUÔ)VÔ&VÜ˜#˜uÐ&9Ó:Ð:Ø€Lr'   c                 ó~   — t        | j                  d«      t        «      rt        dt        › d�«      ‚t        | d«      S )Nr   z'secrets' in the script's [z¸] table must be a list of names (e.g. `secrets = ["HF_TOKEN"]`), not a table: scripts travel publicly, so secret values are always read from the environment of whoever runs the script.)rM   rL   r$   r   rN   rU   )rW   s    r(   rT   rT   ß   sB   € Ü�%—)‘)˜IÓ&¬Ô-ÜØ)¬*¨ð 6(ð (ó
ð 	
ô
 ˜˜yÓ)Ð)r'   ).r!   Úrerw   Úcollections.abcr   Ú
contextlibr   Údataclassesr   r   r   Úpathlibr   Útypingr	   Úurllib.parser
   r_   Úhuggingface_hubr   Úhuggingface_hub.errorsr   Úhuggingface_hub.utilsr   r   Úcompilero   rN   r   ÚtuplerD   r/   r"   r>   r8   r7   rJ   r$   rK   r�   rQ   rR   rS   r%   rU   rT   r&   r'   r(   ú<module>r›      s  ðñó
 
Û 
Ý %Ý %ß 0Ñ 0Ý Ý Ý !ã å %Ý +ß Eð �—‘ÐfÓg€à€
ð ÷=ð =ó ð=ñ" Ñ:¡6¨.Ó#9Ô:Ó:€
ð ÷Kð Kó ðKð ð"˜3ð " 9¨X°t¸TÐ-AÑ#Bò "ó ð"ð6 ð ¨¸$Ñ)>ó ðB˜#ð ¨ð °$ó ð ð ¨¨t©ó ðS˜ð S  S¨# X¡ó Sð"i�Sð i ð i°ð i¸ó ið�4˜˜S˜‘>ð ¨ð °°d±
ó ð�t˜C ˜H‘~ð ¨#°©*ó ð
˜˜c 3˜h™ð 
¨cð 
°d¸3À¸8±nó 
ð˜˜S #˜X™ð ¨Sð °T¸#±Yó ð*˜D  c ™Nð *¨t°C©yô *r'   