
    \j6                        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 ddlmZmZ dd	lmZmZ  G d
 deej4                        Z G d deej4                        ZddhZee edd      f   Zdedz  dedz  dedz  fdZ  ed      Z!e!jE                  dg d      ejF                  ejH                  ddejJ                  dfdedee eddd       f   d!ee ed"d#d$      f   d%ed&ed'ed(eddfd)       Z&e!jE                  d*d+d,g      ejJ                  dfded-ed'ed(eddf
d.       Z'e!jE                  d/g d0      ddd1ejJ                  dfded2ee ed3d4      f   deedz   ed5d6      f   deedz   ed7d8      f   d9ee( ed:d;d<      f   d'ed(eddfd=       Z)e!jE                  d>d?d@g      ddejJ                  dfded-edeedz   ed5dA      f   deedz   ed7dB      f   d'ed(eddfdC       Z*e!jE                  dDdEdFg      ddejJ                  dfded-edGee edH      f   deedz   ed5dI      f   deedz   ed7dJ      f   d'ed(eddfdK       Z+e!jE                  dLdMdNg      dd1ejJ                  dfded-ed>eedz   edOdP      f   dQee( edRdSdT      f   d'ed(eddfdU       Z,e!jE                  dVdWdXg      dd1ejJ                  dfded-ed>eedz   edOdY      f   dQee( edRdSdT      f   d'ed(eddfdZ       Z-e!jE                  d[d\g      ejJ                  dfded-ed]ee ed^      f   d'ed(eddfd_       Z.e!jE                  d`dadbg      dd1ejJ                  dfded-ed>eedz   edOdc      f   dQee( edRdSdT      f   d'ed(eddfdd       Z/e!jE                  dedfg      ejJ                  dfded-ed'ed(eddf
dg       Z0y)hzYContains commands to interact with discussions and pull requests on the Hugging Face Hub.    N)Path)	Annotated)	constants   )	AuthorOptLimitOpt	RepoIdArgRepoTypeRepoTypeOptTokenOpt
get_hf_apityper_factory)ArgumentOption)_dataclass_to_dictoutc                        e Zd ZdZdZdZdZdZy)DiscussionStatusopenclosedmergeddraftallN)__name__
__module____qualname__r   r   r   r   r        R/root/.hermes/venv/lib/python3.12/site-packages/huggingface_hub/cli/discussions.pyr   r   '   s    DFFE
Cr   r   c                       e Zd ZdZdZdZy)DiscussionKindr   
discussionpull_requestN)r   r   r   r   r"   r#   r   r   r   r!   r!   /   s    
CJ!Lr   r!   r   r   z&The discussion or pull request number.)helpminbody	body_filereturnc                     | |t        j                  d      |>t        |      dk(  rt        j                  j                         S |j                  d      S | S )zFResolve body text from --body or --body-file (supports '-' for stdin).z'Cannot use both --body and --body-file.-zutf-8)encoding)clickBadParameterstrsysstdinread	read_text)r&   r'   s     r   
_read_bodyr3   E   s[    I1  !JKKy>S 99>>##""G"44Kr   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)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                    t        |      }|t        j                  k(  rd}n|t        j                  k(  rd}nd}|t        j
                  k(  rd}	n|j                  }	g }
|j                  | ||	||j                        D ]O  }|j                  t        v r|j                  |j                  k7  r/|
j                  |       t        |
      |k\  sO n |
D cg c]  }t        |       }}t        j                  |g dd       yc c}w )	z-List discussions and pull requests on a repo.r<   r   r   N)r6   r9   discussion_typediscussion_statusr;   )numtitleis_pull_requestr7   r9   
created_atrA   )headersid_key)r   r   r   r   r!   r   valueget_repo_discussions_CLIENT_SIDE_STATUSESr7   appendlenr   r   table)r6   r7   r8   r9   r:   r;   r<   api
api_statusapi_discussion_typediscussionsditemss                r   discussion_listrS   S   s	   B 5
!C !&&&
	#**	*

 ~!!!""jjK%%+$// &   <<00QXX5M1{u$ -88q"8E8IIU 9s   Dinfoz'hf discussions info username/my-model 5z5hf discussions info username/my-model 5 --format jsonrA   c                     t        |      }|j                  | ||j                        }t        j                  |       y)z,Get info about a discussion or pull request.r>   r6   discussion_numr;   N)r   get_discussion_detailsrG   r   dictr6   rA   r;   r<   rM   detailss         r   discussion_infor\      s>     5
!C((// ) G
 HHWr   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"FrB   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                 &   t        ||      }t        |      }|j                  | |||j                  |      }	|rdnd}
|rd|	j                   nd}t        j                  d|
 d|	j                   d	|  |	j                  |	j                  |
       y)z2Create a new discussion or pull request on a repo.r>   )r6   rB   descriptionr;   r#   zpull requestr"   zrefs/pr/NzCreated z #z on )rA   urlref)r3   r   create_discussionrG   rA   r   resultr`   )r6   rB   r&   r'   r#   r;   r<   r_   rM   r"   r8   ra   s               r   discussion_createrd      s    X T9-K
