o
    0jn1                     @   st  d Z ddlZddlZddlmZ ddlmZ ddlZddlm	Z	 ddl
mZmZmZmZmZmZmZmZmZ ddlmZ G d	d
 d
eejZG dd deejZddhZeeejdddf ZdedB dedB dedB fddZeddZej dg ddej!ej"ddej#dfdedeeej$ddd df d!eeej$d"d#d$df d%ed&ed'ed(eddfd)d*Z%ej d+d,d-gdej#dfded.ed'ed(eddf
d/d0Z&ej d1g d2dddd3ej#dfded4eeej$d5d6df deedB ej$d7d8df deedB ej$d9d:df d;ee'ej$d<d=d>df d'ed(eddfd?d@Z(ej dAdBdCgdddej#dfded.edeedB ej$d7dDdf deedB ej$d9dEdf d'ed(eddfdFdGZ)ej dHdIdJgddd3ej#dfded.edAeedB ej$dKdLdf dMee'ej$dNdOdPdf d'ed(eddfdQdRZ*ej dSdTdUgddd3ej#dfded.edAeedB ej$dKdVdf dMee'ej$dNdOdPdf d'ed(eddfdWdXZ+ej dYdZgdej#dfded.ed[eeejd\df d'ed(eddfd]d^Z,ej d_d`dagddd3ej#dfded.edAeedB ej$dKdbdf dMee'ej$dNdOdPdf d'ed(eddfdcddZ-ej dedfgdej#dfded.ed'ed(eddf
dgdhZ.dS )izYContains commands to interact with discussions and pull requests on the Hugging Face Hub.    N)Path)	Annotated)	constants   )		AuthorOptLimitOpt	RepoIdArgRepoTypeRepoTypeOptTokenOptapi_object_to_dict
get_hf_apityper_factory)outc                   @   s    e Zd ZdZdZdZdZdZdS )DiscussionStatusopenclosedmergeddraftallN)__name__
__module____qualname__r   r   r   r   r    r   r   `/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/cli/discussions.pyr   '   s    r   c                   @   s   e Zd ZdZdZdZdS )DiscussionKindr   
discussionpull_requestN)r   r   r   r   r   r   r   r   r   r   r   /   s    r   r   r   z&The discussion or pull request number.)helpminbody	body_filereturnc                 C   sH   | dur|durt d|dur"t|dkrtj S |jddS | S )zFResolve body text from --body or --body-file (supports '-' for stdin).Nz'Cannot use both --body and --body-file.-zutf-8)encoding)typerBadParameterstrsysstdinread	read_text)r    r!   r   r   r   
_read_bodyE   s   

r,   z0Manage discussions and pull requests on the Hub.)r   z	list | ls)z%hf discussions list username/my-modelzIhf discussions list username/my-model --kind pull_request --status mergedzFhf discussions list username/my-dataset --type dataset --status closedzBhf discussions list username/my-model --author alice --format json)Zexamples   repo_idstatusz-sz--statusz4Filter by status (open, closed, merged, draft, all).kindz-kz--kindz/Filter by kind (discussion, pull_request, all).authorlimit	repo_typetokenc                 C   s   t |d}|tjkrd}n
|tjkrd}nd}|tjkrd}	n|j}	g }
|j| ||	||jdD ]}|jtv r=|j	|jkr=q/|

| t|
|krJ nq/dd |
D }tj|g dd	d	d
id dS )z-List discussions and pull requests on a repo.r4   r   r   N)r.   r1   Zdiscussion_typeZdiscussion_statusr3   c                 S   s   g | ]}t |qS r   )r   ).0dr   r   r   
<listcomp>   s    z#discussion_list.<locals>.<listcomp>)numtitleZis_pull_requestr/   r1   Z
created_atr9   right)headersZid_keyZ
alignments)r   r   r   r   r   r   valueZget_repo_discussions_CLIENT_SIDE_STATUSESr/   appendlenr   table)r.   r/   r0   r1   r2   r3   r4   apiZ
api_statusZapi_discussion_typeZdiscussionsr7   itemsr   r   r   discussion_listS   s<   
!





rD   infoz'hf discussions info username/my-model 5z5hf discussions info username/my-model 5 --format jsonr9   c                 C   s*   t |d}|j| ||jd}t| dS )z,Get info about a discussion or pull request.r5   r.   discussion_numr3   N)r   get_discussion_detailsr=   r   dictr.   r9   r3   r4   rB   detailsr   r   r   discussion_info   s   
rL   create)z<hf discussions create username/my-model --title "Bug report"zWhf discussions create username/my-model --title "Feature request" --body "Please add X"zIhf discussions create username/my-model --title "Fix typo" --pull-requestzUhf discussions create username/my-dataset --type dataset --title "Data quality issue"Fr:   z--titlez,The title of the discussion or pull request.z--bodyz$The description (supports Markdown).z--body-filez4Read the description from a file. Use '-' for stdin.r   z--pull-requestz--prz.Create a pull request instead of a discussion.c                 C   sx   t ||}t|d}|j| |||j|d}	|rdnd}
|r#d|	j nd}tjd|
 d|	j d	|  |	j|	j|d
 dS )z2Create a new discussion or pull request on a repo.r5   )r.   r:   descriptionr3   r   zpull requestr   zrefs/pr/NzCreated z #z on )r9   urlref)r,   r   Zcreate_discussionr=   r9   r   resultrO   )r.   r:   r    r!   r   r3   r4   rN   rB   r   r0   rP   r   r   r   discussion_create   s   
,
.rR   commentzIhf discussions comment username/my-model 5 --body "Thanks for reporting!"z9hf discussions comment username/my-model 5 --body "LGTM!"z%The comment text (supports Markdown).z0Read the comment from a file. Use '-' for stdin.c                 C   sZ   t ||}|du rtdt|d}|j| |||jd tjd| d|  || d dS )z(Comment on a discussion or pull request.Nz)Either --body or --body-file is required.r5   r.   rG   rS   r3   zCommented on # in r9   repo)r,   r%   r&   r   Zcomment_discussionr=   r   rQ   )r.   r9   r    r!   r3   r4   rS   rB   r   r   r   discussion_comment   s   


 rX   closez(hf discussions close username/my-model 5zIhf discussions close username/my-model 5 --comment "Closing as resolved."z	--commentz)An optional comment to post when closing.yesz--yesz-yzSkip confirmation prompt.c                 C   \   t jd| d|  d|d t|d}|j| |d||jd t jd| d	|  || d
 dS )z#Close a discussion or pull request.zClose # on ''?rZ   r5   r   r.   rG   Z
new_statusrS   r3   zClosed #rU   rV   Nr   confirmr   Zchange_discussion_statusr=   rQ   r.   r9   rS   rZ   r3   r4   rB   r   r   r   discussion_close     
 rc   Zreopenz)hf discussions reopen username/my-model 5zZhf discussions reopen username/my-model 5 --comment "Reopening for further investigation."z+An optional comment to post when reopening.c                 C   r[   )z+Reopen a closed discussion or pull request.zReopen #r\   r]   r^   r5   r   r_   z
Reopened #rU   rV   Nr`   rb   r   r   r   discussion_reopen>  rd   re   renamez9hf discussions rename username/my-model 5 "Updated title"	new_titlezThe new title.c                 C   s@   t |d}|j| |||jd tjd| d|  || |d dS )z$Rename a discussion or pull request.r5   )r.   rG   rg   r3   z	Renamed #rU   )r9   rW   r:   N)r   Zrename_discussionr=   r   rQ   )r.   r9   rg   r3   r4   rB   r   r   r   discussion_renameg  s   
"rh   mergez(hf discussions merge username/my-model 5zEhf discussions merge username/my-model 5 --comment "Merging, thanks!"z)An optional comment to post when merging.c                 C   sZ   t jd| d|  d|d t|d}|j| |||jd t jd| d|  || d	 d
S )zMerge a pull request.zMerge #r\   r]   r^   r5   rT   zMerged #rU   rV   N)r   ra   r   Zmerge_pull_requestr=   rQ   rb   r   r   r   discussion_merge  s   
 rj   diffz'hf discussions diff username/my-model 5c                 C   s@   t |d}|j| ||jd}|jrt|j dS td dS )z Show the diff of a pull request.r5   rF   zNo diff available.N)r   rH   r=   rk   r   textrJ   r   r   r   discussion_diff  s   
rm   )/__doc__enumr(   pathlibr   typingr   r%   Zhuggingface_hubr   Z
_cli_utilsr   r   r   r	   r
   r   r   r   r   _outputr   r'   Enumr   r   r>   intZArgumentZDiscussionNumArgr,   Zdiscussions_clicommandr   r   modelOptionrD   rL   boolrR   rX   rc   re   rh   rj   rm   r   r   r   r   <module>   s  ,
"	

?
	 !1
"
"
"	

!	