
    3i*                       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mZm	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r 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 d dlm Z m!Z! d dl"m#Z# ddl$m%Z%  eejL                  jO                  e(            jR                  Z*e*dz  Z+ ejX                  e-      Z. G d d      Z/ G d de      Z0ddZ1ddgZ2y)    )annotationsN)ABCabstractmethod)ArgumentTypeError)literal_eval)OrderedDict)Path)TYPE_CHECKING)ArgumentParser)AnyNoReturn)
PythonInfo)AppData)VirtualEnvOptions)safe_delete)LogCmdrun_cmd)__version__   )PyEnvCfgzdebug.pyc                      e Zd ZddZy)CreatorMetac                    d | _         y N)errorselfs    L/var/www/opsc/venv/lib/python3.12/site-packages/virtualenv/create/creator.py__init__zCreatorMeta.__init__$   s	    
    NreturnNone)__name__
__module____qualname__r    r    r   r   r   #   s    r    r   c                  J   e Zd ZdZddZer?edd       Zedd       Zedd       Z	edd       Z
edd       Zedd       Zedd	       Zdd
ZddZedd       Ze	 	 	 	 	 	 	 	 	 	 dd       Zedd       Zedd       ZddZddZddZddZed d       Zedd       Zy)!CreatorzFA class that given a python Interpreter creates a virtual environment.c                H   || _         d| _        t        |j                        | _        |j                  | _        |j
                  | _        t        j                  | j                        | _        |j                  | _	        |j                  | _
        t        |dd      | _        y)zConstruct a new virtual environment creator.

        :param options: the CLI option as parsed from :meth:`add_parser_arguments`
        :param interpreter: the interpreter to create virtual environment from

        Nprompt)interpreter_debugr	   destclearno_vcs_ignorer   from_folder	pyenv_cfgapp_dataenvgetattrr+   )r   optionsr,   s      r   r   zCreator.__init__+   sz     '&	]]
$22!--dii8((;;gx6r    c                     y r   r'   r   s    r   exezCreator.exe>   s    "r    c                     y r   r'   r   s    r   env_namezCreator.env_nameA       #&r    c                     y r   r'   r   s    r   bin_dirzCreator.bin_dirD   r;   r    c                     y r   r'   r   s    r   
script_dirzCreator.script_dirG       &)r    c                     y r   r'   r   s    r   libszCreator.libsJ   r@   r    c                     y r   r'   r   s    r   purelibzCreator.purelibM   r;   r    c                     y r   r'   r   s    r   platlibzCreator.platlibP   r;   r    c                    | j                   j                   ddj                  d | j                         D               dS )N(z, c              3  0   K   | ]  \  }}| d |   yw)=Nr'   ).0kvs      r   	<genexpr>z#Creator.__repr__.<locals>.<genexpr>T   s     5ZTQ1QCj5Zs   ))	__class__r$   join_argsr   s    r   __repr__zCreator.__repr__S   s7    ..))*!DII5ZTZZ\5Z,Z+[[\]]r    c                f    dt        | j                        fd| j                  fd| j                  fgS )Nr.   r/   r0   )strr.   r/   r0   r   s    r   rR   zCreator._argsV   s6    S^$djj!d001
 	
r    c                     y)a  Determine if we can create a virtual environment.

        :param interpreter: the interpreter in question

        :returns: ``None`` if we can't create, any other object otherwise that will be forwarded to
            :meth:`add_parser_arguments`

        Tr'   )clsr,   s     r   
can_createzCreator.can_create]   s     r    c                    |j                  dd| j                         |j                  ddddd	       |j                  d
dddd	       y)a  Add CLI arguments for the creator.

        :param parser: the CLI parser
        :param app_data: the application data folder
        :param interpreter: the interpreter we're asked to create virtual environment for
        :param meta: value as returned by :meth:`can_create`

        r.   z!directory to create virtualenv at)helptypez--clearr/   
store_truezZremove the destination directory if exist before starting (will overwrite files otherwise)F)r.   actionrZ   defaultz--no-vcs-ignorer0   z>don't create VCS ignore directive in the destination directoryN)add_argumentvalidate_dest)rW   parserr,   metar3   s        r   add_parser_argumentszCreator.add_parser_argumentsi   sn      	4"" 	 	

 	m 	 	
 	 Q 	 	