5
!C&&//! ' J *>|D)5HZ^^$
%4CJJ$r*..!1gY?Z^^YcYgYgmpqr   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                     t        ||      }|t        j                  d      t        |      }|j	                  | |||j
                         t        j                  d| d|  ||        y)z(Comment on a discussion or pull request.N)Either --body or --body-file is required.r>   r6   rW   re   r;   zCommented on # in rA   repo)r3   r,   r-   r   comment_discussionrG   r   rc   )r6   rA   r&   r'   r;   r<   re   rM   s           r   discussion_commentrm      ss    8 y)G  !LMM
5
!C//	   JJuD	2'Jr   editzHhf discussions edit username/my-model 5 abc123 --body "Updated comment."zChf discussions edit username/my-model 5 abc123 --body-file fixed.md
comment_idzLThe ID of the comment to edit (see 'hf discussions info ... --format json').z)The new comment text (supports Markdown).z4Read the new comment from a file. Use '-' for stdin.c                     t        ||      }|t        j                  d      t        |      }|j	                  | ||||j
                         t        j                  d| d| d|  || |       y)	z9Edit an existing comment on a discussion or pull request.Nrg   r>   )r6   rW   ro   new_contentr;   zEdited comment z on #ri   )rA   rk   ro   )r3   r,   r-   r   edit_discussion_commentrG   r   rc   )	r6   rA   ro   r&   r'   r;   r<   rq   rM   s	            r   discussion_editrs     s    D T9-K  !LMM
5
!C//    JJE#d7)D#T[hrsr   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                     t        j                  d| d|  d|       t        |      }|j                  | |d||j                         t        j
                  d| d	|  || 
       y)z#Close a discussion or pull request.zClose # on ''?ru   r>   r   r6   rW   
new_statusre   r;   zClosed #ri   rj   Nr   confirmr   change_discussion_statusrG   rc   r6   rA   re   ru   r;   r<   rM   s          r   discussion_closer   D  sp    : KK'#eG9B/S9
5
!C  // !  JJ#d7),#GDr   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                     t        j                  d| d|  d|       t        |      }|j                  | |d||j                         t        j
                  d| d	|  || 
       y)z+Reopen a closed discussion or pull request.zReopen #rw   rx   ry   r>   r   rz   z
Reopened #ri   rj   Nr|   r   s          r   discussion_reopenr   m  sp    : KK(3%uWIR0c:
5
!C  // !  JJC5WI.CgFr   renamez9hf discussions rename username/my-model 5 "Updated title"	new_titlezThe new title.c                     t        |      }|j                  | |||j                         t        j                  d| d|  || |       y)z$Rename a discussion or pull request.r>   )r6   rW   r   r;   z	Renamed #ri   )rA   rk   rB   N)r   rename_discussionrG   r   rc   )r6   rA   r   r;   r<   rM   s         r   discussion_renamer     sR    & 5
!C//	   JJ3%tG9-3WIVr   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                     t        j                  d| d|  d|       t        |      }|j                  | |||j                         t        j
                  d| d|  || 	       y
)zMerge a pull request.zMerge #rw   rx   ry   r>   rh   zMerged #ri   rj   N)r   r}   r   merge_pull_requestrG   rc   r   s          r   discussion_merger     sm    : KK'#eG9B/S9
5
!C//	   JJ#d7),#GDr   diffz'hf discussions diff username/my-model 5c                     t        |      }|j                  | ||j                        }|j                  r t	        j
                  |j                         yt	        j
                  d       y)z Show the diff of a pull request.r>   rV   zNo diff available.N)r   rX   rG   r   r   textrZ   s         r   discussion_diffr     sV     5
!C((// ) G
 ||%&r   )1__doc__enumr/   pathlibr   typingr   r,   huggingface_hubr   
_cli_utilsr   r   r	   r
   r   r   r   r   
_frameworkr   r   _outputr   r   r.   Enumr   r!   rI   intDiscussionNumArgr3   discussions_clicommandr   r   modelrS   r\   boolrd   rm   rs   r   r   r   r   r   r   r   r   <module>r      sF   `  
    %	 	 	 ) ,sDII "S$)) " "7+  5 S4Z D4K C$J   %WX   $ 	 	%^^+;;G	
	; B	
	;$ %;& ';( );* +;, 
-;;| 
1?   &^^		  	
 
    0 	 	 	%^^A.r.r?	
	.r d
7	
	.r  tG	
	!.r. A	
	/.r> ?.r@ A.rB 
C.r.rb SC    	 	%^^%KK	K d
8	
	K tC	
	K" #K$ %K& 
'KKD 
RM  , 	 	%^^1&t&t	&t _	
	&t d
<	
	&t  tG	
	!&t. /&t0 1&t2 
3&t&tR 2S    	 	%^^'EE	E d
<	
	E 
,	
	
E$ %E& 'E( 
)EED 3d    	 	%^^'GG	G d
>	
	G 
,	
	
G$ %G& 'G( 
)GGD C   &^^WW	W !	
	W W W 
WW. 2O    	 	%^^'EE	E d
<	
	E 
,	
	
E$ %E& 'E( 
)EEB 
1   &^^	''	' ' 	'
 
''r   