
    qiA                     	   d Z ddlZddlZddlZddlmZ ddlmZmZ ddl	Z	ddl
mZ ddlmZm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mZmZmZmZmZ  G d
 de ejB                        Z" G d de ejB                        Z# G d de ejB                        Z$ddhZ%ee& e	jN                  dd      f   Z(de de fdZ)dee    dee   dee    fdZ*dpdede+ddfdZ, ed      Z-e-j]                  d g d!"      e"j^                  e#j`                  dd#ejb                  ejd                  ddfd$edee" e	jf                  d%d&d'      f   d(ee# e	jf                  d)d*d+      f   d,ed-ed.ed/ed0ed1eddfd2       Z4e-j]                  d3g d4"      dddejb                  e$jj                  dfd$ed5e(d6ee+ e	jf                  d7d8      f   d9ee+ e	jf                  d:d;      f   d<ee+ e	jf                  d=d>      f   d.ed/ee$ e	jf                  d?      f   d1eddfd@       Z6e-j]                  dAg dB"      dddejb                  dfd$edCee  e	jf                  dDdE      f   deee     e	jf                  dFdG      f   deee    e	jf                  dHdI      f   dJee+ e	jf                  dKdLdM      f   d.ed1eddfdN       Z7e-j]                  dOdPdQg"      ddejb                  dfd$ed5e(deee     e	jf                  dFdR      f   deee    e	jf                  dHdS      f   d.ed1eddfdT       Z8e-j]                  dUdVdWg"      ddejb                  dfd$ed5e(dOeee     e	jf                  dXdY      f   dZee+ e	jf                  d[d\d]      f   d.ed1eddfd^       Z9e-j]                  d_d`dag"      ddejb                  dfd$ed5e(dOeee     e	jf                  dXdb      f   dZee+ e	jf                  d[d\d]      f   d.ed1eddfdc       Z:e-j]                  dddeg"      ejb                  dfd$ed5e(dfee  e	jN                  dg      f   d.ed1eddfdh       Z;e-j]                  didjdkg"      ddejb                  dfd$ed5e(dOeee     e	jf                  dXdl      f   dZee+ e	jf                  d[d\d]      f   d.ed1eddfdm       Z<e-j]                  d9dng"      ejb                  dfd$ed5e(d.ed1eddf
do       Z=y)qzYContains commands to interact with discussions and pull requests on the Hugging Face Hub.    N)Path)	AnnotatedOptional)	constants)DiscussionCommentDiscussionWithDetails)ANSI   )	AuthorOpt	FormatOptLimitOptOutputFormatQuietOpt	RepoIdArgRepoTypeRepoTypeOptTokenOpt_format_cellapi_object_to_dict
get_hf_apiprint_list_outputtyper_factoryc                        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        Q/opt/pipecat/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'   6   s    
CJ!Lr$   r'   c                       e Zd ZdZdZdZy)
InfoFormatz#Output format for the info command.textjsonN)r    r!   r"   __doc__r,   r-   r#   r$   r%   r+   r+   <   s    -DDr$   r+   r   r   z&The discussion or pull request number.)helpminstatusreturnc                     | dk(  rt        j                  d      S | dk(  rt        j                  d      S | dk(  rt        j                  d      S | dk(  rt        j                  d      S | S )Nr   r   r   r   )r	   greenredblueyellow)r1   s    r%   _format_statusr8   S   sc    zz&!!	8	xx!!	8	yy""	7	{{7##Mr$   body	body_filec                     | |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)r9   r:   s     r%   
_read_bodyrE   _   s[    I1  !JKKy>S 99>>##""G"44Kr$   Fdetailsshow_commentsc           	      p   | j                   rdnd}t        t        j                  | j                         dt        j
                  d| j                                 t        | j                        | j                  | j                  j                  d      g}| j                   r=| j                  r1|j                  dt        j                  | j                                t        | ddj                  |              | j                   rs| j                  rg| j                  d	u rt        t        j                   d
             n:t        t        j                   ddj                  | j                                      d }g }| j"                  D ]6  }t%        |t&              s|j(                  r!||}&|j                  |       8 |rG|j*                  j-                         r-t                t        |j*                  j-                                |r|rt                t        t        j
                  d             |D ]u  }t                t        t        j                  |j                         d|j                  j                  d              t        |j*                  j-                                w nI|rGt                t        t        j
                  t/        |       dt/        |      dk7  rdnd d             t                t        dt        j0                  | j2                                y )NzPull Request
