o
    Wi*                     @  sP  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rbd 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j&'e(j)Z*e*d Z+e,e-Z.G dd dZ/G dd deZ0d#d!d"Z1ddgZ2dS )$    )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                   @  s   e Zd ZdddZdS )CreatorMetareturnNonec                 C  s
   d | _ d S N)errorself r   M/home/ubuntu/.local/lib/python3.10/site-packages/virtualenv/create/creator.py__init__$   s   
zCreatorMeta.__init__Nr   r   )__name__
__module____qualname__r   r   r   r   r   r   #   s    r   c                   @  s  e Zd ZdZd>dd	Zer>ed?ddZed@ddZed?ddZ	ed?ddZ
edAddZed?ddZed?ddZd@ddZdBddZedCd!d"ZedDd)d*ZedEd+d,ZedFd.d/ZdEd0d1ZdEd2d3ZdEd4d5ZdEd6d7ZedGd9d:Zed?d;d<Zd=S )HCreatorzFA class that given a python Interpreter creates a virtual environment.optionsr   interpreterr   r   r   c                 C  sX   || _ d| _t|j| _|j| _|j| _t| j| _|j	| _	|j
| _
t|dd| _dS )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)r&   _debugr   destclearno_vcs_ignorer   from_folder	pyenv_cfgapp_dataenvgetattrr'   )r   r%   r&   r   r   r   r   +   s   zCreator.__init__r   c                 C     d S r   r   r   r   r   r   exe>      zCreator.exestrc                 C  r1   r   r   r   r   r   r   env_nameA   r3   zCreator.env_namec                 C  r1   r   r   r   r   r   r   bin_dirD   r3   zCreator.bin_dirc                 C  r1   r   r   r   r   r   r   
script_dirG   r3   zCreator.script_dir
list[Path]c                 C  r1   r   r   r   r   r   r   libsJ   r3   zCreator.libsc                 C  r1   r   r   r   r   r   r   purelibM   r3   zCreator.purelibc                 C  r1   r   r   r   r   r   r   platlibP   r3   zCreator.platlibc                 C  s(   | j j dddd |  D  dS )N(z, c                 s  s"    | ]\}}| d | V  qdS )=Nr   ).0kvr   r   r   	<genexpr>T   s     z#Creator.__repr__.<locals>.<genexpr>))	__class__r!   join_argsr   r   r   r   __repr__S   s   (zCreator.__repr__list[tuple[str, Any]]c                 C  s    dt | jfd| jfd| jfgS )Nr)   r*   r+   )r4   r)   r*   r+   r   r   r   r   rE   V   s   zCreator._argsCreatorMeta | Nonec                 C  s   dS )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&   r   r   r   
can_create]   s   
zCreator.can_createparserr
   metar   r.   r   c                 C  s>   |j dd| jd |j dddddd	 |j d
ddddd	 dS )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)   actionrM   defaultz--no-vcs-ignorer+   z>don't create VCS ignore directive in the destination directoryN)add_argumentvalidate_dest)rI   rK   r&   rL   r.   r   r   r   add_parser_argumentsi   s&   
zCreator.add_parser_argumentsc                 C  s   t )z)Perform the virtual environment creation.)NotImplementedErrorr   r   r   r   create   s   zCreator.create	raw_valuec              	   C  s  ddd}t  }t }|dkrd	d
ini }t|D ]%}z|j|fi ||}||kr/W qt| ty?   d||< Y qw |rXd| }d| d|d|}	t	|	t
j|v rkd|dt
j d}	t	|	t|}
|
 r|
 rd|
 d}	t	|	tt
jt|
 }|}
|r| rt
t|t
jr	 t|
S |||
 |j|j}}||kr|||
 |}|st|
