o
    i                     @   s  d Z ddlZddlZddlmZmZmZ ddlZddlm	Z	m
Z
mZ ddlmZ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eeZeeZ ej!dd	d
 e D e"dZ#eee" ej$dd%e deedf Z&eddZ'e'j(dddgdddddddej)ddf	dedededeee# ej$ddf dede&ded ed!ed"dfd#d$Z*e'j(d%d&d'gd			d-d(ee"ej+d)df d*ede&d!ed"df
d+d,Z,dS ).a  Contains commands to interact with spaces on the Hugging Face Hub.

Usage:
    # list spaces on the Hub
    hf spaces ls

    # list spaces with a search query
    hf spaces ls --search "chatbot"

    # get info about a space
    hf spaces info enzostvs/deepsite
    N)	AnnotatedOptionalget_args)CLIErrorRepositoryNotFoundErrorRevisionNotFoundError)ExpandSpaceProperty_TSpaceSort_T   )	AuthorOpt	FilterOpt	FormatOptLimitOptOutputFormatQuietOptRevisionOpt	SearchOptTokenOptapi_object_to_dict
get_hf_apimake_expand_properties_parserprint_list_outputtyper_factorySpaceSortEnumc                 C   s   i | ]}||qS  r   ).0sr   r   \/sda-disk/www/egybert/egybert_env/lib/python3.10/site-packages/huggingface_hub/cli/spaces.py
<dictcomp>8   s    r   )typezMComma-separated properties to expand. Example: '--expand=likes,tags'. Valid: z, .)helpcallbackz Interact with spaces on the Hub.)r!   lszhf spaces ls --limit 10z4hf spaces ls --search "chatbot" --author huggingface)examples
   FsearchauthorfiltersortzSort results.limitexpandformatquiettokenreturnc	              	   C   sJ   t |d}	|r
|jnd}
dd |	j||| |
||dD }t|||d dS )zList spaces on the Hub.r.   Nc                 S   s   g | ]}t |qS r   )r   )r   
space_infor   r   r   
<listcomp>_   s    zspaces_ls.<locals>.<listcomp>)r(   r'   r&   r)   r*   r+   )r,   r-   )r   valuelist_spacesr   )r&   r'   r(   r)   r*   r+   r,   r-   r.   apisort_keyresultsr   r   r   	spaces_lsG   s   
r8   infoz hf spaces info enzostvs/deepsitez>hf spaces info gradio/theme_builder --expand sdk,runtime,likesspace_idz)The space ID (e.g. `username/repo-name`).revisionc              
   C   s   t |d}z
|j| ||d}W n, ty$ } z	td|  d|d}~w ty; } ztd| d|  d|d}~ww ttjt|d	d
 dS )z"Get info about a space on the Hub.r0   )repo_idr;   r+   zSpace 'z' not found.Nz
Revision 'z' not found on 'z'.   )indent)	r   r1   r   r   r   printjsondumpsr   )r:   r;   r+   r.   r5   r9   er   r   r   spaces_infoh   s   
rC   )NNN)-__doc__enumr@   typingr   r   r   typerhuggingface_hub.errorsr   r   r   huggingface_hub.hf_apir   r	   
_cli_utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   sorted_EXPAND_PROPERTIES_SORT_OPTIONSEnumstrr   Optionjoin	ExpandOpt
spaces_clicommandtabler8   ArgumentrC   r   r   r   r   <module>   s   @
	
	
	