
    ,i/                       U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 d dlmZmZmZ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
lmZ ddlmZmZ ddlm Z   ejB                  e"      Z#de$d<   ee%ee   f   Z&ed   Z'dZ(dZ) ejT                  d      Z+ G d de      Z, G d de      Z- G d de	      Z. G d de.      Z/ G d de.      Z0ee0e/f   Z1d'dZ2ejf                  d	 	 	 	 	 	 	 d(dZ4d)d Z5d*d!Z6d+d"Z7 G d# d$ee1         Z8 e8d%      js                         Z: e8d&      js                         Z;y),    )annotationsN)ABCabstractmethod)IOAnyUnionMappingcast)Path)Literaloverride   )config)	LazyProxy)PrismaError)nodejsget_args)platformzlogging.Loggerlog)nodenpm)      )      zv?(\d+)(?:\.?(\d+))c                        e Zd Zd fdZ xZS )UnknownTargetErrorc                   t         |   d| ddj                  t        t	        t
        t                                  y )NzUnknown target: z; Valid choices are: z, )super__init__joinr   r
   typeTargetselftarget	__class__s     U/var/www/html/langgraph-service/venv/lib/python3.12/site-packages/prisma/cli/_node.pyr    zUnknownTargetError.__init__&   s9    +F83HS[\`aegm\nSoIpHqrs    )r&   strreturnNone__name__
__module____qualname__r    __classcell__r'   s   @r(   r   r   %   s    t tr)   r   c                        e Zd Zd fdZ xZS )MissingNodejsBinErrorc                $    t         |   d       y )NzdAttempted to access a function that requires the `nodejs-bin` package to be installed but it is not.)r   r    )r%   r'   s    r(   r    zMissingNodejsBinError.__init__,   s    r	
r)   )r+   r,   r-   r2   s   @r(   r4   r4   +   s    
 
r)   r4   c                      e Zd Zdddddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZedddddd	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zeedd              Zy)	StrategyFNcheckcwdstdoutstderrenvc               X     | j                   |||||t        || j                        dS )z|Call the underlying Node.js binary.

        The interface for this function is very similar to `subprocess.run()`.
        )r=   
target_binr8   )__run___update_path_envr?   r%   r9   r:   r;   r<   r=   argss          r(   runzStrategy.run4   s8     t|| ??

 
	
r)   c                    y)zCall the underlying Node.js binary.

        This should not be directly accessed, the `run()` function should be used instead.
        N rB   s          r(   r@   zStrategy.__run__M   s    r)   c                     y)a  Property containing the location of the `bin` directory for the resolved node installation.

        This is used to dynamically alter the `PATH` environment variable to give the appearance that Node
        is installed globally on the machine as this is a requirement of Prisma's installation step, see this
        comment for more context: https://github.com/RobertCraigie/prisma-client-py/pull/454#issuecomment-1280059779
        NrF   r%   s    r(   r?   zStrategy.target_bin\   s     	r)   rC   r*   r9   boolr:   Path | Noner;   File | Noner<   rL   r=   Mapping[str, str] | Noner+   "subprocess.CompletedProcess[bytes]r+   r   )r.   r/   r0   rD   r   r@   propertyr?   rF   r)   r(   r7   r7   2   s    
 ""(,

 
 	

 
 
 &
 
,
2  ""(,  	
   & 
,    r)   r7   c                      e Zd ZU ded<   ded<   	 	 	 	 	 	 	 	 ddZeedd              Zedddddd		 	 	 	 	 	 	 	 	 	 	 	 	 dd
       Ze	dd       Z
e	dd       Zy)NodeBinaryStrategyr#   r&   Literal['global', 'nodeenv']resolverc               .    || _         || _        || _        y Npathr&   rT   )r%   rX   r&   rT   s       r(   r    zNodeBinaryStrategy.__init__l   s     	 r)   c                .    | j                   j                  S rV   )rX   parentrH   s    r(   r?   zNodeBinaryStrategy.target_binw   s     yyr)   FNr8   c                   t        | j                  j                               }t        j	                  d||       t        j                  |g||||||      S )Nz$Executing binary at %s with args: %sr9   r:   r=   r;   r<   )r*   rX   absoluter   debug
subprocessrD   )r%   r9   r:   r;   r<   r=   rC   rX   s           r(   r@   zNodeBinaryStrategy.__run__|   sU     499%%'(		8$E~~MDM
 	
r)   c                    d }t         j                  rt        |      }|t        ||d      S t        j	                  |      S )NglobalrW   )r   use_global_node_get_global_binaryrR   from_nodeenv)clsr&   rX   s      r(   resolvezNodeBinaryStrategy.resolve   sI    !!%f-D%!  "..v66r)   c                   t         j                  j                         }|j                         rt        j                  d|       nwt        j                  d|       	 t        j                  t        j                  ddt        |      gt         j                  dt        j                  t        j                         |j                         st!        d	      t#        j$                         d
k(  r|dz  }|dk(  r|dz  }n|| dz  }n|dz  |z  }|dk(  r | |d|      S |dk(  r | |d|      S t'        |      # t        $ r"}t        dt        j                         |d }~ww xY w)Nz8Skipping nodeenv installation as it already exists at %szInstalling nodeenv to %sz-mnodeenvT)r9   r;   r<   z`nodeenv installation failed; You may want to try installing `nodejs-bin` as it is more reliable.)filez[Could not install nodeenv to the expected directory; See the output above for more details.windowsScriptsr   znode.exez.cmdbinr   )rX   rT   r&   r&   )r   nodeenv_cache_dirr]   existsr   r^   r_   rD   sys
executabler*   nodeenv_extra_argsr;   r<   	ExceptionprintRuntimeErrorr   namer   )re   r&   	cache_direxcbin_dirrX   s         r(   rd   zNodeBinaryStrategy.from_nodeenv   s^   ,,557	IIJ
 II0)<!I	
  22 ::::& !m 
 ==?i')+G+F840u$v-DU?D9VDDvD9VDD$F337  v 	s   A D< <	E'E""E')rX   r   r&   r#   rT   rS   r+   r,   rO   rI   )r&   r#   r+   rR   )r.   r/   r0   __annotations__r    rP   r   r?   r@   classmethodrf   rd   rF   r)   r(   rR   rR   h   s    N**	! 	! 		!
 /	! 
	!       ""(,

 
 	

 
 
 &
 
,
 
( 7 7 14 14r)   rR   c                      e Zd ZU ded<   ded<   ddZedddddd	 	 	 	 	 	 	 	 	 	 	 	 	 dd	       Zedd
       Zeedd              Z	y)NodeJSPythonStrategyr#   r&   zLiteral['nodejs-bin']rT   c                    || _         d| _        y )Nz
