3
W>p_                  @   s*  d dl mZmZm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mZ d dlmZmZ d dlm Z  d dl!m"Z" ddl#m$Z$ eej%j&e'j(Z)e)d Z*G dd de+Z,ee	G dd de+Z-dd Z.dS )    )absolute_importprint_functionunicode_literalsN)ABCMetaabstractmethod)ArgumentTypeError)literal_eval)OrderedDict)dedent)add_metaclass)LogCmd)WIN_CPYTHON_2)Pathsafe_delete)
ensure_strensure_text)run_cmd)__version__   )PyEnvCfgzdebug.pyc               @   s   e Zd Zdd ZdS )CreatorMetac             C   s
   d | _ d S )N)error)self r   /home/aldo/Documentos/tesis/tesis/device auto/pruebas pulsar/pruebaclonado/envClonado/lib/python3.6/site-packages/virtualenv/create/creator.py__init__   s    zCreatorMeta.__init__N)__name__
__module____qualname__r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdd Z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edd Zdd ZdS )CreatorzEA class that given a python Interpreter creates a virtual environmentc             C   s:   || _ d| _t|j| _|j| _tj| j| _|j| _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)	interpreter_debugr   destclearr   Zfrom_folder	pyenv_cfgapp_data)r   optionsr    r   r   r   r   %   s    zCreator.__init__c             C   s   t | j S )N)r   __unicode__)r   r   r   r   __repr__2   s    zCreator.__repr__c             C   s$   dj | jjdjdd | j D S )Nz{}({})z, c             s   s   | ]\}}d j ||V  qdS )z{}={}N)format).0kvr   r   r   	<genexpr>6   s    z&Creator.__unicode__.<locals>.<genexpr>)r)   	__class__r   join_args)r   r   r   r   r'   5   s    zCreator.__unicode__c             C   s   dt t| jfd| jfgS )Nr"   r#   )r   strr"   r#   )r   r   r   r   r0   8   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	 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"   actionr4   defaultN)add_argumentvalidate_dest)r2   parserr    metar%   r   r   r   add_parser_argumentsH   s    	zCreator.add_parser_argumentsc             C   s   t dS )z)Perform the virtual environment creation.N)NotImplementedError)r   r   r   r   create\   s    zCreator.createc             C   s  dd }t j }t }|dkr&ddini }xXt|D ]L}y*|j|f|j|}||krXw4t|W q4 tk
r~   d||< Y q4X q4W |rtdj|dj	|j
 |tj|krtd	j|tjt|}|j r|j rtd
j|dt j  k odkn  rttjj|}	nttjjt|j }	|	}xb|	r|	j rjtjtt|	tjr`P n
||	| |	j|	j }
}|
|	kr||	| |
}	q4W t|S )zANo path separator in the path, valid chars and must be write-ablec             S   s2   t tjj|j| jg }tdj| j||d S )Nz*the destination {} is not write-able at {})r   ospathcommonprefixpartsr   r)   relative_to)r"   valuecommonr   r   r   non_write_ablee   s    z-Creator.validate_dest.<locals>.non_write_ablembcserrorsignoreNzDthe file system codec ({}) cannot handle characters {!r} within {!r} zddestination {!r} must not contain the path separator ({}) as this would break the activation scriptsz/the destination {} already exists and is a file      )rL   rL   )rL   rM   )sysgetfilesystemencodingr	   r   encodedecode
ValueErrorr   r)   r/   keysr@   pathsepr   existsis_fileversion_inforA   realpathabspathr1   resolveaccessW_OKparentname)r2   Z	raw_valuerG   encodingZrefusedkwargscharZtriprE   r"   base_r   r   r   r:   a   sJ    





zCreator.validate_destc             C   sD   | j j r(| jr(tjd| j  t| j  | j  | j  | j  d S )Nz	delete %s)	r"   rU   r#   loggingdebugr   r?   set_pyenv_cfgsetup_ignore_vcs)r   r   r   r   run   s    
zCreator.runc             C   sR   t  | j_| jj| jd< | jj| jd< djdd | jjD | jd< t| jd< d S )Nhomeimplementation.c             s   s   | ]}t |V  qd S )N)r1   )r*   ir   r   r   r-      s    z(Creator.set_pyenv_cfg.<locals>.<genexpr>rW   
virtualenv)	r	   r$   contentr    Zsystem_exec_prefixrj   r/   rW   r   )r   r   r   r   rf      s
    
zCreator.set_pyenv_cfgc             C   s(   | j d }|j s$|jtdj  dS )z9Generate ignore instructions for version control systems.z
.gitignoreze
                    # created by virtualenv automatically
                    *
                    N)r"   rU   Z
write_textr
   lstrip)r   Z
git_ignorer   r   r   rg      s
    
zCreator.setup_ignore_vcsc             C   s0   | j dkr*| jdk	r*t| j| j | j| _ | j S )zt
        :return: debug information about the virtual environment (only valid after :meth:`create` has run)
        N)r!   Zexeget_env_debug_infodebug_scriptr%   )r   r   r   r   re      s    zCreator.debugc             C   s   t S )N)DEBUG_SCRIPT)r   r   r   r   rq      s    zCreator.debug_scriptN)r   r   r   __doc__r   r(   r'   r0   classmethodr3   r=   r   r?   r:   rh   rf   rg   propertyre   rq   r   r   r   r   r   !   s   
8
r   c       
      C   s   t jj }|jtdd  |j|J}t| t|g}trHdd |D }tjtdt	| t
|\}}}W d Q R X y,|dkrt|}n
tj|}|r||d< W n. tk
r }	 z|||t|	dS d }	~	X nX d|krd	|d kr|d d	 d= |S )
N
PYTHONPATHc             S   s   g | ]}t |qS r   )r   )r*   rl   r   r   r   
<listcomp>   s    z&get_env_debug_info.<locals>.<listcomp>zdebug via %rr   err)outrx   
returncode	exceptionrN   rA   )r@   environcopypopr1   Zensure_extractedr   rd   re   r   r   r   jsonloads	Exceptionrepr)
Zenv_exerq   r%   envcmdcodery   rx   resultr{   r   r   r   rp      s&    


rp   )/
__future__r   r   r   r   rd   r@   rN   abcr   r   argparser   astr   collectionsr	   textwrapr
   sixr   Z#virtualenv.discovery.cached_py_infor   Zvirtualenv.infor   Zvirtualenv.util.pathr   r   Zvirtualenv.util.sixr   r   Zvirtualenv.util.subprocessr   Zvirtualenv.versionr   r$   r   rA   rY   __file__r]   ZHERErr   objectr   r   rp   r   r   r   r   <module>   s0    (