r    c                    t         )z)Perform the virtual environment creation.)NotImplementedErrorr   s    r   createzCreator.create   s
     "!r    c                   dd}t        j                         }t               }|dk7  rddini }t        |      D ]5  }	  |j                  |fi |j                  |      }||k(  r,t        |       |r5dj                  |j                               }d| d|d	|}	t        |	      t        j                  |v r"d
|dt        j                   d}	t        |	      t        |      }
|
j                         r!|
j                         rd|
 d}	t        |	      t        t        j                  j!                  t        |
                  j#                         }|}
|r}|j                         rBt        j$                  t        |      t        j&                        r	 t        |
      S  |||
       |j(                  |j*                  }}||k(  r	 |||
       |}|r}t        |
      S # t        $ r	 d||<   Y w xY w)zBNo path separator in the path, valid chars and must be write-able.c                    t        t        j                  j                  |j                  | j                  g       }d| j                  |       d| }t        |      )Nthe destination z is not write-able at )r	   ospathcommonprefixpartsrelative_tor   )r.   valuecommonmsgs       r   non_write_ablez-Creator.validate_dest.<locals>.non_write_able   sT    277//djj0IJKF$T%5%5f%=$>>TU[T\]C#C((r    mbcserrorsignoreN zthe file system codec (z) cannot handle characters z within zdestination z& must not contain the path separator (z,) as this would break the activation scriptsri   z already exists and is a file)r.   r	   ro   r	   r"   r   )sysgetfilesystemencodingr   rU   encodedecode
ValueErrorrQ   keysr   rj   pathsepr	   existsis_filerk   abspathresolveaccessW_OKparentname)rW   	raw_valuerr   encodingrefusedkwargschartripbadrq   ro   r.   base_s                 r   r`   zCreator.validate_dest   s   	) ,,.-)1V);(H%	N 	%D%"t{{86v6==hG4< &&	% ''',,.)C+H:5PQTPWW_`i_lmC#C((::"ym+QRTR\R\Q] ^> ?  $C((Y<<>emmo$UG+HIC#C((BGGOOCJ/088:{{}99SY0 5z tU+kk499!Dt|tU+D  5z9  % $%s   'G#%G##G54G5c                T   | j                   j                         rA| j                  r5t        j	                  d| j                          t        | j                          | j                          | j                          | j                          | j                  s| j                          y y )Nz	delete %s)r.   r~   r/   LOGGERdebugr   rf   add_cachedir_tagset_pyenv_cfgr0   setup_ignore_vcsr   s    r   runzCreator.run   sq    99$**LLdii0		"!!!!# "r    c                    | j                   dz  }|j                         s7t        j                  d      j	                         }|j                  |d       yy)zBGenerate a file indicating that this is not meant to be backed up.zCACHEDIR.TAGa  
                Signature: 8a477f597d28d172789f06886806bc55
                # This file is a cache directory tag created by Python virtualenv.
                # For information about cache directory tags, see:
                #   https://bford.info/cachedir/
            utf-8r   N)r.   r~   textwrapdedentstrip
