
    i3                     2	   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mZ ddlmZmZ  G d	 d
eej2                        Z G d deej2                        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!jE                  dg d      ejF                  ejH                  ddejJ                  ejL                  dfdedee ejN                  ddd      f   d ee ejN                  d!d"d#      f   d$ed%ed&ed'ed(eddfd)       Z(e!jE                  d*d+d,g      ejJ                  ejL                  dfded-ed&ed'ed(eddfd.       Z)e!jE                  d/g d0      ddd1ejJ                  ejL                  dfded2ee ejN                  d3d4      f   deedz   ejN                  d5d6      f   deedz   ejN                  d7d8      f   d9ee* ejN                  d:d;d<      f   d&ed'ed(eddfd=       Z+e!jE                  d>d?d@g      ddejJ                  ejL                  dfded-edeedz   ejN                  d5dA      f   deedz   ejN                  d7dB      f   d&ed'ed(eddfdC       Z,e!jE                  dDdEdFg      dd1ejJ                  ejL                  dfded-ed>eedz   ejN                  dGdH      f   dIee* ejN                  dJdKdL      f   d&ed'ed(eddfdM       Z-e!jE                  dNdOdPg      dd1ejJ                  ejL                  dfded-ed>eedz   ejN                  dGdQ      f   dIee* ejN                  dJdKdL      f   d&ed'ed(eddfdR       Z.e!jE                  dSdTg      ejJ                  ejL                  dfded-edUee ej<                  dV      f   d&ed'ed(eddfdW       Z/e!jE                  dXdYdZg      dd1ejJ                  ejL                  dfded-ed>eedz   ejN                  dGd[      f   dIee* ejN                  dJdKdL      f   d&ed'ed(eddfd\       Z0e!jE                  d]d^g      ejJ                  ejL                  dfded-ed&ed'ed(eddfd_       Z1y)`zYContains commands to interact with discussions and pull requests on the Hugging Face Hub.    N)Path)	Annotated)	constants   )
	AuthorOptFormatWithAutoOptLimitOpt	RepoIdArgRepoTypeRepoTypeOptTokenOptapi_object_to_dict
get_hf_apityper_factory)OutputFormatWithAuto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        p/var/www/vps2.regionflexible.com/Desarrollo/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!   0   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_bodyr3   F   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format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ddi	       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_atrB   right)headersid_key
alignments)r   r   r   r   r!   r   valueget_repo_discussions_CLIENT_SIDE_STATUSESr7   appendlenr   r   table)r6   r7   r8   r9   r:   r;   r<   r=   api
api_statusapi_discussion_typediscussionsditemss                 r   discussion_listrV   T   s   D 5
!C !&&&
	#**	*

 ~!!!""jjK%%+$// &   <<00QXX5M1{u$ -88q"8E8IIU7#	 9s   Dinfoz'hf discussions info username/my-model 5z5hf discussions info username/my-model 5 --format jsonrB   c                     t        |      }|j                  | ||j                        }t        j                  |       y)z,Get info about a discussion or pull request.r?   r6   discussion_numr;   N)r   get_discussion_detailsrJ   r   dictr6   rB   r;   r<   r=   rP   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"FrC   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   rC   descriptionr;   r#   zpull requestr"   zrefs/pr/NzCreated z #z on )rB   urlref)r3   r   create_discussionrJ   rB   r   resultrc   )r6   rC   r&   r'   r#   r;   r<   r=   rb   rP   r"   r8   rd   s                r   discussion_createrg      s    Z 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?   r6   rZ   rh   r;   zCommented on # in rB   repo)r3   r,   r-   r   comment_discussionrJ   r   rf   )	r6   rB   r&   r'   r;   r<   r=   rh   rP   s	            r   discussion_commentro      ss    : 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 ''?rq   r?   r   r6   rZ   
new_statusrh   r;   zClosed #rk   rl   Nr   confirmr   change_discussion_statusrJ   rf   r6   rB   rh   rq   r;   r<   r=   rP   s           r   discussion_closer|     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 #rs   rt   ru   r?   r   rv   z
Reopened #rk   rl   Nrx   r{   s           r   discussion_reopenr   D  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   rZ   r   r;   z	Renamed #rk   )rB   rm   rC   N)r   rename_discussionrJ   r   rf   )r6   rB   r   r;   r<   r=   rP   s          r   discussion_renamer   n  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 #rs   rt   ru   r?   rj   zMerged #rk   rl   N)r   ry   r   merge_pull_requestrJ   rf   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?   rY   zNo diff available.N)r   r[   rJ   r   r   textr]   s          r   discussion_diffr     sV     5
!C((// ) G
 ||%&r   )2__doc__enumr/   pathlibr   typingr   r,   huggingface_hubr   
_cli_utilsr   r   r	   r
   r   r   r   r   r   r   _outputr   r   r.   Enumr   r!   rL   intArgumentDiscussionNumArgr3   discussions_clicommandr   r   modelautoOptionrV   r_   boolrg   ro   r|   r   r   r   r   r   r   r   <module>r      sc   `  
    %   /sDII "S$)) " "7+  ENN5 S4Z D4K C$J   %WX   $ 	 	%^^ 4 9 9-==G	
	= B	
	=$ %=& '=( )=* +=, -=. 
/==@ 
1?   &^^ 4 9 9	  	
  
"   0 	 	 	%^^ 4 9 9C/r/r?	
	/r d
7	
	/r  tG	
	!/r. A	
	//r> ?/r@ A/rB C/rD 
E/r/rd SC    	 	%^^ 4 9 9' K K	 K d
8	
	 K tC	
	 K" # K$ % K& ' K( 
) K KF 2S    	 	%^^ 4 9 9) E E	 E d
<	
	 E 
,	
	
 E$ % E& ' E( ) E* 
+ E EF 3d    	 	%^^ 4 9 9) G G	 G d
>	
	 G 
,	
	
 G$ % G& ' G( ) G* 
+ G GF C   &^^ 4 9 9WW	W !	
	W W W W 
WW0 2O    	 	%^^ 4 9 9)EE	E d
<	
	E 
,	
	
E$ %E& 'E( )E* 
+EED 
1   &^^ 4 9 9''	' ' 	'
 ' 
''r   