o
    ۷i                     @  s   d dl mZ d dl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mZ d dlmZ d dlmZ d%ddZ	d&d'ddZd(ddZedddfd)d#d$ZdS )*    )annotationsN)Path)	Annotated)escape)ArgumentOption)LivePanelDisplay)set_directorynpm_installstrc                 C  s4   |   } | dkrtd}|std| d} | S )Nnpm installnpmzBy default, the install command uses npm to install the frontend dependencies. Please install npm or pass your own install command via the --npm-install option.z install)stripshutilwhich
ValueError)r
   r    r   f/home/ubuntu/vllm_env/lib/python3.10/site-packages/gradio/cli/commands/components/install_component.py_get_npm   s   

r   F
executableexecutable_path
str | Nonecli_arg_namecheck_3boolreturnc                 C  sv   |rt | rt | std|  d| d|S t| }|r,t|  dp+|}|s9td|  d| d|S )a  Get the path to an executable, either from the provided path or from the PATH environment variable.

    The value of executable_path takes precedence in case the value in PATH is incorrect.
    This should give more control to the developer in case their envrinment is not set up correctly.

    If check_3 is True, we append 3 to the executable name to give python3 priority over python (same for pip).
    zThe provided z path (z") does not exist or is not a file.3zCould not find z=. Please ensure it is installed and in your PATH or pass the z parameter.)r   existsis_filer   r   r   )r   r   r   r   pathr   r   r   _get_executable_path   s   
r    	directoryr   liver   pip_pathc                 C  s  t d|ddd}|ddt|  dg}|dtd	| d
 tj|dddd}|jdkr>|d ||j t	d|d |d| d
 t
| d 3 tj| dddd}|jdkrx|d ||j ||j t	d|d W d    d S 1 sw   Y  d S )Npipz
--pip-pathT)r   r   r   installz-ez[dev]z4:construction_worker: Installing python... [grey37]( z)[/]F)capture_outputtextcheckr   z8:red_square: Python installation [bold][red]failed[/][/]zPython installation failedz,:white_check_mark: Python install succeeded!z8:construction_worker: Installing javascript... [grey37](frontendz0:red_square: NPM install [bold][red]failed[/][/]zNPM install failedz):white_check_mark: NPM install succeeded!)r    r   updater   join
subprocessrun
returncodestderr
SystemExitr	   splitstdout)r!   r"   r
   r#   pip_executable_pathcmdspiper   r   r   _install_command:   s6   





"r7   .r   QAnnotated[Path, Argument(help='The directory containing the custom components.')]TAnnotated[str, Option(help="NPM install command to use. Default is 'npm install'.")]Annotated[str | None, 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.')]c                 C  sB   t |}t }t| ||| W d    d S 1 sw   Y  d S )N)r   r   r7   )r!   r
   r#   r"   r   r   r   _install^   s   "r<   )r
   r   )F)
r   r   r   r   r   r   r   r   r   r   )r!   r   r"   r   r
   r   r#   r   )r!   r9   r
   r:   r#   r;   )
__future__r   r   r-   pathlibr   typingr   rich.markupr   typerr   r   gradio.cli.commands.displayr   gradio.utilsr	   r   r    r7   r<   r   r   r   r   <module>   s"    

'