
    ;3h*              
      @   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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ddZ ddZ! ed      dz  ddddd ed      dddf
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ"ddZ#y)    )annotationsN)Path)	AnnotatedOptional)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 ]:  }d|v s#|j                  d      s|j                  d      s*|j                  |       < |S )N__pycache__distnode_modules)
startswithappend)_srcnamesignoredns       f/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/cli/commands/components/publish.py_ignorer$      sG    G Af!5n9UNN1 N    c                j    t        j                  d| j                        }|r|j                  d      S y )Nz-(\d+\.\d+\.\d+[a-zA-Z]*\d*)-   )researchnamegroup)	dist_filematchs     r#   _get_version_from_filer.   !   s-    II6	GE{{1~ r%   c                    g }| D ]5  }t        |      }|s	 |j                  t        j                  |             7 |rt        t        |            S d S # t        $ r Y  y w xY w)N)r.   r   semantic_versionVersion
ValueErrorstrmax)distribution_filesversionspversions       r#   _get_max_versionr9   '   sn    H (+  0 8 8 AB "*3s8}3t3  s   $A	A"!A".r   T Fc
           	     p   t        dd |||	       t               }
| j                         } | j                         st	        |  d      | j                         st	        |  d      t        |       j                  d      D cg c]!  }|j                  dv s|j                         # }}t        d |D        d 	      }|st	        d
      d }|r|r|st        dt         d      }t        |       t        j                  d      }|rQt        j                         dz  j                         r,t        d       t!        t        j                         dz        }n9|r7t        d       t#        j                  d      }t#        j                  dd      }|r	 ddlm} ddlm} ddlm} |r|r |||      }n|r
 ||      }nt	        d      	 t5        |      }|D cg c]  }|r||j6                  v rt!        |       }}t        ddj9                  |              	  |||       	 |r|st        d       }t        |       t        j                  d!      }|rnt        d"      }t        |       t#        j                  d#t        d$      d%z         }|xs t!        t        d$      d%z        }t        |      j                         }|rd|	sbt        d&      }t        |       t        j                  d'      }	|	r5t#        j                  d(|       xs |}t        |      j                         }|r|d)z  }	 t?        |jA                               }|d*   d+   }|st	        d.      |j6                  jC                  d,      d d- \  }}tE        jF                         5 }tI        jJ                  t!        |      t!        |      d/       tI        jL                  t!        |d0z        t!        t        |      d0z               |	r;tI        jJ                  t!        |      t!        t        |      d1z        dtN        2       tI        jL                  t!        |d3z        t!        t        |      d3z               tQ        |4      }|jS                  |d5dd67      }|jT                  } |jW                  | |d58       |r(|jY                  | t!        |      |j6                  d59       t        d:       |j[                  | d|;       t        d<|  d=       d d d        y y c c}w # t0        t2        f$ r}t	        d      |d }~ww xY wc c}w # |$ r}t	        d      |d }~ww xY w# t:        $ r |
j=                          Y Lw xY w# t:        $ r% |j6                  jC                  d,      d d- \  }}Y Nw xY w# 1 sw Y   y xY w)>Npublish)upload_demoupload_pypiupload_sourcezQ does not exist. Run `gradio cc build` to create a wheel and source distribution.z is not a directory*>   .gz.whlc              3  @   K   | ]  }|j                   d k(  s|  yw)rC   N)suffix).0r7   s     r#   	<genexpr>z_publish.<locals>.<genexpr>n   s     =q!((f*<=s   c                v    t        j                  t        | j                        j	                  d      d         S )N-r'   )r0   r1   r3   r*   split)ss    r#   <lambda>z_publish.<locals>.<lambda>o   s*    &..s166{/@/@/Ea/H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.)usernamerN   )config_filezBNo pypi username or password provided and no ~/.pypirc file found.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*   rI      zdemo_dir must be set)dirs_exist_okz
.gitignoresrc)rX   ignorez	README.md)tokenspacegradio)repo_id	repo_typeexist_ok	space_sdk)r^   folder_pathr_   )r^   path_or_fileobjpath_in_repor_   
)r^   factory_rebootr[   z/Demo uploaded to https://huggingface.co/spaces/z !).r   r	   resolveexistsr2   is_dirr   globrE   r4   r
   PYPI_REGISTER_URLr   r   askhomer3   r   twine.commands.uploadrO   twine.exceptionsrP   twine.settingsrQ   ImportErrorModuleNotFoundErrorr9   r*   join	Exceptionprint_exceptionr   	read_textrJ   tempfileTemporaryDirectoryshutilcopytreecopyfiler$   r   create_repor^   upload_folderupload_filerestart_space)!dist_dirr?   pypi_usernamepypi_passwordr>   demo_dir