write_text)r   cachedir_tag_filecachedir_tag_texts      r   r   zCreator.add_cachedir_tag   sW     II6 '') ( 1 !
   (():W(M *r    c                   t               | j                  _        | j                  j                  xs | j                  j
                  }|J t        j                  j                  t        j                  j                  |            | j                  d<   | j                  j                  | j                  d<   dj                  d | j                  j                  D              | j                  d<   dj                  d | j                  j                  d d D              | j                  d<   t        j                  j                  |      | j                  d	<   t        j
                   d
| j                   | j                  d<   t         | j                  d<   | j"                  \| j"                  dk(  r1t        j                  j%                  t        j&                               n| j"                  }|| j                  d<   y y )Nhomeimplementation.c              3  2   K   | ]  }t        |        y wr   rU   rK   is     r   rN   z(Creator.set_pyenv_cfg.<locals>.<genexpr>   s     1`Q#a&1`   version_infoc              3  2   K   | ]  }t        |        y wr   r   r   s     r   rN   z(Creator.set_pyenv_cfg.<locals>.<genexpr>   s     ,_SV,_r      version
executablez -m virtualenv command
virtualenvr+   )r   r2   contentr,   system_executabler   rj   rk   dirnamer   r   rQ   r   realpathrw   r.   r   r+   basenamegetcwd)r   r   prompt_values      r   r   zCreator.set_pyenv_cfg   sw   !, ,,>>]$BRBRB]B] ,,,!#AR1S!Tv+/+;+;+J+J'(),1`$BRBRB_B_1`)`~&$'HH,_T=M=M=Z=Z[]\]=^,_$_y!')ww'7'78I'J|$'*~~&6odii[$Qy!'2|$;;"<@KK3<N277++BIIK8TXT_T_L'3DNN8$ #r    c                j    | j                   dz  }|j                         s|j                  dd       yy)z9Generate ignore instructions for version control systems.z
.gitignorez(# created by virtualenv automatically
*
r   r   N)r.   r~   r   )r   
git_ignores     r   r   zCreator.setup_ignore_vcs   s8     YY-
  "!!"NY`!a #r    c                    | j                   K| j                  ?t        | j                  | j                         | j                  | j
                        | _         | j                   S )zc:returns: debug information about the virtual environment (only valid after :meth:`create` has run))r-   r8   get_env_debug_infodebug_scriptr3   r4   r   s    r   r   zCreator.debug   sK     ;;488#7,TXXt7H7H7JDMM[_[c[cdDK{{r    c                     t         S r   )DEBUG_SCRIPTr'   r    r   r   zCreator.debug_script   s    r    N)r6   r   r,   r   r"   r#   )r"   r	   )r"   rU   )r"   z
list[Path])r"   zlist[tuple[str, Any]])r,   r   r"   zCreatorMeta | None)
ra   r   r,   r   rb   r   r3   r   r"   r#   r!   )r   rU   r"   rU   )r"   zdict[str, Any] | None)r$   r%   r&   __doc__r   r
   propertyr8   r:   r=   r?   rB   rD   rF   rS   rR   classmethodrX   rc   r   rf   r`   r   r   r   r   r   staticmethodr   r'   r    r   r)   r)   (   s<   P7" 	" 
"	& 
&	& 
&	) 
)	) 
)	& 
&	& 
&^
 	 	 !
!
  !
 	!

 !
 
!
 !
F " " / /b$
N4b    r    r)   c                0   |j                         }|j                  dd        |j                  |      5 }t        |       t        |      g}t        j                  dt        |             t        |      \  }}}d d d        	 dk7  r-rt        |      }	n4|dk(  rdv rt        |      t              t        j                        }	r||	d<   d|	v rd	|	d   v r	|	d   d	   d= |	S # 1 sw Y   nxY w# t        $ r}
t        |
      dcY d }
~
S d }
~
ww xY w)
N
PYTHONPATHzdebug via %rr      fileerr)outr   
returncode	exceptionrw   rk   )copypopensure_extractedrU   r   r   r   r   r   OSError	Exceptionjsonloadsrepr)env_exer   r3   r4   debug_script_extractedcmdcoder   r   resultr   s              r   r   r     s   
((*CGGL$		"	"<	0 &4J7|S!789^VC[1 c3&
Z19%c*193!#,&n$ZZ_FF5M 6VE]25M&!!$M-& &$  Z3diYYZs+   AC&AC2 &C/2	D;D
DD)
r   r	   r   r	   r3   r   r4   zdict[str, str]r"   zdict[str, Any])3
__future__r   r   loggingrj   rw   r   abcr   r   argparser   astr   collectionsr   pathlibr	   typingr
   r   r   r   python_discoveryr   virtualenv.app_data.baser   virtualenv.config.cli.parserr   virtualenv.util.pathr   virtualenv.util.subprocessr   r   virtualenv.versionr   r2   r   rk   r   __file__r   HEREr   	getLoggerr$   r   r   r)   r   __all__r'   r    r   <module>r      s    "   	 
  # &  #   '$+0> , 6 * BGGOOH%&--j 			8	$ 
Vc Vr< r    