o
    0i?                  $   @   s   d Z ddlZddlZddlmZmZ ddlZddlmZm	Z	m
Z
mZ ddlmZ ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ edd	Zejd
ddejddfddZ edd	Z!edd	Z"ej#e!dd ej#e"dd G dd de$ej%Z&eee' ej(ddd	f Z)eee' ej(ddd	f Z*eee$ ej(ddd	f Z+eee$ ej(ddd	f Z,eee- ej(dd d	f Z.ej/d!g d"d#ej0dddddd$ddddddddfd%ed&ed'eee$ ej(d(d	f d)ed*e)d+e*d,ed-ee'ej(d.d	f d/eee$ ej(d0d	f d1e+d2e,d3e.d4ed5ed6ed7eddf"d8d9Z1ej/d:d;d<gd#dej0ddddd$dddddddfd=ed>eee$ ej2d?d	f d&ed)ed*e)d+e*d,ed-ee'ej(d.d	f d1e+d2e,d3e.d4ed5ed6ed7eddf d@dAZ3ej/dBdCgd#ej0dd$fd%ed&ed,edDee'ej(dEd	f ddf
dFdGZ4ej/dHdIgd#dej0fd=ed>ed,ed&eddf
dJdKZ5ej/dLg dMd#dddddej0fd%edNeee& ej(dOd	f d)ed*e)d+e*d,ed&eddfdPdQZ6ej/dRg dSd#ej0dddd$dfd%edTee7e$ ej2dUd	f d&edVedWeee$ ej(dXd	f dYeee$ ej(dZd	f d[ee'ej(d\d	f d,eddfd]d^Z8e"j/d!d_d`gd#ddej0d$fd%edee$ej2dad	f dVed,ed&ed-ee'ej(dbd	f ddfdcddZ9e"j/dBdegd#dej0fd%edee$ej2dfd	f d,ed&eddf
dgdhZ:e!j/d!didjgd#dddej0fd%edee$ej2dkd	f dleee$ ej(dmdndod	f dVed,ed&eddfdpdqZ;e!j/drdsgd#dej0fd%ed,ed&eddfdtduZ<e!j/dBdvgd#d$dej0fd%edee$ej2dwd	f dxee'ej(dydzd{d	f d,ed&eddfd|d}Z=dS )~ae  Contains commands to interact with repositories on the Hugging Face Hub.

Usage:
    # create a new dataset repo on the Hub
    hf repos create my-cool-dataset --repo-type=dataset

    # create a private model repo on the Hub
    hf repos create my-cool-model --private

    # delete files from a repo on the Hub
    hf repos delete-files my-model file.txt
    N)	AnnotatedOptional)CLIErrorHfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError)ANSI   )
EnvFileOptEnvOpt
PrivateOpt	RepoIdArgRepoTypeRepoTypeOptRevisionOptSecretsFileOpt
SecretsOptTokenOptenv_map_to_key_value_list
get_hf_apiparse_env_maptyper_factoryzManage repos on the Hub.)helpT)Zinvoke_without_commandctxreturnc                 C   s&   | j dkrttdtjd d S d S )Nrepoz>FutureWarning: `hf repo` is deprecated in favor of `hf repos`.)file)Z	info_nameprintr   yellowsysstderr)r    r!   S/home/kim/smarthome/.venv/lib/python3.10/site-packages/huggingface_hub/cli/repos.py_repos_callback9   s   

