o
    Zi                     @   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g d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 datasets on the Hugging Face Hub.

Usage:
    # list datasets on the Hub
    hf datasets ls

    # list datasets with a search query
    hf datasets ls --search "code"

    # get info about a dataset
    hf datasets info HuggingFaceFW/fineweb
    N)	AnnotatedOptionalget_args)CLIErrorRepositoryNotFoundErrorRevisionNotFoundError)DatasetSort_TExpandDatasetProperty_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DatasetSortEnumc                 C   s   i | ]}||qS  r   ).0sr   r   S/home/app/Keep/.python/lib/python3.10/site-packages/huggingface_hub/cli/datasets.py
<dictcomp>8   s    r   )typezWComma-separated properties to expand. Example: '--expand=downloads,likes,tags'. Valid: z, .)helpcallbackz"Interact with datasets on the Hub.)r!   Zls)zhf datasets lsz*hf datasets ls --sort downloads --limit 10zhf datasets ls --search "code")Z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 datasets on the Hub.r,   Nc                 S   s   g | ]}t |qS r   )r   )r   dataset_infor   r   r   
<listcomp>`   s    zdatasets_ls.<locals>.<listcomp>)r&   r%   r$   r'   r(   r)   )r*   r+   )r   valueZlist_datasetsr   )r$   r%   r&   r'   r(   r)   r*   r+   r,   apisort_keyresultsr   r   r   datasets_lsG   s   
r5   infoz&hf datasets info HuggingFaceFW/finewebz9hf datasets info my-dataset --expand downloads,likes,tags
dataset_idz+The dataset 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 dataset on the Hub.r.   )Zrepo_idr8   r)   z	Dataset 'z' not found.Nz
Revision 'z' not found on 'z'.   )indent)	r   r/   r   r   r   printjsondumpsr   )r7   r8   r)   r,   r2   r6   er   r   r   datasets_infoi   s   
r?   )NNN)-__doc__enumr<   typingr   r   r   ZtyperZhuggingface_hub.errorsr   r   r   Zhuggingface_hub.hf_apir   r	   Z
_cli_utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   sortedZ_EXPAND_PROPERTIESZ_SORT_OPTIONSEnumstrr   OptionjoinZ	ExpandOptZdatasets_clicommandtabler5   ZArgumentr?   r   r   r   r   <module>   s   @
		
	
	