o
    $¼"b´  ã                   @   sÂ   d dl mZmZ d dlZd dlZd dl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ejƒG dd„ dee	ƒƒZdd„ ZdS )é    )Úabsolute_importÚunicode_literalsN)Úadd_metaclass)ÚPython2Supports)ÚPathRefToDest)Ú	IS_ZIPAPP)ÚPath)Úensure_text)Úreadé   )ÚViaGlobalRefVirtualenvBuiltinc                       s„   e Zd Z‡ fdd„Zedd„ ƒZedd„ ƒZe‡ f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‡  ZS )ÚPython2c                    sî   t t| ƒ ¡  t| jjƒ}|d  ¡ s|d  ¡ r| jn| j}|d ‰ t	ƒ }t
r-t|ƒ}n| ¡ }t ‡ fdd„| jD ƒ¡}| d|¡}tj dd„ | j ¡ D ƒ¡ ¡ }| d|¡}tj d	d„ | j ¡ D ƒ¡ ¡ }| d
|¡}ˆ  |¡ dS )zJPerform operations needed to make the created environment work on Python 2úsite.pyzsite.pycc                    s*   g | ]}t j tt|ƒƒttˆ ƒƒ¡‘qS © )ÚosÚpathÚrelpathr	   Ústr©Ú.0Úi©Úsite_pyr   úZ/usr/lib/python3/dist-packages/virtualenv/create/via_global_ref/builtin/python2/python2.pyÚ
<listcomp>)   s   * z"Python2.create.<locals>.<listcomp>Ú___EXPECTED_SITE_PACKAGES___c                 s   ó   � | ]}d   |¡V  qdS )z    {}N©Úformatr   r   r   r   Ú	<genexpr>-   ó   € z!Python2.create.<locals>.<genexpr>z# ___RELOAD_CODE___c                 s   r   )z            {}Nr   r   r   r   r   r   0   r    z# ___SKIP_REWRITE____N)Úsuperr   Úcreater   ÚinterpreterÚsystem_stdlib_platformÚexistsÚstdlib_platformÚstdlibÚget_custom_siter   Úread_from_zipappÚ	read_textÚjsonÚdumpsÚlibsÚreplacer   ÚlinesepÚjoinÚreload_codeÚ
splitlinesÚlstripÚskip_rewriteÚ
write_text)ÚselfÚsys_std_platÚ
site_py_inÚcustom_siteÚcustom_site_textÚexpectedr1   r4   ©Ú	__class__r   r   r"      s(   
ÿ
ÿý
  zPython2.createc                 C   ó   dS )NzSreload(sys.modules["site"])  # noqa # call system site.py to setup import librariesr   ©r6   r   r   r   r1   5   ó   zPython2.reload_codec                 C   r>   )NÚ r   r?   r   r   r   r4   9   r@   zPython2.skip_rewritec                 #   s    � t t| ƒ |¡D ]}|V  q	|  |¡|  ¡ }}|  ¡ D ]0}|  |d |¡¡\}}}|  |d |¡¡\}	}
}|s=|s=|sDt||d�V  |rMt|	|
d�V  qd S )Nz{}.pyz{}.pyc)Údest)	r!   r   ÚsourcesÚmappingsÚneeds_stdlib_py_moduleÚmodulesÚfrom_stdlibr   r   )Úclsr#   ÚsrcrD   Úneeds_py_moduleÚreqÚmodule_fileÚ	to_moduleÚmodule_existsÚcompiled_fileÚto_compiledÚcompiled_existsr<   r   r   rC   =   s   €þ€úzPython2.sourcesc                 C   sJ   | D ]\}}|| }|  ¡ r||df  S q| d d | | d d dfS )NTr   é   F)r%   )rD   ÚnameÚfrom_stdÚto_stdrI   r   r   r   rG   O   s   ÿzPython2.from_stdlibc                 C   s8   t |jƒ| jfg}|j|jkr| t |jƒ| jf¡ |S ©N)r   r$   Úto_stdlib_platformÚsystem_stdlibÚappendÚ	to_stdlib)rH   r#   rD   r   r   r   rD   X   s   zPython2.mappingsc                 C   ó   | j |j S rV   )r'   rS   ©r6   rI   r   r   r   rZ   _   ó   zPython2.to_stdlibc                 C   r[   rV   )r&   rS   r\   r   r   r   rW   b   r]   zPython2.to_stdlib_platformc                 C   s   t ‚rV   )ÚNotImplementedError©rH   r   r   r   rE   e   r@   zPython2.needs_stdlib_py_modulec                 C   s   g S rV   r   r_   r   r   r   rF   i   r@   zPython2.modules)Ú__name__Ú
__module__Ú__qualname__r"   Úpropertyr1   r4   ÚclassmethodrC   ÚstaticmethodrG   rD   rZ   rW   rE   rF   Ú__classcell__r   r   r<   r   r      s$    




r   c                   C   s   t d S )Nr   )ÚHEREr   r   r   r   r(   n   s   r(   )Ú
__future__r   r   Úabcr+   r   Úsixr   Úvirtualenv.create.describer   Ú,virtualenv.create.via_global_ref.builtin.refr   Úvirtualenv.infor   Úvirtualenv.util.pathr   Úvirtualenv.util.sixr	   Úvirtualenv.util.zipappr
   r)   Úvia_global_self_dor   r   ÚabspathÚ__file__Úparentrg   ÚABCMetar   r(   r   r   r   r   Ú<module>   s     X