S )zBNo path separator in the path, valid chars and must be write-able.r)   r   valuer   r   c                 S  s6   t tj|j| jg }d| | d| }t|)Nthe destination z is not write-able at )r   ospathcommonprefixpartsrelative_tor   )r)   rX   commonmsgr   r   r   non_write_able   s   z-Creator.validate_dest.<locals>.non_write_able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 scriptsrY   z already exists and is a file)r)   r   rX   r   r   r   )sysgetfilesystemencodingr   r4   encodedecode
ValueErrorrD   keysr   rZ   pathsepr   existsis_filer[   abspathresolveaccessW_OKparentname)rI   rW   ra   encodingrefusedkwargschartripbadr`   rX   r)   base_r   r   r   rS      sN   



	zCreator.validate_destc                 C  sV   | j  r| jrtd| j  t| j  |   |   |   | j	s)| 
  d S d S )Nz	delete %s)r)   rm   r*   LOGGERdebugr   rV   add_cachedir_tagset_pyenv_cfgr+   setup_ignore_vcsr   r   r   r   run   s   
zCreator.runc                 C  s6   | j d }| std }|j|dd dS dS )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ru   N)r)   rm   textwrapdedentstrip
write_text)r   cachedir_tag_filecachedir_tag_textr   r   r   r      s   
zCreator.add_cachedir_tagc                 C  s  t  | j_| jjp| jj}|d usJ tjtj	|| jd< | jj
| jd< ddd | jjD | jd< ddd | jjd d D | jd	< tj|| jd
< tj d| j | jd< t| jd< | jd ur| jdkrutjt n| j}|| jd< d S d S )Nhomeimplementation.c                 s      | ]}t |V  qd S r   r4   r>   ir   r   r   rA          z(Creator.set_pyenv_cfg.<locals>.<genexpr>version_infoc                 s  r   r   r   r   r   r   r   rA      r      version
executablez -m virtualenv command
virtualenvr'   )r   r-   contentr&   system_executabler   rZ   r[   dirnamero   r   rD   r   realpathrf   r)   r   r'   basenamegetcwd)r   r   prompt_valuer   r   r   r      s   
&

 zCreator.set_pyenv_cfgc                 C  s(   | j d }| s|jddd dS dS )z9Generate ignore instructions for version control systems.z
.gitignorez(# created by virtualenv automatically
*
r   r   N)r)   rm   r   )r   
git_ignorer   r   r   r      s   
zCreator.setup_ignore_vcsdict[str, Any] | Nonec                 C  s4   | j du r| jdurt| j|  | j| j| _ | j S )zc:returns: debug information about the virtual environment (only valid after :meth:`create` has run)N)r(   r2   get_env_debug_infodebug_scriptr.   r/   r   r   r   r   r~      s   zCreator.debugc                   C  s   t S r   )DEBUG_SCRIPTr   r   r   r   r      s   zCreator.debug_scriptN)r%   r   r&   r   r   r   )r   r   )r   r4   )r   r8   )r   rG   )r&   r   r   rH   )
rK   r
   r&   r   rL   r   r.   r   r   r   r    )rW   r4   r   r4   )r   r   )r!   r"   r#   __doc__r   r	   propertyr2   r5   r6   r7   r9   r:   r;   rF   rE   classmethodrJ   rT   r   rV   rS   r   r   r   r   r~   staticmethodr   r   r   r   r   r$   (   sH    


#
1



r$   env_exer   r   r.   r   r/   dict[str, str]r   dict[str, Any]c              
   C  s  |  }|dd  ||}t| t|g}tdt| t|\}}}W d    n1 s1w   Y  z(|dkrR|rBt|}	n|dkrNd|v rNt	|t
|t|}	|r]||	d< W n t
yy }
 z|||t|
dW  Y d }
~
S d }
~
ww d|	v rd	|	d v r|	d d	 d= |	S )
N
PYTHONPATHzdebug via %rr      fileerr)outr   
returncode	exceptionrf   r[   )copypopensure_extractedr4   r}   r~   r   r   r   OSError	Exceptionjsonloadsrepr)r   r   r.   r/   debug_script_extractedcmdcoder   r   resultr   r   r   r   r     s2   

r   )
r   r   r   r   r.   r   r/   r   r   r   )3
__future__r   r   loggingrZ   rf   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   r-   r   r[   ro   __file__rs   HEREr   	getLoggerr!   r}   r   r$   r   __all__r   r   r   r   <module>   s@    
 
Z