r#   z"Manage tags for a repo on the Hub.z&Manage branches for a repo on the Hub.tag)namebranchc                   @   s   e Zd ZdZdZdZdS )GatedChoicesautomanualfalseN)__name__
__module____qualname__r(   r)   r*   r!   r!   r!   r"   r'   H   s    r'   z--publiczDWhether to make the repo public. Ignored if the repo already exists.z--protectedzVWhether to make the Space protected (Spaces only). Ignored if the repo already exists.z--flavorzOSpace hardware flavor (e.g. 'cpu-basic', 't4-medium', 'l4x4'). Only for Spaces.z	--storagezOSpace persistent storage tier ('small', 'medium', or 'large'). Only for Spaces.z--sleep-timez[Seconds of inactivity before the Space is put to sleep. Use -1 to disable. Only for Spaces.create)zhf repos create my-modelz8hf repos create my-dataset --repo-type dataset --privatezxhf repos create my-space --type space --space-sdk gradio --flavor t4-medium --secrets HF_TOKEN -e THEME=dark --protected)ZexamplesFrepo_id	repo_type	space_sdkzEHugging Face Spaces SDK type. Required when --type is set to 'space'.privatepublic	protectedtokenexist_okz-Do not raise an error if repo already exists.resource_group_idzoResource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.hardwarestorage
sleep_timesecretssecrets_fileenvenv_filec                 C   s   t |d}|j| |j|rdn	|rdn|rdnd|||||	|
|tt||tt||d}tdt|j d td	t|  dS )
zCreate a new repo on the Hub.r5   r2   r3   r4   N)r/   r0   
visibilityr5   r6   r7   r1   space_hardwarespace_storagespace_sleep_timespace_secretsspace_variablesSuccessfully created  on the Hub.Your repo is now available at )	r   Zcreate_repovaluer   r   r   r   boldr/   )r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   apirepo_urlr!   r!   r"   repo_createv   s"   
*rM   Z	duplicatez/hf repos duplicate openai/gdpval --type datasetzzhf repos duplicate multimodalart/dreambooth-training my-dreambooth --type space --flavor l4x4 --secrets HF_TOKEN --privatefrom_idto_idz_Destination repo ID (e.g. `myorg/my-copy`). Defaults to your namespace with the same repo name.c                 C   s   t |d}|j| ||j|rdn	|rdn|rdnd||||	|
tt||tt||d}tdt|  dt|j d	 td
t|  dS )z7Duplicate a repo on the Hub (model, dataset, or Space).r?   r2   r3   r4   N)rN   rO   r0   r@   r5   r6   rA   rB   rC   rD   rE   zSuccessfully duplicated  to rG   rH   )	r   Zduplicate_reporI   r   r   r   r   rJ   r/   )rN   rO   r0   r2   r3   r4   r5   r6   r8   r9   r:   r;   r<   r=   r>   rK   rL   r!   r!   r"   repo_duplicate   s    
#$rQ   deletezhf repos delete my-model
missing_okz=If set to True, do not raise an error if repo does not exist.c                 C   s6   t |d}|j| |j|d tdt|  d dS )z>Delete a repo from the Hub. This is an irreversible operation.r?   )r/   r0   rS   Successfully deleted rG   N)r   Zdelete_reporI   r   r   rJ   )r/   r0   r5   rS   rK   r!   r!   r"   repo_delete   s   
rU   movez;hf repos move old-namespace/my-model new-namespace/my-modelc                 C   sB   t |d}|j| ||jd tdt|  dt| d dS )z8Move a repository from a namespace to another namespace.r?   )rN   rO   r0   zSuccessfully moved rP   rG   N)r   Z	move_reporI   r   r   rJ   )rN   rO   r5   r0   rK   r!   r!   r"   	repo_move   s   
&rW   settings)z$hf repos settings my-model --privatez'hf repos settings my-model --gated autoz8hf repos settings my-space --repo-type space --protectedgatedz$The gated status for the repository.c                 C   sZ   t |d}|j| |r|jnd|rdn	|rdn|rdnd|jd tdt|  d dS )	z$Update the settings of a repository.r?   Nr2   r3   r4   )r/   rY   r@   r0   z%Successfully updated the settings of rG   )r   Zupdate_repo_settingsrI   r   r   rJ   )r/   rY   r2   r3   r4   r5   r0   rK   r!   r!   r"   repo_settings  s   
rZ   zdelete-files)z'hf repos delete-files my-model file.txtz'hf repos delete-files my-model "*.json"z&hf repos delete-files my-model folder/patternszXGlob patterns to match files to delete. Based on fnmatch, '*' matches files recursively.revisioncommit_messagez9The summary / title / first line of the generated commit.commit_descriptionz(The description of the generated commit.	create_prz7Whether to create a new Pull Request for these changes.c           
   	   C   s8   t |d}|j|| |j||||d}	td|	 d dS )z$Delete files from a repo on the Hub.r?   )Zdelete_patternsr/   r0   r\   r]   r^   r_   z+Files correctly deleted from repo. Commit: .N)r   Zdelete_filesrI   r   )
