
    Pi-                    :   d dl mZ d dl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 d dlmZ d dlm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 d dlmZ g dZdZ d Z!d:dZ"d;dZ#d<dZ$ ed          dz  dd d dd ed          dd!d!dfd=d8Z%d>d9Z&dS )?    )annotationsN)Path)	Annotated)HfApi)Version)print)Console)Panel)ConfirmPrompt)parse)ArgumentOption)custom_component_analytics)redyellowgreenblueindigopurplepinkgrayz"https://pypi.org/account/register/c                    g }|D ]E}d|v s*|                     d          s|                     d          r|                    |           F|S )N__pycache__distnode_modules)
startswithappend)_srcnamesignoredns       z/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/gradio/cli/commands/components/publish.py_ignorer$      s[    G  Af!5!5n9U9UNN1N    	dist_filer   return
str | Nonec                h    t          j        d| j                  }|r|                    d          S d S )Nz-(\d+\.\d+\.\d+[a-zA-Z]*\d*)-   )researchnamegroup)r&   matchs     r#   _get_version_from_filer0   "   s3    I6	GGE {{1~~4r%   version_stringstr/semantic_version.Version | PEP440Version | Nonec                    	 t          j        |           S # t          $ r% 	 t          |           cY S # t          $ r Y Y dS w xY ww xY w)zCParse a version string, trying semantic_version first, then PEP440.N)semantic_versionr   
ValueErrorPEP440Version	Exception)r1   s    r#   _parse_versionr9   )   sp    '777   	 00000 	 	 	444	s(    
A2A
AA AAdistribution_files
list[Path]c                    g }| D ]=}t          |          }|r*t          |          }|r|                    |           : d S >|rt          t	          |                    nd S )N)r0   r9   r   r2   max)r:   versionspversionparseds        r#   _get_max_versionrB   6   s    H 	 	(++  	#G,,F ''''tt	 "*33s8}}t3r%   .r   T Fdist_dir_Annotated[Path, Argument(help=f"Path to the wheel directory. Default is {Path('.') / 'dist'}")]upload_pypi:Annotated[bool, Option(help='Whether to upload to PyPI.')]pypi_username5Annotated[str, Option(help='The username for PyPI.')]pypi_password5Annotated[str, Option(help='The password for PyPI.')]upload_demoFAnnotated[bool, Option(help='Whether to upload demo to HuggingFace.')]demo_dirBAnnotated[Path | None, Option(help='Path to the demo directory.')]
source_dirUAnnotated[Path, Option(help='Path to the source directory of the custom component.')]tokenAnnotated[str | None, Option(help='HuggingFace token for uploading demo. Can be omitted if already logged in via huggingface cli.')]prefer_localvAnnotated[bool, Option(help='Install the package from the local wheel in the demo space, even if it exists on PyPi.')]upload_sourcewAnnotated[bool, Option(help='Whether to upload the source code of the custom component, to share with the community.')]repo_idAnnotated[str | None, Option(help='The repository id to upload the demo to. If not provided, a space will be created with the same name as the package in the HuggingFace account corresponding to the token.')]c           	         t          dd |||	           t                      }|                                 } |                                 st	          |  d          |                                 st	          |  d          d t          |                               d          D             }dAd	}t          d
 |D             |          }|st	          d          d }|r|r|st          dt           d          }t          |           t          j        d          }|r[t          j                    dz                                  r3t          d           t          t          j                    dz            }n;|r9t          d           t!          j        d          }t!          j        dd          }|r 	 ddlm} ddlm} ddlm} n)# t.          t0          f$ r}t	          d          |d }~ww xY w|r|r |||          }n|r ||          }nt	          d          	 t3          |            fd|D             }t          d d!                    |                      	  |||           n# |$ r}t	          d"          |d }~ww xY wn$# t6          $ r |                                 Y nw xY w|r|st          d#          }t          |           t          j        d$          }|rt          d%          }t          |           t!          j        d&t          d'          d(z             }|pt          t          d'          d(z            }t          |                                          }|rp|	snt          d)          }t          |           t          j        d*          }	|	r:t!          j        d+|           p|}t          |                                          }|r~|d,z  }	 t;          |                                          }|d-         d.         }n5# t6          $ r( |j                             d/          d d0         \  }}Y nw xY w|st	          d1          |j                             d/          d d0         \  }}tC          j"                    5 }tG          j$        t          |          t          |          d2           tG          j%        t          |d3z            t          t          |          d3z                       |	rGtG          j$        t          |          t          t          |          d4z            dtL          5           tG          j%        t          |d6z            t          t          |          d6z                       tO          |7          }|(                    |