nodejs-bin)r&   rT   )r%   r&   s     r(   r    zNodeJSPythonStrategy.__init__   s    $r)   FNr8   c               *   t         
t               d }| j                  dk(  rt         j                  j                  }n@| j                  dk(  rt         j
                  j                  }nt        | j                        t        d |||||||            S )Nr   r   rm   rN   r\   )r   r4   r&   r   rD   r   r   r
   )r%   r9   r:   r;   r<   r=   rC   funcs           r(   r@   zNodeJSPythonStrategy.__run__   s     >'));;& ;;??D[[E!::>>D$DKK880

 
	
r)   c                h    t         
t               t        t         j                  j                        S )z%Returns the path to the `node` binary)r   r4   r   r   rX   rH   s    r(   	node_pathzNodeJSPythonStrategy.node_path   s'     >'))FKK$$%%r)   c                @    t        | j                        j                  S rV   )r   r   rZ   rH   s    r(   r?   zNodeJSPythonStrategy.target_bin  s     DNN#***r)   r&   r#   r+   r,   rI   rO   )
r.   r/   r0   rz   r    r   r@   rP   r   r?   rF   r)   r(   r}   r}      s    N##%  ""(,

 
 	

 
 
 &
 
,
 
@ & & +  +r)   r}   c                   | dvrt        |       t        j                  rKt        j	                  d       t
        0t        j	                  dt
        j                         t        |       S t        j                  |       S )N>   r   r   rm   z#Checking if nodejs-bin is installedz!Using nodejs-bin with version: %s)
