
    wiz)                     N   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j        e          Z G d de          Z G d d          Z G d d          Z G d de          Z G d de          Z G 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                   *    e Zd Zedefd            ZdS )RepoCommandsparserc                 
   |                      dd                              d          }                    fd           |                     dd          }|                    d	t          d
           |                    dt          d           |                    dt          dt
                     |                    ddd           |                    dt          d           |                    ddd           |                    dt          d           |                    d            |                     dd          }|                    ddd !          }|                     dd"          }|                    d	t          d#           |                    dt          d$           |                    d%d&t          d'           |                    d(t          d)           |                    dt          d*           |                    dg d+d,d-.           |                    d/            |                     d0d1          }|                    d	t          d2           |                    dt          d*           |                    dg d+d,d-.           |                    d3            |                     d4d5          }|                    d	t          d6           |                    dt          d7           |                    d8d9dd:           |                    dt          d*           |                    dg d+d,d-.           |                    d;            d S )<NrepozManage repos on the Hub.)helpz%huggingface.co repos related commandsc                 ,                                     S N)
print_help)argsrepo_parsers    p/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/huggingface_hub/cli/repo.py<lambda>z2RepoCommands.register_subcommand.<locals>.<lambda>0   s    ;3I3I3K3K     )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                      t          |           S r   )RepoCreateCommandr   s    r   r   z2RepoCommands.register_subcommand.<locals>.<lambda>X   s    :KD:Q:Q r   tagz"Manage tags for a repo on the Hub.zTag actions
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.)modeldatasetspacer+   z6Set the type of repository (model, dataset, or space).)r!   defaultr   c                      t          |           S r   )RepoTagCreateCommandr&   s    r   r   z2RepoCommands.register_subcommand.<locals>.<lambda>o       9Md9S9S r   listzList tags for a repo.z@The ID of the repo to list tags for (e.g. `username/repo-name`).c                      t          |           S r   )RepoTagListCommandr&   s    r   r   z2RepoCommands.register_subcommand.<locals>.<lambda>   s    7I$7O7O 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                      t          |           S r   )RepoTagDeleteCommandr&   s    r   r   z2RepoCommands.register_subcommand.<locals>.<lambda>   r1   r   )
add_parseradd_subparsersset_defaultsadd_argumentstrr	   )	r   repo_subparsersrepo_create_parserrepo_tag_parsertag_subparserstag_create_parsertag_list_parsertag_delete_parserr   s	           @r   register_subcommandz RepoCommands.register_subcommand*   s   ''5O'PP%44:a4bb 	  &K&K&K&K LLL -77Gl7mm'' [ 	( 	
 	
 	

 	''j 	( 	
 	
 	

 	''b$	 	( 	
 	
 	
 	''{ 	( 	
 	
 	

 	''_ 	( 	
 	
 	

 	''@ 	( 	
 	
 	

 	''! C 	( 	
 	
 	

 	''-Q-Q'RRR *44UAe4ff(77]Q]hl7mm +55hE_5``&&C&^ 	' 	
 	
 	
 	&&u3=]&^^^&&t[sIp&qqq&&|#D^&___&&C&r 	' 	
 	
 	
 	&&111I	 	' 	
 	
 	
 	&&,S,S&TTT )33FAX3YY$$C&h 	% 	
 	
 	
 	$$C&r 	% 	
 	
 	
 	$$111I	 	% 	
 	
 	
 	$$*O*O$PPP +55hE`5aa&&C&n 	' 	
 	
 	
 	&&u3=]&^^^&&tW\Pv&www&&C&r 	' 	
 	
 	
 	&&111I	 	' 	
 	
 	
 	&&,S,S&TTTTTr   N)__name__
__module____qualname__staticmethodr   rD    r   r   r   r   )   sH        fU$5 fU fU fU \fU fU fUr   r   c                   *    e Zd Zdej        fdZd ZdS )r%   r   c                     |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   s     r   __init__zRepoCreateCommand.__init__   sR     L(,(,!\$(J
"m040FGG			r   c           	      *   | j                             | j        | j        | j        | j        | j        | j        | j                  }t          dt          j        |j                   d           t          dt          j        |                      d S )N)r   rL   rN   rO   rP   rQ   rM   zSuccessfully created z on the Hub.zYour repo is now available at )rR   create_repor   rL   rN   rO   rP   rQ   rM   printr   bold)rT   repo_urls     r   runzRepoCreateCommand.run   s    9((LnL*]"4n ) 
 
 	Odi0@&A&AOOOPPPDty/B/BDDEEEEEr   N)rE   rF   rG   argparse	NamespacerU   r[   rI   r   r   r%   r%      sF        X/    F F F F Fr   r%   c                       e Zd Zd ZdS )RepoTagCommandc                     || _         t          t          |dd                     | _        |j        | _        t          |dd          | _        | j        t          vr t          d           t          d           d S d S )NrO   )rO   rL   r+   zInvalid repo --repo-type   )	r   r   getattrapir   rL   r   rX   exitrS   s     r   rU   zRepoTagCommand.__init__   sv    	wtWd;;<<<| {G<<>++,---GGGGG ,+r   N)rE   rF   rG   rU   rI   r   r   r_   r_      s#            r   r_   c                       e Zd Zd ZdS )r0   c                    t          dt          j        t          | j        j                             d| j         dt          j        | j                              	 | j        	                    | j        | j        j        t          | j        dd           t          | j        dd           | j                   nE# t          $ rU t          | j                                         dt          j        | j                   d           t          d           Y nt          $ rX t          d	t          j        t          t          | j        dd                                d           t          d           Y nt          $ r{}|j        j        d
k    rdt          dt          j        t          | j        j                             dt          j        | j                              t          d           |d }~ww xY wt          dt          j        t          | j        j                             dt          j        | j                              d S )NzYou are about to create tag  on  messagerevision)r   r'   tag_messagerj   rL    not found.ra   z	Revision i  Tag z already exists on z created on )rX   r   rY   r<   r   r'   rL   r   rc   
create_tagrb   r   
capitalizerd   r   r
   responsestatus_code)rT   es     r   r[   zRepoTagCreateCommand.run   s5   x49S5G5G+H+Hxxdnxx_c_himiu_v_vxx	
 	
 	
	HIM#DIy$?? J==.       ' 	 	 	T^..00WW49T\3J3JWWWXXXGGGGG$ 	 	 	_diGDIz4,P,P(Q(QRR___```GGGGG 	 	 	z%,,hTYs49='9'9::hhtyY]YeOfOfhhiiiQG		
 	YTYs49=1122YY	$,@W@WYYZZZZZs(   AB< <AG>AG>:	G>A6G99G>NrE   rF   rG   r[   rI   r   r   r0   r0      s(        [ [ [ [ [r   r0   c                       e Zd Zd ZdS )r4   c                    	 | j                             | j        | j                  }n# t          $ rU t          | j                                         dt          j        | j                   d           t          d           Y n_t          $ rS}t          |           t          t          j        |j        j                             t          d           Y d }~nd }~ww xY wt          |j                  dk    rt          d           t          d           t          d| j         dt          j        | j                   d           |j        D ]}t          |j                   d S )	N)r   rL   rh   rl   ra   r   zNo tags foundz	Tags for :)rc   list_repo_refsr   rL   r   rX   ro   r   rY   rd   r   redrp   textlentagsname)rT   refsrr   r'   s       r   r[   zRepoTagListCommand.run   sn   	8**. +  DD ' 	 	 	T^..00WW49T\3J3JWWWXXXGGGGG 	 	 	!HHH$(1:?++,,,GGGGGGGG	 ty>>Q/"""GGGE$.EE49T\+B+BEEEFFF9 	 	C#(OOOO	 	s   &) AC#	C#A	CC#Nrs   rI   r   r   r4   r4      s#            r   r4   c                       e Zd Zd ZdS )r7   c           
         t          dt          j        | j        j                   d| j         dt          j        | j                              t          | j        dd          sBt          d          	                                }|dvrt          d           t                       	 | j                            | j        | j        j        | j        	           n# t          $ rU t          | j                                         dt          j        | j                   d
           t          d           Y nft          $ rZ t          dt          j        | j        j                   dt          j        | j                              t          d           Y nw xY wt          dt          j        | j        j                   dt          j        | j                              d S )NzYou are about to delete tag rg   rh   yesFzProceed? [Y/n] ) yr   Abort)r   r'   rL   rl   ra   rm   z not found on z deleted on )rX   r   rY   r   r'   rL   r   rb   inputlowerrd   rc   
delete_tagr   ro   r   )rT   choices     r   r[   zRepoTagDeleteCommand.run   s   uTYty}-E-Euu4>uu\`\efjfr\s\suuvvvty%// 	,--3355F---g	H$)-SWSabbbb& 	 	 	T^..00WW49T\3J3JWWWXXXGGGGG$ 	 	 	Z49=11ZZ4<AXAXZZ[[[GGGGG	 	TTYty}--TT49T\;R;RTTUUUUUs   *1C AF:A FFNrs   rI   r   r   r7   r7      s(        V V V V Vr   r7   )__doc__r\   r   typingr   requests.exceptionsr   huggingface_hub.commandsr   #huggingface_hub.commands._cli_utilsr   huggingface_hub.constantsr   r	   huggingface_hub.errorsr
   r   r   huggingface_hub.hf_apir   huggingface_hub.utilsr   
get_loggerrE   loggerr   r%   r_   r0   r4   r7   rI   r   r   <module>r      s     & & & & & &       ) ) ) ) ) ) > > > > > > 4 4 4 4 4 4 B B B B B B B B a a a a a a a a a a ( ( ( ( ( ( ) ) ) ) ) ) 
	H	%	%hU hU hU hU hU, hU hU hUVF F F F F F F F2       [ [ [ [ [> [ [ [6       ,V V V V V> V V V V Vr   