o
    0i|                     @   s  d Z ddlZddlmZmZ ddlZddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZmZmZmZ d	d
lmZmZmZmZ eeZeddZejdg dd			d2dedeeejddf deeejddf ddfddZ ejdddgd	d3deee! ejddf ddfddZ"dee! fd d!Z#ejd"d#d$gd		d4deee! ejd%df deeejddf ddfd&d'Z$ejd(d)gdd5d*d+Z%ejd,d-d.gdej&fd/eddfd0d1Z'dS )6a  Contains commands to authenticate to the Hugging Face Hub and interact with your repositories.

Usage:
    # login and save token locally.
    hf auth login --token=hf_*** --add-to-git-credential

    # switch between tokens
    hf auth switch

    # list all tokens
    hf auth list

    # logout from all tokens
    hf auth logout

    # check which account you are logged in as
    hf auth whoami
    N)	AnnotatedOptional)ENDPOINT)whoami   )	auth_listauth_switchloginlogout)ANSIget_stored_tokens	get_tokenlogging   )	FormatOptOutputFormatTokenOpttyper_factoryz,Manage authentication (login, logout, etc.).)helpr	   )zhf auth loginzhf auth login --token $HF_TOKENz7hf auth login --token $HF_TOKEN --add-to-git-credentialzhf auth login --force)ZexamplesFtokenadd_to_git_credentialzTSave to git credential helper. Useful only if you plan to run git commands directly.forcez)Force re-login even if already logged in.returnc                 C   s   t | || d dS )z8Login using a token from huggingface.co/settings/tokens.)r   r   Zskip_if_logged_inN)r	   )r   r   r    r   R/home/kim/smarthome/.venv/lib/python3.10/site-packages/huggingface_hub/cli/auth.py
auth_login4   s   r   r
   zhf auth logoutz$hf auth logout --token-name my-token
token_namezName of token to logoutc                 C   s   t | d dS )zLogout from a specific token.r   N)r
   r   r   r   r   auth_logoutP   s   r   c                  C   s   t t  } | std d S td t| dD ]\}}t| d|  q	 z,td}| dkr6W d S t	|d }d|  krHt
| k rOn n| | W S td	 W n tya   td
 Y nw q()Nz+No stored tokens found. Please login first.zAvailable stored tokens:r   z. Tz=Enter the number of the token to switch to (or 'q' to quit): qr   z$Invalid selection. Please try again.z4Invalid input. Please enter a number or 'q' to quit.)listr   keysloggererrorprint	enumerateinputlowerintlen
ValueError)Ztoken_namesir   choiceindexr   r   r   _select_token_name^   s(   

r.   switchzhf auth switchz$hf auth switch --token-name my-tokenzName of the token to switch toc                 C   s6   | du rt  } | du rtd t t| |d dS )zSwitch between access tokens.Nz!No token name provided. Aborting.)r   )r.   r$   typerExitr   )r   r   r   r   r   auth_switch_cmdv   s   r2   z	list | lszhf auth listc                   C   s
   t   dS )zList all stored access tokens.N)r   r   r   r   r   auth_list_cmd   s   
r3   r   zhf auth whoamizhf auth whoami --format jsonformatc                 C   s   t  }|du r!| tjkrttddi t td t t|}| tjkr6ttj|dtd dS tt	
d|d  dd	 |d
 D }|rVtt	
dd| tdkrctdt  dS dS )z;Find out which huggingface.co account you are logged in as.Nr#   zNot logged inr   )indentdefaultzuser: namec                 S   s   g | ]}|d  qS )r7   r   ).0orgr   r   r   
<listcomp>   s    zauth_whoami.<locals>.<listcomp>orgszorgs: ,zhttps://huggingface.coz(Authenticated through private endpoint: )r   r   jsonr$   dumpsr0   r1   r   strr   boldjoinr   )r4   r   infor;   r   r   r   auth_whoami   s"   

rC   )NFF)N)NF)r   N)(__doc__r=   typingr   r   r0   Zhuggingface_hub.constantsr   Zhuggingface_hub.hf_apir   Z_loginr   r   r	   r
   utilsr   r   r   r   Z
_cli_utilsr   r   r   r   Z
get_logger__name__r"   Zauth_clicommandboolOptionr   r?   r   r.   r2   r3   tablerC   r   r   r   r   <module>   s   





