
    ;3h                        d dl mZ d dlZd dlZd dlmZ d dlmZ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y)    )annotationsN)Path)	AnnotatedOptional)escape)ArgumentOption)LivePanelDisplay)set_directoryc                ~    | j                         } | 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)npm_installr   s     p/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/cli/commands/components/install_component.py_get_npmr      sO    ##%Km#ll5!0 
 X&    c                $   |rFt        |      j                         rt        |      j                         st        d|  d| d      |S t	        j
                  |       }|rt	        j
                  |  d      xs |}|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   )
executableexecutable_pathcli_arg_namecheck_3paths        r   _get_executable_pathr       s     O$++-T/5J5R5R5T
|7?2CCef  <<
#D||zl!,-5j\)fgsftt  A
 	
 Kr   c                $   t        d|dd      }|ddt        |        dg}|j                  dt        d	j	                  |             d
       t        j                  |ddd      }|j                  dk7  r7|j                  d       |j                  |j                         t        d      |j                  d       |j                  d| d
       t        | dz        5  t        j                  |j                         ddd      }|j                  dk7  rR|j                  d       |j                  |j                         |j                  |j                         t        d      |j                  d       	 d d d        y # 1 sw Y   y xY w)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    strupdater   join
subprocessrun
returncodestderr
SystemExitr   splitstdout)	directoryliver   pip_pathpip_executable_pathcmdspipes          r   _install_commandr9   :   si    /xlD  DS^4DE2JKDKK
>vchhtn?U>VVZ[ >>$t$eLD!NODKK 566 	BCKK
B;-tT 
y:-	. 
E~~4u
 ??aKKJKKK$KK$122KKCD
E 
E 
Es   "BFF.r   c                t    t        |      }t               5 }t        | |||       d d d        y # 1 sw Y   y xY w)N)r   r
   r9   )r3   r   r5   r4   s       r   _installr<   ^   s=     ;'K		 AtD+x@A A As   .7)r   r)   )F)
r   r)   r   
str | Noner   r)   r   boolreturnr)   )r3   r   r4   r
   r   r)   r5   r=   )r3   zQAnnotated[Path, Argument(help='The directory containing the custom components.')]r   zTAnnotated[str, Option(help="NPM install command to use. Default is 'npm install'.")]r5   zAnnotated[Optional[str], 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.')])
__future__r   r   r,   pathlibr   typingr   r   rich.markupr   typerr   r	   gradio.cli.commands.displayr
   gradio.utilsr   r   r    r9   r<    r   r   <module>rH      s    "    &  " 8 &$ 	  	
 	:!E!E+!E:=!EIS!EN 	S	 	 	AA	AAr   