r   r   use_nodejs_binr   r^   r   node_versionr}   rR   rf   rm   s    r(   rf   rf     sb    _$ //		78II96;N;NO'v66%%f--r)   )sepc                   | t        t        j                        } t        j	                  d|       |j                         sJ d       | j                  dd      xs  t        j                  j                  dd      }|r=|j                  |      r|j                          | }n0|j                          | | }nt        |j                               }t        j	                  d|       i | d|iS )zReturns a modified version of `os.environ` with the `PATH` environment variable updated
    to include the location of the downloaded Node binaries.
    z%Attempting to preprend %s to the PATHz%Target `bin` directory does not existPATH z#Using PATH environment variable: %s)
dictosenvironr   r^   ro   get
startswithr]   r*   )r=   r?   r   rX   s       r(   rA   rA     s     {2::II5zBG GG7762<"**.."<D??3 ))+,TF3D ))+,SE$8D :&&()II3T: c 64  r)   c                h   t         j                  d|        t        j                  |       }|t         j                  d|        yt         j                  d|       t	        |      }|j                         st         j                  d|       yt        | |      syt         j                  d| |       |S )zuReturns the path to a globally installed binary.

    This also ensures that the binary is of the right version.
    z%Checking for global target binary: %sNz"Global target binary: %s not foundzFound global binary at: %sz#Global binary does not exist at: %s)r&   rX   zUsing global %s binary at %s)r   r^   shutilwhichr   ro   _should_use_binary)r&   r   rX   s      r(   rc   rc   :  s    
 II5v>LL E}		6?II*E2;D;;=		7?V$7II,fd;Kr)   c                    | dk(  rt         }n| dk(  rt        }nt        |       t        | |      }|t        j                  d| |        y||k  rt        j                  d| ||       yy)a2  Call the binary at `path` with a `--version` flag to check if it matches our minimum version requirements.

    This only applies to the global node installation as:

    - the minimum version of `nodejs-bin` is higher than our requirement
    - `nodeenv` defaults to the latest stable version of node
    r   r   rm   z=Could not resolve %s version, ignoring global %s installationFzPGlobal %s version (%s) is lower than the minimum required version (%s), ignoringT)MIN_NODE_VERSIONMIN_NPM_VERSIONr   _get_binary_versionr   r^   )r&   rX   min_versionversions       r(   r   r   T  s{     &	5% //!&$/G		K	

 		^		
 r)   c                   t        j                  t        |      dgt         j                  t         j                  d      }t
        j                  d| |j                         |j                  j                  d      j                  d      }t
        j                  d| |       t        j                  |      }|sy t        d |j                         D              }t
        j                  d	| |       |S )
Nz	--versionF)r;   r<   r9   z$%s version check exited with code %szutf-8
z%s version check output: %sc              3  2   K   | ]  }t        |        y wrV   )int).0values     r(   	<genexpr>z&_get_binary_version.<locals>.<genexpr>  s     ;5CJ;s   z%s version check returning %s)r_   rD   r*   PIPESTDOUTr   r^   
returncoder;   decoderstrip
VERSION_REsearchtuplegroups)r&   rX   procoutputmatchr   s         r(   r   r   x  s    >>	TK   	D II4fdooN[[(//5FII+VV<f%E;ELLN;;GII-vw?Nr)   c                  >     e Zd ZU ded<   d fdZedd       Z xZS )LazyBinaryProxyr#   r&   c                0    t         |           || _        y rV   )r   r    r&   r$   s     r(   r    zLazyBinaryProxy.__init__  s    r)   c                ,    t        | j                        S rV   )rf   r&   rH   s    r(   __load__zLazyBinaryProxy.__load__  s    t{{##r)   r   )r+   Node)r.   r/   r0   rz   r    r   r   r1   r2   s   @r(   r   r     s!    N $ $r)   r   r   r   )r&   r#   r+   r   )r=   rM   r?   r   r   r*   r+   zdict[str, str])r&   r#   r+   rK   )r&   r#   rX   r   r+   rJ   )r&   r#   rX   r   r+   ztuple[int, ...] | None)<
__future__r   r   rerp   r   loggingr_   abcr   r   typingr   r   r   r	   r
   pathlibr   typing_extensionsr   r   r   r   _proxyr   errorsr   _compatr   r   binariesr   	getLoggerr.   r   rz   r   Filer#   r   r   compiler   r   r4   r7   rR   r}   r   rf   pathseprA   rc   r   r   r   __as_proxied__r   r   rF   r)   r(   <module>r      sd   " 	 	 
    # 0 0  /     & 'g''1^ 1S"S'\		    RZZ./
t t
K 
3s 3lj4 j4Z4+8 4+n !#556
." zz	!	!! ! 
	!
 !<4!H*	$io 	$ e++-v--/r)   