o
    ۷i                     @  s   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%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	              	   C  s@  t d|d d d |d |st|  }|sd|   }| r+|s+td|  d| r6|r6t| |j|d t	 rIt
d d}nt|}t D}	|	jd	|  d
| ddd |rl|	d| d n|	d t|}
t| |
|| |	jddd tj|  |
||d |	jddd |rt||	|| |	j  d}g }|rHttd td}t|d  }|rH|d d } td}|r||d d< tdpd}td| d ||d d< td }|pd!}td"| d |pd!|d d#< td$ 	 td&}|r|| nnq|d d'g }|| |d d'< t|d d(d)d*}t|| W d    n	1 sCw   Y  |d+ d,  | tt!j"d- d. }| }|rid/d/#| nd0}d/| }|$d1|$d2|$d3|$d4|}|d.  | td5 W d    d S 1 sw   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,   r.   	answer_qspyproject_tomllicense_requires_pythonkeywordcurrent_keywordsfreadme_pathreadme_contentstags rX   [/home/ubuntu/vllm_env/lib/python3.10/site-packages/gradio/cli/commands/components/create.py_create   s   2











$rZ   )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   rZ   rX   rX   rX   rY   <module>   s,    