
    jn1                     p   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
eej                  Z G d deej                  ZddhZee ej        dd          f         Zdedz  dedz  dedz  fdZ ed          Ze                     dg d          ej!        ej"        ddej#        dfdedee ej$        ddd          f         d ee ej$        d!d"d#          f         d$ed%ed&ed'eddfd(            Z%e                     d)d*d+g          ej#        dfded,ed&ed'eddf
d-            Z&e                     d.g d/          ddd0ej#        dfded1ee ej$        d2d3          f         deedz   ej$        d4d5          f         deedz   ej$        d6d7          f         d8ee' ej$        d9d:d;          f         d&ed'eddfd<            Z(e                     d=d>d?g          ddej#        dfded,edeedz   ej$        d4d@          f         deedz   ej$        d6dA          f         d&ed'eddfdB            Z)e                     dCdDdEg          dd0ej#        dfded,ed=eedz   ej$        dFdG          f         dHee' ej$        dIdJdK          f         d&ed'eddfdL            Z*e                     dMdNdOg          dd0ej#        dfded,ed=eedz   ej$        dFdP          f         dHee' ej$        dIdJdK          f         d&ed'eddfdQ            Z+e                     dRdSg          ej#        dfded,edTee ej        dU          f         d&ed'eddfdV            Z,e                     dWdXdYg          dd0ej#        dfded,ed=eedz   ej$        dFdZ          f         dHee' ej$        dIdJdK          f         d&ed'eddfd[            Z-e                     d\d]g          ej#        dfded,ed&ed'eddf
d^            Z.dS )_zYContains 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                   "    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        b/var/www/html/Carbon-Document/venv/lib/python3.11/site-packages/huggingface_hub/cli/discussions.pyr   r   '   s'        DFFE
CCCr   r   c                       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        
CJ!LLLr   r   r   r   z&The discussion or pull request number.)helpminbody	body_filereturnc                     | |t          j        d          |Gt          |          dk    rt          j                                        S |                    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%   s     r   
_read_bodyr1   E   sd    I1 !JKKKy>>S  9>>###""G"4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                  D ]K}|j        t          v r|j	        |j        k    r!|

                    |           t          |
          |k    r nLd |
D             }t          j        |g dddd	i
           dS )z-List discussions and pull requests on a repo.r:   r   r   N)r4   r7   discussion_typediscussion_statusr9   c                 ,    g | ]}t          |          S r   )r   ).0ds     r   
<listcomp>z#discussion_list.<locals>.<listcomp>   s!    888q""888r   )numtitleis_pull_requestr5   r7   
created_atrC   right)headersid_key
alignments)r   r   r   r   r   r   valueget_repo_discussions_CLIENT_SIDE_STATUSESr5   appendlenr   table)r4   r5   r6   r7   r8   r9   r:   api
api_statusapi_discussion_typediscussionsrA   itemss                r   discussion_listrV   S   sD   B 5
!
!
!C !&&&

	#*	*	*


 ~!!!""jK%%+$/ &     <000QX5M5M1{u$$E % 98K888EIUUU7#	     r   infoz'hf discussions info username/my-model 5z5hf discussions info username/my-model 5 --format jsonrC   c                     t          |          }|                    | ||j                  }t          j        |           dS )z,Get info about a discussion or pull request.r<   r4   discussion_numr9   N)r   get_discussion_detailsrK   r   dictr4   rC   r9   r:   rQ   detailss         r   discussion_infor_      sQ     5
!
!
!C((/ )  G
 HW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"FrD   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        |          }	|rdnd}
|r
d|	j         nd}t          j        d|
 d|	j         d	|  |	j        |	j        |
           dS )z2Create a new discussion or pull request on a repo.r<   )r4   rD   descriptionr9   r!   zpull requestr    zrefs/pr/NzCreated z #z on )rC   urlref)r1   r   create_discussionrK   rC   r   resultrc   )r4   rD   r$   r%   r!   r9   r:   rb   rQ   r    r6   rd   s               r   discussion_createrg      s    X T9--K