Discussion #z%Y-%m-%d %H:%Mzinto z: u    · TzHas conflicting fileszConflicting files: z,    ────────────────────────────────────────────────────────────z commentr
   s z (use --comments to show)View on Hub: )is_pull_requestprintr	   boldtitlegraynumr8   r1   author
created_atstrftimetarget_branchappendjoinconflicting_filesr7   events
isinstancer   hiddencontentstriplenr6   url)rF   rG   kindpartsr9   commentseventcomments           r%   _print_discussion_infori   j   se   $44>,D	TYYw}}%&a		Agkk]2C(D'E
FGGNN+W^^W=O=O=X=XYi=jkE7#8#8uTYYw'<'<=>?@	TF"V[['(
)*7#<#<$$,$++567$++ 3DIIg>W>W4X3YZ[\DH 'e./|&' ""$dll  "#dii
#$ 	+GGTYYw~~./tG4F4F4O4OP`4a3bcd'//'')*	+ 
dii3x=/X!9K#QS1TTmnop	G	M$))GKK01
23r$   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_idz-sz--statusz4Filter by status (open, closed, merged, draft, all).rd   z-kz--kindz/Filter by kind (discussion, pull_request, all).rV   limit	repo_typeformatquiet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        |||dg dd dd	i
       yc c}w )z-List discussions and pull requests on a repo.rq   r   r   N)rl   rV   discussion_typediscussion_statusrn   rU   )rU   rS   rP   r1   rV   rW   c                 "   d| d    t        | j                  dd      d      | j                  d      rdndt        t        | j                  d	d                  t        | j                  d
d            t        | j                  dd            gS )NrK   rU   rS   rN   2   )max_lenrP   PRr1   rV   rW   )r   getr8   r@   )items    r%   <lambda>z!discussion_list.<locals>.<lambda>   s{    U}'2.;HH./DR3txx"5672&',34
 r$   right)ro   rp   id_keyheadersrow_fn
alignments)r   r   r   r   r'   r   valueget_repo_discussions_CLIENT_SIDE_STATUSESr1   rZ   rb   r   r   )rl   r1   rd   rV   rm   rn   ro   rp   rq   api
api_statusapi_discussion_typediscussionsditemss                  r%   discussion_listr      s   F 5
!C !&&&
	#**	*

 ~!!!""jjK%%+$// &   <<00QXX5M1{u$ -88q"8E8U
 7# 9s   Dinfo)z'hf discussions info username/my-model 5z2hf discussions info username/my-model 5 --commentsz.hf discussions info username/my-model 5 --diffz5hf discussions info username/my-model 5 --format jsonrU   rf   z
--commentszShow all comments.diffz--diffz"Show the diff (for pull requests).no_colorz
--no-colorzDisable colored output.zOutput format (text or json).c                    ddl }|rd|j                  d<   t        |      }	|	j                  | ||j                        }
|t
        j                  k(  r@t        |
      }|s|j                  dd       t        t        j                  |d	             yt        |
|
       |rK|
j                  r>t                t        t        j                  d             t        |
j                         yyy)z,Get info about a discussion or pull request.r   N1NO_COLORrs   rl   discussion_numrn   r      )indent)rG   rL   )osenvironr   get_discussion_detailsr   r+   r-   r   poprQ   dumpsri   r   r	   rT   )rl   rU   rf   r   r   rn   ro   rq   r   r   rF   results               r%   discussion_infor      s    V !$

