o
    0 iz)                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ dd	lmZmZmZ dd
lmZ ddlmZ eeZG dd deZG dd dZG dd dZG dd deZG dd deZG dd deZdS )a  Contains commands to interact with repositories on the Hugging Face Hub.

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

    # create a private model repo on the Hub
    hf repo create my-cool-model --private
    N)_SubParsersAction)Optional)	HTTPError)BaseHuggingfaceCLICommand)ANSI)
REPO_TYPESSPACES_SDK_TYPES)HfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError)HfApi)loggingc                   @   s   e Zd ZedefddZdS )RepoCommandsparserc                    s0  | j ddd  jdd} j fddd |j dd	d}|jd
tdd |jdtdd |jdtdtd |jdddd |jdtdd |jdddd |jdtdd |jdd d |j ddd}|jdd d!d"}|j dd#d}|jd
td$d |jdtd%d |jd&d'td(d |jd)td*d |jdtd+d |jdg d,d-d.d/ |jd0d d |j d1d2d}|jd
td3d |jdtd+d |jdg d,d-d.d/ |jd4d d |j d5d6d}|jd
td7d |jdtd8d |jd9d:dd;d |jdtd+d |jdg d,d-d.d/ |jd<d d d S )=NrepozManage repos on the Hub.)helpz%huggingface.co repos related commandsc                    s      S N)
print_helpargsZrepo_parser d/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/huggingface_hub/cli/repo.py<lambda>0       z2RepoCommands.register_subcommand.<locals>.<lambda>)funccreatez#Create a new repo on huggingface.corepo_idzThe ID of the repo to create to (e.g. `username/repo-name`). The username is optional and will be set to your username if not provided.)typer   z--repo-typezWOptional: set to "dataset" or "space" if creating a dataset or space, default is model.z--space_sdkzOOptional: Hugging Face Spaces SDK type. Required when --type is set to "space".)r   r   choicesz	--private
store_truezhWhether to create a private repository. Defaults to public unless the organization's default is private.)actionr   z--tokenzLHugging Face token. Will default to the locally saved token if not provided.z
--exist-okz-Do not raise an error if repo already exists.z--resource-group-idzoResource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.c                 S      t | S r   )RepoCreateCommandr   r   r   r   r   X   r   tagz"Manage tags for a repo on the Hub.zTag actionsZ
tag_actionT)r   destrequiredzCreate a tag for a repo.z6The ID of the repo to tag (e.g. `username/repo-name`).zThe name of the tag to create.z-mz	--messagez%The description of the tag to create.z
--revisionzThe git revision to tag.zJA User Access Token generated from https://huggingface.co/settings/tokens.)modelZdatasetspacer'   z6Set the type of repository (model, dataset, or space).)r   defaultr   c                 S   r"   r   )RepoTagCreateCommandr   r   r   r   r   o   r   listzList tags for a repo.z@The ID of the repo to list tags for (e.g. `username/repo-name`).c                 S   r"   r   )RepoTagListCommandr   r   r   r   r      r   deletezDelete a tag from a repo.zFThe ID of the repo to delete the tag from (e.g. `username/repo-name`).zThe name of the tag to delete.z-yz--yesz$Answer Yes to prompts automatically.c                 S   r"   r   )RepoTagDeleteCommandr   r   r   r   r      r   )
add_parseradd_subparsersset_defaultsadd_argumentstrr   )r   Zrepo_subparsersZrepo_create_parserZrepo_tag_parserZtag_subparsersZtag_create_parserZtag_list_parserZtag_delete_parserr   r   r   register_subcommand*   s   z RepoCommands.register_subcommandN)__name__
__module____qualname__staticmethodr   r4   r   r   r   r   r   )   s    r   c                   @   s$   e Zd ZdejfddZdd ZdS )r#   r   c                 C   sD   |j | _ |j| _|j| _|j| _|j| _|j| _|j| _t | _d S r   )	r   	repo_type	space_sdkprivatetokenexist_okresource_group_idr   _apiselfr   r   r   r   __init__   s   zRepoCreateCommand.__init__c              	   C   sX   | j j| j| j| j| j| j| j| jd}t	dt
|j d t	dt
|  d S )N)r   r9   r;   r<   r=   r>   r:   zSuccessfully created z on the Hub.zYour repo is now available at )r?   Zcreate_repor   r9   r;   r<   r=   r>   r:   printr   bold)rA   repo_urlr   r   r   run   s   	zRepoCreateCommand.runN)r5   r6   r7   argparse	NamespacerB   rF   r   r   r   r   r#      s    
r#   c                   @      e Zd Zdd ZdS )RepoTagCommandc                 C   sR   || _ tt|dd d| _|j| _t|dd| _| jtvr'td td d S d S )Nr<   )r<   r9   r'   zInvalid repo --repo-type   )	r   r   getattrapir   r9   r   rC   exitr@   r   r   r   rB      s   
zRepoTagCommand.__init__N)r5   r6   r7   rB   r   r   r   r   rJ          rJ   c                   @   rI   )r*   c                 C   sh  t dtt| jj d| j dt| j  z| jj	| j| jjt
| jdd t
| jdd | jd W nh tyR   t | j  dt| j d td Y nK typ   t d	ttt
| jdd  d td Y n- ty } z!|jjd
krt dtt| jj dt| j  td |d }~ww t dtt| jj dt| j  d S )NzYou are about to create tag  on  messagerevision)r   r$   Ztag_messagerS   r9    not found.rK   z	Revision i  Tag z already exists on z created on )rC   r   rD   r3   r   r$   r9   r   rM   Z
create_tagrL   r
   
