
    -:jE1                     @   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  G d	 d
eej.                        Z G d deej.                        ZddhZee ej8                  dd      f   Zdedz  dedz  dedz  fdZ ed      ZejA                  dg d      ejB                  ejD                  ddejF                  dfdedee ejH                  ddd      f   d ee ejH                  d!d"d#      f   d$ed%ed&ed'eddfd(       Z%ejA                  d)d*d+g      ejF                  dfded,ed&ed'eddf
d-       Z&ejA                  d.g d/      ddd0ejF                  dfded1ee ejH                  d2d3      f   deedz   ejH                  d4d5      f   deedz   ejH                  d6d7      f   d8ee' ejH                  d9d:d;      f   d&ed'eddfd<       Z(ejA                  d=d>d?g      ddejF                  dfded,edeedz   ejH                  d4d@      f   deedz   ejH                  d6dA      f   d&ed'eddfdB       Z)ejA                  dCdDdEg      dd0ejF                  dfded,ed=eedz   ejH                  dFdG      f   dHee' ejH                  dIdJdK      f   d&ed'eddfdL       Z*ejA                  dMdNdOg      dd0ejF                  dfded,ed=eedz   ejH                  dFdP      f   dHee' ejH                  dIdJdK      f   d&ed'eddfdQ       Z+ejA                  dRdSg      ejF                  dfded,edTee ej8                  dU      f   d&ed'eddfdV       Z,ejA                  dWdXdYg      dd0ejF                  dfded,ed=eedz   ejH                  dFdZ      f   dHee' ejH                  dIdJdK      f   d&ed'eddfd[       Z-ejA                  d\d]g      ejF                  dfded,ed&ed'eddf
d^       Z.y)_zYContains 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)_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        a/var/www/html/tokenscope/api/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)typerBadParameterstrsysstdinread	read_text)r$   r%   s     r   
_read_bodyr1   D   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)r4   r7   discussion_typediscussion_statusr9   )numtitleis_pull_requestr5   r7   
created_atr?   )headersid_key)r   r   r   r   r   r   valueget_repo_discussions_CLIENT_SIDE_STATUSESr5   appendlenr   r   table)r4   r5   r6   r7   r8   r9   r:   api
api_statusapi_discussion_typediscussionsditemss                r   discussion_listrQ   R   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 jsonr?   c                     t        |      }|j                  | ||j                        }t        j                  |       y)z,Get info about a discussion or pull request.r<   r4   discussion_numr9   N)r   get_discussion_detailsrE   r   dictr4   r?   r9   r:   rK   detailss         r   discussion_inforZ      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"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                 &   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<   )r4   r@   descriptionr9   r!   zpull requestr    zrefs/pr/NzCreated z #z on )r?   urlref)r1   r   create_discussionrE   r?   r   resultr^   )r4   r@   r$   r%   r!   r9   r:   r]   rK   r    r6   r_   s               r   discussion_createrb      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.Nz)Either --body or --body-file is required.r<   r4   rU   rc   r9   zCommented on # in r?   repo)r1   r*   r+   r   comment_discussionrE   r   ra   )r4   r?   r$   r%   r9   r:   rc   rK   s           r   discussion_commentrj      ss    8 y)G  !LMM
5
!C//	   JJuD	2'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        |      }|j                  | |d||j                         t        j
                  d| d	|  || 
       y)z#Close a discussion or pull request.zClose # on ''?rl   r<   r   r4   rU   
new_statusrc   r9   zClosed #rf   rg   Nr   confirmr   change_discussion_statusrE   ra   r4   r?   rc   rl   r9   r:   rK   s          r   discussion_closerw     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 #rn   ro   rp   r<   r   rq   z
Reopened #rf   rg   Nrs   rv   s          r   discussion_reopenrz   <  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<   )r4   rU   r|   r9   z	Renamed #rf   )r?   rh   r@   N)r   rename_discussionrE   r   ra   )r4   r?   r|   r9   r:   rK   s         r   discussion_renamer   e  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 #rn   ro   rp   r<   re   zMerged #rf   rg   N)r   rt   r   merge_pull_requestrE   ra   rv   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<   rT   zNo diff available.N)r   rV   rE   r   r   textrX   s         r   discussion_diffr     sV     5
!C((// ) G
 ||%&r   )/__doc__enumr-   pathlibr   typingr   r*   huggingface_hubr   
_cli_utilsr   r   r	   r
   r   r   r   r   _outputr   r   r,   Enumr   r   rG   intArgumentDiscussionNumArgr1   discussions_clicommandr   r   modelOptionrQ   rZ   boolrb   rj   rw   rz   r   r   r   r   r   r   <module>r      s   `  
    %	 	 	 -sDII "S$)) " "7+  ENN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 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   