
    wi                        d dl m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mZ d dlmZ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'd%ZdS )(    )annotationsN)Path)	Annotated)print)Panel)ConfirmPrompt)dumpparse)custom_component_analytics   )LivePanelDisplay   )_create_utils)_get_npm_install_command Tnpm installFnamegAnnotated[str, typer.Argument(help='Name of the component. Preferably in camel case, i.e. MyTextBox.')]	directoryAnnotated[Path | None, typer.Option(help='Directory to create the component in. Default is None. If None, will be created in <component-name> directory in the current directory.')]package_nameaAnnotated[str | None, typer.Option(help='Name of the package. Default is gradio_{name.lower()}')]templatekAnnotated[str, typer.Option(help='Component to use as a template. Should use exact name of python class.')]installAnnotated[bool, typer.Option(help='Whether to install the component in your current environment as a development install. Recommended for development.')]npm_installZAnnotated[str, typer.Option(help="NPM install command to use. Default is 'npm install'.")]pip_pathAnnotated[str | None, typer.Option(help='Path to pip executable. If None, will use the default path found by `which pip3`. If pip3 is not found, `which pip` will be tried. If both fail an error will be raised.')]	overwrite_Annotated[bool, typer.Option(help='Whether to overwrite the existing component if it exists.')]configure_metadatamAnnotated[bool, typer.Option(help='Whether to interactively configure project metadata based on user input')]c	                j	   t          d|d d d |           |s!t          |                                           }|sd|                                  }|                                r'|s%t	          d|                                 d          |                                r|rt          j        |           |                    |           t          j	                    rt          j        d           d}nt          |          }t                      5 }	|	                    d	|  d
| dd           |r|	                    d| d           n|	                    d           t          j        |          }
t          j        | |
||           |	                    dd           t          j        |                                 |
||           |	                    dd           |rt%          ||	||           |	j                                         d}g }|rt+          t-          d                     t/          j        d          }t3          |dz                                            }|r@|d         d         } t7          j        d          }|r||d         d<   t7          j        d          pd}t+          d| d           ||d         d<   t7          j        d           }|pd!}t+          d"| d           |pd!|d         d#<   t+          d$           	 t7          j        d&          }|r|                    |           nn.|d                             d'g           }||z   |d         d'<   t=          |dz  d(d)*          5 }t?          ||           d d d            n# 1 swxY w Y   |d+z  d,z                       |           t          tB                    j"        d-z  d.z  }|                                }|rd/d/#                    |           nd0}d/| }|$                    d1|          $                    d2|          $                    d3|          $                    d4|          }|d.z                       |           t+          d5           d d d            d S # 1 swxY w Y   d S )6Ncreate)r   gradio_zThe directory z already exists. Please set --overwrite flag or pass in the name of a directory that does not already exist via the --directory option.)exist_okpnpmz i --ignore-scriptsz5:building_construction:  Creating component [orange3]z[/] in directory [orange3]z[/]g?)	add_sleepz&:fax: Starting from template [orange3]z7:page_facing_up: Creating a new component from scratch.z:snake: Created backend code)r   r   z:art: Created frontend codezA gradio custom componentzIt is recommended to answer the following [bold][magenta]4 questions[/][/] to finish configuring your custom component's metadata.
You can also answer them later by editing the [bold][magenta]pyproject.toml[/][/] file in your component directory.z 
Do you want to answer them now?zpyproject.tomlprojectr   zY
:pencil: Please enter a one sentence [bold][magenta]description[/][/] for your componentdescriptionzv
:bookmark_tabs: Please enter a [bold][magenta]software license[/][/] for your component. Leave blank for 'apache-2.0'z
apache-2.0z-:bookmark_tabs: Using license [bold][magenta]z[/][/]licensezs
:snake: Please enter the [bold][magenta]allowed python[/][/] versions for your component. Leave blank for '>=3.10'z>=3.10z0:snake: Using requires-python of [bold][magenta]zrequires-pythonzI
:label: Please add some keywords to help others discover your component.Tz+:label: Leave blank to stop adding keywordskeywordswzutf-8)encodingdemozrequirements.txtfilesz	README.mdz, r   z	<<title>>z<<short-description>>z<<tags>>z<<template>>z2
Component creation [bold][magenta]complete[/][/]!)%r   r   lowerexists
ValueErrorresolver   delete_contentsmkdir_in_test_dirshutilwhichr   r   update_get_component_code_create_backend_create_frontendr   _panelstopr   r   r   askr   	read_textr	   appendgetopenr
   
write_text__file__parentjoinreplace)r   r   r   r   r   r   r!   r#   r%   live	componentr.   r0   	answer_qspyproject_tomllicense_requires_pythonkeywordcurrent_keywordsfreadme_pathreadme_contentstagss                          u/root/.openclaw/workspace/chatterbox_venv_py311/lib/python3.11/site-packages/gradio/cli/commands/components/create.py_creater[      s6   d      '&&	 0/// 1) 1UY..00 U U U
 
 	

 
				 1	 1%i000OOYO'''!## ,f--BBB{++			 aEtrDrrdmrrr 	 	
 	
 	
  	SKKNNNNOOOOKKQRRR!5h??	%dIy,OOO2cBBB&JJLL)y|	
 	
 	
 	
 	1SAAA 	EYk8DDD1 5	,L     $GHHI"I0@$@#K#K#M#MNNN ),%i08$jp   K?JN9-m< J R  $ $	  VhVVVWWW7?y))4"(* K# # #2"=X^^^^   $/x y)*;< `  $j)VWWG  0000 $2)#<#@#@R#P#P 8H88Sy)*5)&66gNNN ,RS+++, , , , , , , , , , , , , , , 
V	0	0<<\JJJ8nn+g5C%//11-5=)DIIh'')))2"??##K>>W,k::WZ&&W^X..	 	 
[	 ,,_===CDDDCaE aE aE aE aE aE aE aE aE aE aE aE aE aE aE aE aE aEs8   I6R(N(R((N,	,R(/N,	0C+R((R,/R,)NNr   Tr   NFT)r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   )
__future__r   r<   pathlibr   typingr   typerrichr   
rich.panelr   rich.promptr   r	   tomlkitr
   r   gradio.analyticsr   displayr   r   r   install_componentr   r   r[        rZ   <module>ri      sI   " " " " " "                           ' ' ' ' ' ' ' '         7 7 7 7 7 7 & & & & & &       9 9 9 9 9 9 9 9 	 	 	 	 	 	 	 	apE pE pE pE pE pE pErh   