
    Pi                        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Z	 d"d#dZd$dZ ed          ddfd%d ZdS )&    )annotationsN)Path)	Annotated)escape)ArgumentOption)LivePanelDisplay)set_directorynpm_installstrc                    |                                  } | dk    r*t          j        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   s     /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/gradio/cli/commands/components/install_component.py_get_npmr      sb    ##%%Km##l5!! 	0  
 &&&    F
executableexecutable_path
str | Nonecli_arg_namecheck_3boolreturnc                L   |rZt          |                                          r!t          |                                          st          d|  d| d          |S t	          j        |           }|rt	          j        |  d          p|}|st          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   paths        r   _get_executable_pathr#      s      O$$++-- 	T/5J5J5R5R5T5T 	f
ff?fff   <
##D 6|z,,,--5 
 Aj  A  Ags  A  A  A
 
 	
 Kr   	directoryr   liver	   pip_pathc                   t          d|dd          }|ddt          |            dg}|                    dt          d	                    |                     d
           t          j        |ddd          }|j        dk    r>|                    d           |                    |j                   t          d          |                    d           |                    d| d
           t          | dz            5  t          j        |                                ddd          }|j        dk    rX|                    d           |                    |j                   |                    |j                   t          d          |                    d           	 d d d            d S # 1 swxY w 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pipes          r   _install_commandr;   :   s4    /xlD    DS^^2J2J2JKDKK[vchhtnn?U?U[[[   >$t$eLLLD!NOOODK   5666 	BCCCKKT;TTT   
y:-	.	. 
E 
E~4u
 
 
 ?aKKJKKKKK$$$KK$$$1222KKCDDDD
E 
E 
E 
E 
E 
E 
E 
E 
E 
E 
E 
E 
E 
E 
E 
E 
E 
Es   B#F55F9<F9.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                    t          |          }t                      5 }t          | |||           d d d            d S # 1 swxY w Y   d S )N)r   r	   r;   )r$   r   r&   r%   s       r   _installrA   ^   s     ;''K			 AtD+x@@@A A A A A A A A A A A A A A A A A As   >AA)r   r   )F)
r   r   r   r   r   r   r   r   r   r   )r$   r   r%   r	   r   r   r&   r   )r$   r=   r   r>   r&   r?   )
__future__r   r   r1   pathlibr   typingr   rich.markupr   typerr   r   gradio.cli.commands.displayr	   gradio.utilsr
   r   r#   r;   rA    r   r   <module>rJ      s*   " " " " " "                        " " " " " " " " 8 8 8 8 8 8 & & & & & &   $ 	    :!E !E !E !EN 	S		 	 	A A A A A A Ar   