o
    e~#g:                     @  s   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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 eejjd d ZedddddfdddZdS )    )annotationsN)Path)	AnnotatedOptional)dumpparse)custom_component_analytics)get_deep)run_command)_get_executable_path)LivePanelDisplay	templatesfrontend.TFpathNAnnotated[Path, typer.Argument(help='The directory of the custom component.')]build_frontendLAnnotated[bool, typer.Option(help='Whether to build the frontend as well.')]bump_versionWAnnotated[bool, typer.Option(help='Whether to bump the version number automatically.')]generate_docsTAnnotated[bool, typer.Option(help='Whether to generate the documentation as well.')]python_pathAnnotated[Optional[str], typer.Option(help='Path to python executable. If None, will use the default path found by `which python3`. If python3 is not found, `which python` will be tried. If both fail an error will be raised.')]c                 C  sT  t dd d d d ||d t|  }|d  std| t }}|jdt|j ddd t	| d 
 }t|d	d
g}td|ddd}t|tsQtdzt| W n tym }	 z	td| d|	d }	~	ww |rt	| d 
 }t|d	 d  }
|d|
 d t|
|d	 d< t| d ddd}t|| W d    n1 sw   Y  n|d	 d }
|d|
 d |rtd }d}|| }|d }t||d|ddd|||d |dd |rS|d  |  }td!}|std"tj|d#d$gt|d% ddd&}|jd'krtd(|jd }||d)|d*td+dd|g
}tj|dddd,}|jd'krN|d- ||j  ||j t!d.|d/ |d0dt|g}|d1d2"| d3 tj|dddd,}|jd'kr|d- ||j  t!d4|d/ |d5t|d6  d W d    d S 1 sw   Y  d S )7Nbuild)r   r   zpyproject.tomlz#Cannot find pyproject.toml file in z':package: Building package in [orange3]z[/]g?)	add_sleepprojectnamepythonz--python-pathT)check_3z>Your pyproject.toml file does not have a [project] name field!zYour custom component package (z\) is not installed! Please install it with the gradio cc install command before building it.versionz$:1234: Using version [bold][magenta]z][/][/]. Set [bold][magenta]--no-bump-version[/][/] to use the version in pyproject.toml file.wzutf-8)encodingz/:1234: Package will use version [bold][magenta]zx[/][/] defined in pyproject.toml file. Set [bold][magenta]--bump-version[/][/] to automatically bump the version number.demozapp.pyz	README.mdFsimple)liver   suppress_demo_checkpyproject_tomlgenerate_spacegenerate_readme	type_mode
_demo_path	_demo_dir_readme_path	space_url_component_dirr$   z:art: Building frontendnodez5node must be installed in order to run build command.z-ez/console.log(require.resolve('@gradio/preview'))r   )cwdcheckcapture_outputr   zYCould not find `@gradio/preview`. Run `npm i -D @gradio/preview` in your frontend folder.z--component-directoryz--rootz--mode)r3   textr2   z:red_square: Build failed!zFrontend build failedz#:white_check_mark: Build succeeded!z-mz+:construction_worker: Building... [grey37]( z)[/]zPython build failedz):ferris_wheel: Wheel located in [orange3]dist)#r   r   resolveexists
ValueErrorr   updatestrr   r   	read_textr	   r   
isinstance	importlibimport_moduleModuleNotFoundErrorsemantic_versionVersion
next_patchopenr   r
   shutilwhich
subprocessrun
returncodestdoutdecodestripgradio_template_pathstderr
SystemExitjoin)r   r   r   r   r   r   r%   r'   package_nameer    fr,   
_demo_namer+   r-   component_directoryr0   gradio_node_path	node_cmdspipecmds rZ   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/gradio/cli/commands/components/build.py_build   s   	












$r\   )
r   r   r   r   r   r   r   r   r   r   )
__future__r   r>   rE   rG   pathlibr   typingr   r   rA   typertomlkitr   r   gradiogradio.analyticsr   *gradio.cli.commands.components._docs_utilsr	   #gradio.cli.commands.components.docsr
   0gradio.cli.commands.components.install_componentr   gradio.cli.commands.displayr   __file__parentrM   r\   rZ   rZ   rZ   r[   <module>   s,    