o
    Uh#                     @  s  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 d d	lmZ d d
l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Z&dd Z'ddgZ(dS )    )annotationsN)ABCabstractmethod)ArgumentTypeError)literal_eval)OrderedDict)Path)LogCmd)safe_delete)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/var/www/html/construction_image-detection-poc/venv/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d!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dS )"CreatorzFA class that given a python Interpreter creates a virtual environment.r   r   c                 C  sJ   || _ d| _t|j| _|j| _|j| _t| j| _|j	| _	|j
| _
dS )z
        Construct 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)interpreter_debugr   destclearno_vcs_ignorer   from_folder	pyenv_cfgapp_dataenv)r   optionsr   r   r   r   r   "   s   zCreator.__init__strc                 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>3   s     z#Creator.__repr__.<locals>.<genexpr>))	__class__r   join_argsr   r   r   r   __repr__2   s   (zCreator.__repr__c                 C  s    dt | jfd| jfd| jfgS )Nr    r!   r"   )r(   r    r!   r"   r   r   r   r   r2   5   s   zCreator._argsc                 C  s   dS )a  
        Determine if we can create a virtual environment.

        :param interpreter: the interpreter in question
        :return: ``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_createc                 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    actionr6   defaultz--no-vcs-ignorer"   z>don't create VCS ignore directive in the destination directoryN)add_argumentvalidate_dest)r4   parserr   metar%   r   r   r   add_parser_argumentsG   s&   

zCreator.add_parser_argumentsc                 C  s   t )z)Perform the virtual environment creation.)NotImplementedErrorr   r   r   r   createe   s   zCreator.createc              	   C  s~  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 |rWd| }d| d	|d
|}	t	|	t
j|v rjd|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.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    valuecommonmsgr   r   r   non_write_ablen   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 scriptsrB   z already exists and is a file)sysgetfilesystemencodingr   r(   encodedecode
ValueErrorr1   keysr   rC   pathsepr   existsis_filerD   abspathresolveaccessW_OKparentname)r4   	raw_valuerK   encodingrefusedkwargschartripbadrJ   rH   r    base_r   r   r   r<   j   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    rW   r!   LOGGERdebugr
   rA   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r`   N)r    rW   textwrapdedentstrip
write_text)r   cachedir_tag_filecachedir_tag_textr   r   r   rj      s   
zCreator.add_cachedir_tagc                 C  sb   t  | j_tjtj| jj| jd< | jj	| jd< d
dd | jjD | jd< t| jd< d S )Nhomeimplementation.c                 s  s    | ]}t |V  qd S r   )r(   )r+   ir   r   r   r.      s    z(Creator.set_pyenv_cfg.<locals>.<genexpr>version_info
virtualenv)r   r$   contentrC   rD   dirnamerY   r   system_executablerw   r1   rz   r   r   r   r   r   rk      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
*
rn   ro   N)r    rW   rs   )r   
git_ignorer   r   r   rl      s   
zCreator.setup_ignore_vcsc                 C  s4   | j du r| jdurt| j|  | j| j| _ | j S )zb:return: debug information about the virtual environment (only valid after :meth:`create` has run)N)r   exeget_env_debug_infodebug_scriptr%   r&   r   r   r   r   ri      s   zCreator.debugc                   C  s   t S r   )DEBUG_SCRIPTr   r   r   r   r      s   zCreator.debug_scriptNr   )r   r(   )r   r   r   __doc__r   r3   r2   classmethodr5   r?   r   rA   r<   rm   rj   rk   rl   propertyri   staticmethodr   r   r   r   r   r      s*    






1

r   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	exceptionrP   rD   )copypopensure_extractedr(   rh   ri   r	   r   r   OSError	Exceptionjsonloadsrepr)env_exer   r%   r&   debug_script_extractedcmdcoder   r   resultr   r   r   r   r      s2   

r   ))
__future__r   r   loggingrC   rP   rp   abcr   r   argparser   astr   collectionsr   pathlibr   #virtualenv.discovery.cached_py_infor	   virtualenv.util.pathr
   virtualenv.util.subprocessr   virtualenv.versionr   r$   r   rD   rY   __file__r]   HEREr   	getLoggerr   rh   r   r   r   __all__r   r   r   r   <module>   s4    
 3