
    wi+                    &   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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d5dZd6dZ  ed          dz  ddddd ed          ddddfd7d3Z!d8d4Z"dS )9    )annotationsN)Path)	Annotated)HfApi)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       v/root/.openclaw/workspace/chatterbox_venv_py311/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_filer/   !   s8    I6	GGE {{1~~ r$   distribution_files
list[Path]c                    g }| D ]N}t          |          }|r;	 |                    t          j        |                     <# t          $ r Y  d S w xY wO|rt          t          |                    nd S )N)r/   r   semantic_versionVersion
ValueErrorstrmax)r0   versionspversions       r"   _get_max_versionr;   '   s    H  (++  	 0 8 A ABBBB   ttt	
 "*33s8}}t3s   'A
AA.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.')]hf_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 hf_token.')]c           	        t          dd |||	           t                      }|                                 } |                                 st	          |  d          |                                 st	          |  d          d t          |                               d          D             }t          d |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 d.         \  }}Y nw xY w|st	          d/          |j                             d-          d d.         \  }}tC          j"                    5 }tG          j$        t          |          t          |          d0           tG          j%        t          |d1z            t          t          |          d1z                       |	rGtG          j$        t          |          t          t          |          d2z            dtL          3           tG          j%        t          |d4z            t          t          |          d4z                       tO          |5          }|(                    |
p|d6dd78          }|j)        }
|*                    |
|d69           |r+|+                    |
t          |          |j        d6:           t          d;           |,                    |
d|<           t          d=|
 d>           d d d            d S # 1 swxY w Y   d S d S )?Npublish)rF   r@   rP   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.0r9   s     r"   
<listcomp>z_publish.<locals>.<listcomp>n   s3       _9T9T		9T9T9Tr$   *c              3  0   K   | ]}|j         d k    |V  dS )rX   N)rY   r[   s     r"   	<genexpr>z_publish.<locals>.<genexpr>r   s.      ==q!(f*<*<*<*<*<*<==r$   c                    t          j        t          | j                                      d          d                   S )N-r)   )r3   r4   r6   r,   split)ss    r"   <lambda>z_publish.<locals>.<lambda>s   s-    &.s16{{/@/@/E/Ea/HII 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.)usernamerg   )config_filezBNo pypi username or password provided and no ~/.pypirc file found.c                D    g | ]}r	|j         v t          |          S  )r,   r6   )r\   r9   max_versions     r"   r]   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: r<   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,   rb      zdemo_dir must be set)dirs_exist_okz
.gitignoresrc)rt   ignorez	README.md)tokenspacegradio)rR   	repo_typeexist_ok	space_sdk)rR   folder_pathrz   )rR   path_or_fileobjpath_in_reporz   
)rR   factory_rebootrw   z/Demo uploaded to https://huggingface.co/spaces/z !)-r   r   rZ   existsr5   is_dirr   globr7   r	   PYPI_REGISTER_URLr   r
   askhomer6   r   twine.commands.uploadrh   twine.exceptionsri   twine.settingsrj   ImportErrorModuleNotFoundErrorr;   join	Exceptionprint_exceptionr   	read_textr,   rc   tempfileTemporaryDirectoryshutilcopytreecopyfiler#   r   create_reporR   upload_folderupload_filerestart_space) r>   r@   rB   rD   rF   rH   rJ   rL   rN   rP   rR   consoler0   
wheel_filerl   paneltwine_uploadri   rj   etwine_settingstwine_files	demo_dir_source_dir_pyproject_toml_pathpyproject_tomlpackage_name_tempdirapirepo_urlro   s                                   @r"   _publishr   5   su   R #    iiG!!H?? 
jjj
 
 	
 ?? ;H999::: !(^^0055   ==&===II  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   h'''C/<!"	 '  H &G#!    
  #$'
OO!+%	      $KKKgd(SSS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 G5 G00G5)AJ ,I9 8J 9J>JJJ J87J85/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".)rZ   r   FileNotFoundError)rH   	_demo_dirs     r"   resolve_demor     s{      ""IJ&&(( 
:%%
h
	&	&	(	( 
8##EEEE
 
 	
r$   )r%   r   r&   r'   )r0   r1   r&   r'   )r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   )rH   r   r&   r   )#
__future__r   r*   r   r   pathlibr   typingr   r3   huggingface_hubr   richr   rich.consoler   
rich.panelr	   rich.promptr
   r   tomlkitr   typerr   r   gradio.analyticsr   colorsr   r#   r/   r;   r   r   rn   r$   r"   <module>r      s   " " " " " " 				                   ! ! ! ! ! !                         ' ' ' ' ' ' ' '       " " " " " " " " 7 7 7 7 7 7	O	O	O8      4 4 4 4$ 	S		FNRKMKM 	SW 	S		 	 	 	 	OZQ ZQ ZQ ZQ ZQz	
 	
 	
 	
 	
 	
r$   