:
5
!C((// ) G  #G,JJvt$djj*+7(;dii
#$gll tr$   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"rS   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}
t	        d|
 dt        j                  d|	j                          dt        j                  |               |r.t	        d	t        j                  d
|	j                                 t	        dt        j                  |	j                                y)z2Create a new discussion or pull request on a repo.rs   )rl   rS   descriptionrn   r)   zpull requestr(   zCreated rJ   rK   z on zPush changes to: zrefs/pr/rO   N)
rE   r   create_discussionr   rQ   r	   rR   rU   r6   rc   )rl   rS   r9   r:   r)   rn   rq   r   r   r(   rd   s              r%   discussion_creater   3  s    X T9-K
5
!C&&//! ' J *>|D	HTF!DII*..)9&:;<D7AS@T
UV!$))hz~~6F,G"H!IJK	M$))JNN34
56r$   rh   zIhf 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        d| dt        j                  |               y)z(Comment on a discussion or pull request.Nz)Either --body or --body-file is required.rs   rl   r   rh   rn   zCommented on # in )	rE   r>   r?   r   comment_discussionr   rQ   r	   rR   )rl   rU   r9   r:   rn   rq   rh   r   s           r%   discussion_commentr   o  su    8 y)G  !LMM
5
!C//	   
N3%tDIIg$6#7
89r$   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                 "   |s=t        j                  d| d|  d      }|st        d       t        j                         t	        |      }|j                  | |d||j                         t        d| d	t        j                  |               y
)z#Close a discussion or pull request.zClose # on ''?Aborted.rs   r   rl   r   
new_statusrh   rn   zClosed #r   N	r>   confirmrQ   Exitr   change_discussion_statusr   r	   rR   rl   rU   rh   r   rn   rq   r   r   s           r%   discussion_closer     s    : --'#eG9B ?@***,
5
!C  // !  
HSEdii01
23r$   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                 "   |s=t        j                  d| d|  d      }|st        d       t        j                         t	        |      }|j                  | |d||j                         t        d| d	t        j                  |               y
)z+Reopen a closed discussion or pull request.zReopen #r   r   r   rs   r   r   z
Reopened #r   Nr   r   s           r%   discussion_reopenr     s    : --(3%uWIR @A***,
5
!C  // !  
Jse4		' 23
45r$   renamez9hf discussions rename username/my-model 5 "Updated title"	new_titlezThe new title.c           
          t        |      }|j                  | |||j                         t        d| dt	        j
                  |       dt	        j
                  |               y)z$Rename a discussion or pull request.rs   )rl   r   r   rn   z	Renamed #z to r   N)r   rename_discussionr   rQ   r	   rR   )rl   rU   r   rn   rq   r   s         r%   discussion_renamer     sb    & 5
!C//	   
IcU$tyy34D79K8L
MNr$   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                     |s=t        j                  d| d|  d      }|st        d       t        j                         t	        |      }|j                  | |||j                         t        d| dt        j                  |               y	)
zMerge a pull request.zMerge #r   r   r   rs   r   zMerged #r   N)	r>   r   rQ   r   r   merge_pull_requestr   r	   rR   r   s           r%   discussion_merger     s    : --'#eG9B ?@***,
5
!C//	   
HSEdii01
23r$   z'hf discussions diff username/my-model 5c                     t        |      }|j                  | ||j                        }|j                  rt	        |j                         yt	        d       y)z Show the diff of a pull request.rs   r   zNo diff available.N)r   r   r   r   rQ   )rl   rU   rn   rq   r   rF   s         r%   discussion_diffr   ;  sN     5
!C((// ) G
 ||gll"#r$   )F)>r.   enumr-   rA   pathlibr   typingr   r   r>   huggingface_hubr   huggingface_hub.communityr   r   huggingface_hub.utilsr	   
_cli_utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r@   Enumr   r'   r+   r   intArgumentDiscussionNumArgr8   rE   boolri   discussions_clicommandr   r   modeltableOptionr   r,   r   r   r   r   r   r   r   r   r#   r$   r%   <module>r      s   `   
  &  % N &   $sDII "S$)) "dii  "7+  ENN5 	3 	3 	Xc] x~ (3- (4$9 (4$ (4[_ (4V  %WX   $ 	 	%^^$**/IIG	
	I B	
	I$ %I& 'I( )I* +I, -I. /I0 
1IIX 
  $ 	 	 	%^^ 	?::	: %	
	: 5	
	:" *	
	#:0 1:2 0	
	3:> ?:@ 
A::z   0 	 	 	%^^A0707?	
	07 7	
	07  G	
	!07. A	
	/07> ?07@ A07B 
C0707f SC    	 	%^^%::	: 8	
	: C	
	:" #:$ %:& 
'::D 2S    	 	%^^'#4#4	#4 <	
	#4 
,	
	
#4$ %#4& '#4( 
)#4#4L 3d    	 	%^^'#6#6	#6 >	
	#6 
,	
	
#6$ %#6& '#6( 
)#6#6L C   &^^OO	O !	
	O O O 
OO. 2O    	 	%^^'"4"4	"4 <	
	"4 
,	
	
"4$ %"4& '"4( 
)"4"4J 
1   &^^	$$	$ $ 	$
 
$$r$   