source_dirhf_tokenprefer_localr@   consoler7   r5   
wheel_filerS   paneltwine_uploadrP   rQ   etwine_settingsmax_versiontwine_files	demo_dir_source_dir_pyproject_toml_pathpyproject_tomlpackage_name_tempdirapirepo_urlr^   s!                                    r#   _publishr   5   s   J # iG!H??jij
 	
 ??H:%89::!(^005_9T		  =&=IJ <
 	
 KMeevdwwz|

 	ekk";<DIIK)3;;=PQdiikI56K K #JJ'STM"JJADM 	D</ ]%}}UN%+>NT 	&*+=>K ,#{aff'< AK 
 %chh{&;%<=>^[9 8<
 	ekk"?@yE %L

dfjknforxfxdz{I "<ScV);%<II..0H= F
 	e$WX

ghrgst  	  k*224J(+;;	?"#6#@#@#BCN))4V<L 344$////4Ra8a((* -	QgOOHG"
 OOJ-.DML01 
OW-."&"	 OOJ,-s4=;3N/O h'C$!"	 ' H &&G#!  
 #$'
O!+%	    $Kgd(SCG9BOP[-	Q -	Q OJ 01 	: 	  '  [ 
  	&##%	&V  	? * 5 5c :2A >\1	?-	Q -	Qs   TTT U "T=U !	U 9!U; E/V,T:)T55T:=U UUUU U87U8;*V)(V),V5c                    | j                         }|dz  j                         r|dz  S |dz  j                         r|dz  S t        d|  d      )Nzspace.pyzapp.pyz*Could not find "space.py" or "app.py" in "z".)rg   rh   FileNotFoundError)r   	_demo_dirs     r#   resolve_demor     sa      "IJ&&(:%%
h
	&	&	(8##8
"E
 	
r%   )r,   r   returnOptional[str])r5   z
list[Path]r   r   )r   z_Annotated[Path, Argument(help=f"Path to the wheel directory. Default is {Path('.') / 'dist'}")]r?   z:Annotated[bool, Option(help='Whether to upload to PyPI.')]r   z5Annotated[str, Option(help='The username for PyPI.')]r   z5Annotated[str, Option(help='The password for PyPI.')]r>   zFAnnotated[bool, Option(help='Whether to upload demo to HuggingFace.')]r   zEAnnotated[Optional[Path], Option(help='Path to the demo directory.')]r   zUAnnotated[Path, Option(help='Path to the source directory of the custom component.')]r   zAnnotated[Optional[str], Option(help='HuggingFace token for uploading demo. Can be omitted if already logged in via huggingface cli.')]r   zvAnnotated[bool, Option(help='Install the package from the local wheel in the demo space, even if it exists on PyPi.')]r@   zwAnnotated[bool, Option(help='Whether to upload the source code of the custom component, to share with the community.')])r   r   r   r   )$
__future__r   r(   ry   rw   pathlibr   typingr   r   r0   huggingface_hubr   richr   rich.consoler	   
rich.panelr
   rich.promptr   r   tomlkitr   typerr   r   gradio.analyticsr   colorsrk   r$   r.   r9   r   r    r%   r#   <module>r      s   " 	    &  !     '  " 7	O8 4$ 	S	FNRKMKM 	 	 	S	 	 	 	GVQVQ
 LVQ IVQ IVQVQVQVQ$%VQ01VQ<=VQr	
r%   