5
!
!
!C&&/! '  J *;>>|D)5
?
%Z^
%
%
%4CJ?$??*.??g??Z^YcYgmpqqqqq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                   t          j        d| d|  ||            dS )z(Comment on a discussion or pull request.Nz)Either --body or --body-file is required.r<   r4   rZ   rh   r9   zCommented on # in rC   repo)r1   r*   r+   r   comment_discussionrK   r   rf   )r4   rC   r$   r%   r9   r:   rh   rQ   s           r   discussion_commentro      s    8 y))G !LMMM
5
!
!
!C/	     J22222'JJJJJJr   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          |          }|                    | |d||j                   t          j        d| d	|  || 
           dS )z#Close a discussion or pull request.zClose # on ''?rq   r<   r   r4   rZ   
new_statusrh   r9   zClosed #rk   rl   Nr   confirmr   change_discussion_statusrK   rf   r4   rC   rh   rq   r9   r:   rQ   s          r   discussion_closer|     s    : K/#//G///S9999
5
!
!
!C  / !    J,#,,7,,#GDDDDD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          |          }|                    | |d||j                   t          j        d| d	|  || 
           dS )z+Reopen a closed discussion or pull request.zReopen #rs   rt   ru   r<   r   rv   z
Reopened #rk   rl   Nrx   r{   s          r   discussion_reopenr   >  s    : K0300W000c::::
5
!
!
!C  / !    J.C..W..CgFFFFFFr   renamez9hf discussions rename username/my-model 5 "Updated title"	new_titlezThe new title.c                     t          |          }|                    | |||j                   t          j        d| d|  || |           dS )z$Rename a discussion or pull request.r<   )r4   rZ   r   r9   z	Renamed #rk   )rC   rm   rD   N)r   rename_discussionrK   r   rf   )r4   rC   r   r9   r:   rQ   s         r   discussion_renamer   g  sq    & 5
!
!
!C/	     J-3--G--3WIVVVVV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                   t          j        d| d|  || 	           d
S )zMerge a pull request.zMerge #rs   rt   ru   r<   rj   zMerged #rk   rl   N)r   ry   r   merge_pull_requestrK   rf   r{   s          r   discussion_merger     s    : K/#//G///S9999
5
!
!
!C/	     J,#,,7,,#GDDDDDDr   diffz'hf discussions diff username/my-model 5c                     t          |          }|                    | ||j                  }|j        rt	          j        |j                   dS t	          j        d           dS )z Show the diff of a pull request.r<   rY   zNo diff available.N)r   r[   rK   r   r   textr]   s         r   discussion_diffr     st     5
!
!
!C((/ )  G
 | '%&&&&&r   )/__doc__enumr-   pathlibr   typingr   r*   huggingface_hubr   
_cli_utilsr   r   r	   r
   r   r   r   r   r   _outputr   r,   Enumr   r   rM   intArgumentDiscussionNumArgr1   discussions_clicommandr   r   modelOptionrV   r_   boolrg   ro   r|   r   r   r   r   r   r   r   <module>r      s(
   ` _  



              % % % % % %
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
          sDI   " " " " "S$) " " " "7+  EN5   S4Z D4K C$J      -%WXXX      $ 	 	%^+< <<G	
 	
 	
	< B	
 	
 	
	<$ %<& '<( )<* +<, 
-< < < <~ 
1?    &^	 	  	
 
          0 	 	 	%^A.r .r.r?	
 	
 	
	.r d
7	
 	
 	
	.r  tG	
 	
 	
	!.r. A	
 	
 	
	/.r> ?.r@ A.rB 
C.r .r .r .rb SC     	 	%^%K KK	K d
8	
 	
 	
	K tC	
 	
 	
	K" #K$ %K& 
'K K K KD 2S     	 	%^'E EE	E d
<	
 	
 	
	E 
,	
 	
 	
	
E$ %E& 'E( 
)E E E ED 3d     	 	%^'G GG	G d
>	
 	
 	
	G 
,	
 	
 	
	
G$ %G& 'G( 
)G G G GD C    &^W WW	W !	
 	
 	
	W W W 
W W W W. 2O     	 	%^'E EE	E d
<	
 	
 	
	E 
,	
 	
 	
	
E$ %E& 'E( 
)E E E EB 
1    &^	' ''	' ' 	'
 
' ' ' ' ' 'r   