p|d8dd9:          }|j)        }
|*                    |
|d8;           |r+|+                    |
t          |          |j        d8<           t          d=           |,                    |
d|>           t          d?|
 d@           d d d            d S # 1 swxY w Y   d S d S )BNpublish)rM   rG   rW   zQ does not exist. Run `gradio cc build` to create a wheel and source distribution.z is not a directoryc                H    g | ]}|j         d v |                                 S )>   .gz.whl)suffixresolve.0r?   s     r#   
<listcomp>z_publish.<locals>.<listcomp>~   s3       _9T9T		9T9T9Tr%   *pathr   c                    t          | j                                      d          d         }t          |          }|t	          d| d| j                   |S )N-r*   zCould not parse version z from )r2   r-   splitr9   r6   )rf   version_strrA   s      r#   _get_wheel_versionz$_publish.<locals>._get_wheel_version   sZ    $)nn**3//2,,>VVV49VVWWWr%   c              3  0   K   | ]}|j         d k    |V  dS )r_   N)r`   rb   s     r#   	<genexpr>z_publish.<locals>.<genexpr>   s.      ==q!(f*<*<*<*<*<*<==r%   )keyzgA wheel file was not found in the distribution directory. Run `gradio cc build` to create a wheel file.zIt is recommended to upload your component to pypi so that [bold][magenta]anyone[/][/] can install it with [bold][magenta]pip install[/][/].

A PyPi account is needed. If you do not have an account, register account here: [blue]z[/]z:snake: Upload to pypi?z.pypircz<:closed_lock_with_key: Found .pypirc file in home directory.zx:light_bulb: If you have Two Factor Authentication enabled, the username is __token__ and your password is your API key.z*:laptop_computer: Enter your pypi usernamez/:closed_lock_with_key: Enter your pypi passwordT)passwordr   )upload)InvalidDistribution)Settingsz^The twine library must be installed to publish to pypi.Install it with pip, pip install twine.)usernamero   )config_filezBNo pypi username or password provided and no ~/.pypirc file found.c                D    g | ]}r	|j         v t          |          S  )r-   r2   )rc   r?   max_versions     r#   rd   z_publish.<locals>.<listcomp>   s@       # (3af'<'< A'<'<'<r%   zUploading files: ,zqInvalid distribution when uploading to pypi. Try upgrading 'pkginfo' with python -m pip install pkginfo --upgradezIt is recommended you upload a demo of your component to [blue]https://huggingface.co/spaces[/] so that anyone can try it from their browser.z:hugging_face: Upload demo?aX  Please provide the path to the [magenta]demo directory[/] for your custom component.

This directory should contain [magenta]all the files[/] it needs to run successfully.

Please make sure the gradio app is in an [magenta]space.py[/] file.