capitalizerN   r   r	   responsestatus_code)rA   er   r   r   rF      s2   ,
"$*.zRepoTagCreateCommand.runNr5   r6   r7   rF   r   r   r   r   r*      rO   r*   c                   @   rI   )r,   c              
   C   s   z| j j| j| jd}W n@ ty*   t| j  dt| j d t	d Y n# t
yL } zt| tt|jj t	d W Y d }~nd }~ww t|jdkr\td t	d td| j dt| j d |jD ]}t|j qod S )	N)r   r9   rQ   rT   rK   r   zNo tags foundz	Tags for :)rM   Zlist_repo_refsr   r9   r
   rC   rV   r   rD   rN   r   redrW   textlentagsname)rA   refsrY   r$   r   r   r   rF      s*   
" 
zRepoTagListCommand.runNrZ   r   r   r   r   r,      rO   r,   c                   @   rI   )r.   c              
   C   s"  t dt| jj d| j dt| j  t| jdds/td	 }|dvr/t d t
  z| jj| j| jj| jd	 W n= ty\   t | j  dt| j d
 t
d Y n  ty{   t dt| jj dt| j  t
d Y nw t dt| jj dt| j  d S )NzYou are about to delete tag rP   rQ   yesFzProceed? [Y/n] ) yrb   ZAbort)r   r$   r9   rT   rK   rU   z not found on z deleted on )rC   r   rD   r   r$   r9   r   rL   inputlowerrN   rM   Z
delete_tagr
   rV   r   )rA   choicer   r   r   rF      s    ."&*zRepoTagDeleteCommand.runNrZ   r   r   r   r   r.      rO   r.   )__doc__rG   r   typingr   Zrequests.exceptionsr   Zhuggingface_hub.commandsr   Z#huggingface_hub.commands._cli_utilsr   Zhuggingface_hub.constantsr   r   Zhuggingface_hub.errorsr	   r
   r   Zhuggingface_hub.hf_apir   Zhuggingface_hub.utilsr   Z
get_loggerr5   loggerr   r#   rJ   r*   r,   r.   r   r   r   r   <module>   s$   

k