r/   r[   r0   r\   r]   r^   r_   r5   rK   urlr!   r!   r"   repo_delete_files0  s   
'	rb   z#hf repos branch create my-model devz5hf repos branch create my-model dev --revision abc123z!The name of the branch to create.z?If set to True, do not raise an error if branch already exists.c              	   C   sL   t |d}|j| |||j|d tdt| d|j dt|   dS )z*Create a new branch for a repo on the Hub.r?   )r/   r&   r\   r0   r6   rF    branch on  N)r   Zcreate_branchrI   r   r   rJ   )r/   r&   r\   r5   r0   r6   rK   r!   r!   r"   branch_created  s   
,re   z#hf repos branch delete my-model devz!The name of the branch to delete.c              	   C   sH   t |d}|j| ||jd tdt| d|j dt|   dS )z'Delete a branch from a repo on the Hub.r?   )r/   r&   r0   rT   rc   rd   N)r   Zdelete_branchrI   r   r   rJ   )r/   r&   r5   r0   rK   r!   r!   r"   branch_delete  s   
,rf   z!hf repos tag create my-model v1.0z4hf repos tag create my-model v1.0 -m "First release"zThe name of the tag to create.messagez-mz	--messagez%The description of the tag to create.c           	   
   C   s
  |j }t|d}tdt| d| dt|   z|j| ||||d W nK ty@ } zt|  d|  d|d}~w t	yT } z	td	| d|d}~w t
yr } z|jjd
krmtd| d|  d| d}~ww tdt| dt|   dS )zCreate a tag for a repo.r?   zYou are about to create tag  on rd   )r/   r$   Ztag_messager\   r0    '' not found.Nz
Revision 'i  Tag 'z' already exists on ''.Tag z created on )rI   r   r   r   rJ   Z
create_tagr   r   
capitalizer   r   responsestatus_code)	r/   r$   rg   r\   r5   r0   repo_type_strrK   er!   r!   r"   
tag_create  s$   
&$rs   z	list | lszhf repos tag list my-modelc              
   C   s   |j }t|d}z	|j| |d}W n ty* } zt|  d|  d|d}~ww t|jdkr<td t	j
ddtd	| d
t|  d |jD ]}t|j qMdS )zList tags for a repo.r?   )r/   r0   ri   rj   Nr   zNo tags found)codez	Tags for rd   :)rI   r   Zlist_repo_refsr   r   rn   lentagsr   typerExitr   rJ   r%   )r/   r5   r0   rq   rK   refsrr   tr!   r!   r"   tag_list  s   

r|   z!hf repos tag delete my-model v1.0zThe name of the tag to delete.yesz-yz--yesz"Answer Yes to prompt automaticallyc           	   
   C   s   |j }tdt| d| dt|   |s*td }|dvr*td t t|d}z
|j	| ||d W n0 t
yR } zt|  d	|  d
|d}~w tyi } ztd| d|  d|d}~ww tdt| dt|   dS )zDelete a tag for a repo.zYou are about to delete tag rh   rd   zProceed? [Y/n] ) yr}   ZAbortr?   )r/   r$   r0   ri   rj   Nrk   z' not found on 'rl   rm   z deleted on )rI   r   r   rJ   inputlowerrx   ry   r   Z
delete_tagr   r   rn   r   )	r/   r$   r}   r5   r0   rq   choicerK   rr   r!   r!   r"   
tag_delete  s$   &
$r   )>__doc__enumr   typingr   r   rx   Zhuggingface_hub.errorsr   r   r   r   Zhuggingface_hub.utilsr   Z
_cli_utilsr
   r   r   r   r   r   r   r   r   r   r   r   r   r   Z	repos_clicallbackContextr#   Ztag_cliZ
branch_cliZ	add_typerstrEnumr'   boolOptionZ	PublicOptZProtectedOptZSpaceHardwareOptZSpaceStorageOptintZSpaceSleepTimeOptcommandmodelrM   ZArgumentrQ   rU   rW   rZ   listrb   re   rf   rs   r|   r   r!   r!   r!   r"   <module>   s  @



	
	
 5	
.
	
	
,	
		
%