If you need additional python requirements, add a [magenta]requirements.txt[/] file to this directory.zR:roller_coaster: Please enter the path to the demo directory. Leave blank to use: rC   demozwIt is recommended that you share your [magenta]source code[/] so that others can learn from and improve your component.z1:books: Would you like to share your source code?zQ:file_folder: Please enter the path to the source directory. Leave blank to use: zpyproject.tomlprojectr-   rh      zdemo_dir must be set)dirs_exist_okz
.gitignoresrc)r|   ignorez	README.md)rS   spacegradio)rY   	repo_typeexist_ok	space_sdk)rY   folder_pathr   )rY   path_or_fileobjpath_in_repor   
)rY   factory_rebootrS   z/Demo uploaded to https://huggingface.co/spaces/z !)rf   r   )-r   r	   ra   existsr6   is_dirr   globr=   r
   PYPI_REGISTER_URLr   r   askhomer2   r   twine.commands.uploadrp   twine.exceptionsrq   twine.settingsrr   ImportErrorModuleNotFoundErrorrB   joinr8   print_exceptionr   	read_textr-   ri   tempfileTemporaryDirectoryshutilcopytreecopyfiler$   r   create_reporY   upload_folderupload_filerestart_space)!rE   rG   rI   rK   rM   rO   rQ   rS   rU   rW   rY   consoler:   rk   
wheel_filert   paneltwine_uploadrq   rr   etwine_settingstwine_files	demo_dir_source_dir_pyproject_toml_pathpyproject_tomlpackage_name_tempdirapirepo_urlrw   s!                                   @r#   _publishr   E   s   R #    iiG!!H?? 
jjj
 
 	
 ?? ;H999::: !(^^0055      ==&===  J  
<
 
 	
 K M  |ev| | |
 

 	ek";<< 
	DIKK)3;;== 
	PQQQdikkI566KK 	 K   #J'STTM"JAD  M  #&	DDDDDD<<<<<<///////01 	 	 	:  	
  	] 	%X}}UUUNN 	%X+>>>NNT  	&*+=>>K   +  K
 =chh{&;&;==>>>^[9999&    [   :  	& 	& 	&##%%%%%	& 18 1<
 
 	ek"?@@ 	1y E %LLL
{fjknfoforxfx{{ I "<ScV);%<%<II..00H 5= 5 F
 
 	e$WXX 	5
thrtt   	  k**2244J :Q(+;;	?"#6#@#@#B#BCCN))4V<LL 	? 	? 	? * 5 5c : :2A2 >\111	?  	53444$///44RaR8a(** -	QgOHG"   
 OJ-..DMML011    
OOW-.."&"	    OJ,--s4==;3N/O/O   e$$$C/<!"	 '  H &G#!    
  #$'
OO!+%	      $KKKgd%PPPOGOOOPPP[-	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q -	Q:Q :Qst   ?G G8#G33G8,AJ /I< ;J <JJJJ J;:J;8/P( (/QQ&F0Y##Y'*Y'c                    |                                  }|dz                                  r|dz  S |dz                                  r|dz  S t          d|  d          )Nzspace.pyzapp.pyz*Could not find "space.py" or "app.py" in "z".)ra   r   FileNotFoundError)rO   	_demo_dirs     r#   resolve_demor   +  s{      ""IJ&&(( 
:%%
h
	&	&	(	( 
8##EEEE
 
 	
r%   )r&   r   r'   r(   )r1   r2   r'   r3   )r:   r;   r'   r(   )rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   )rO   r   r'   r   )'
__future__r   r+   r   r   pathlibr   typingr   r5   huggingface_hubr   packaging.versionr   r7   richr   rich.consoler	   
rich.panelr
   rich.promptr   r   tomlkitr   typerr   r   gradio.analyticsr   colorsr   r$   r0   r9   rB   r   r   rv   r%   r#   <module>r      s   " " " " " " 				                   ! ! ! ! ! ! 6 6 6 6 6 6                         ' ' ' ' ' ' ' '       " " " " " " " " 7 7 7 7 7 7	O	O	O8      
 
 
 
4 4 4 4& 	S		FNRKMKM 	SW 	S		 	 	 	 	OcQ cQ cQ cQ cQL	
 	
 	
 	
 	
 	
r%   