o
    $¼"b  ã                   @   s˜   d dl mZm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mZ G d
d„ deƒZeeƒG dd„ deƒƒZdS )é    )Úabsolute_importÚunicode_literalsN)ÚABCMeta)Úadd_metaclass)Úfs_supports_symlink)ÚPath)Úensure_texté   )ÚCreatorÚCreatorMetac                       s4   e Zd Z‡ fdd„Zedd„ ƒZedd„ ƒZ‡  ZS )ÚViaGlobalRefMetac                    s.   t t| ƒ ¡  d | _d | _tƒ sd| _d S d S )Nz(the filesystem does not supports symlink)Úsuperr   Ú__init__Ú
copy_errorÚsymlink_errorr   ©Úself©Ú	__class__© úF/usr/lib/python3/dist-packages/virtualenv/create/via_global_ref/api.pyr      s   
ÿzViaGlobalRefMeta.__init__c                 C   ó   | j  S ©N)r   r   r   r   r   Úcan_copy   ó   zViaGlobalRefMeta.can_copyc                 C   r   r   )r   r   r   r   r   Úcan_symlink   r   zViaGlobalRefMeta.can_symlink)Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   r   Ú__classcell__r   r   r   r   r      s    
r   c                       sh   e Zd Z‡ fdd„Zedd„ ƒZe‡ fdd„ƒZdd„ Zd	d
„ Z	dd„ Z
‡ fdd„Z‡ fdd„Z‡  ZS )ÚViaGlobalRefApic                    s*   t t| ƒ ||¡ |  |¡| _|j| _d S r   )r   r!   r   Ú_should_symlinkÚsymlinksÚsystem_siteÚenable_system_site_package)r   ÚoptionsÚinterpreterr   r   r   r   #   s   zViaGlobalRefApi.__init__c                 C   s�   t | ddƒt | ddƒ}}|  d¡|  d¡}}dD ]+}||kr"|nd }||kr*|nd }|du r7|du r7 dS |du r> dS |du rE dS qdS )NÚcopiesFr#   )Úclizenv varÚfileÚdefaultT)ÚgetattrÚ
get_source)r&   r(   r#   Úcopy_srcÚsym_srcÚlevelÚs_optÚc_optr   r   r   r"   (   s   ÿzViaGlobalRefApi._should_symlinkc                    sˆ   t t| ƒ ||||¡ |jdddddd� | ¡ }|js#|js#tdƒ‚|jr0|jdd	dd
dd� |jrB|jdd|j dddd� d S d S )Nz--system-site-packagesFÚ
store_truer$   zCgive the virtual environment access to the system site-packages dir)r+   ÚactionÚdestÚhelpz(neither symlink or copy method supportedz
--symlinksTr#   zZtry to use symlinks rather than copies, when symlinks are not the default for the platformz--copiesz--always-copyr(   z[try to use copies rather than symlinks, even when symlinks are the default for the platform)r   r!   Úadd_parser_argumentsÚadd_argumentÚadd_mutually_exclusive_groupr   r   ÚRuntimeError)ÚclsÚparserr'   ÚmetaÚapp_dataÚgroupr   r   r   r7   9   s:   ûû
úÿz$ViaGlobalRefApi.add_parser_argumentsc                 C   s   |   ¡  d S r   )Úinstall_patchr   r   r   r   ÚcreateX   s   zViaGlobalRefApi.createc                 C   sd   |   ¡ }|r0| jd }t dtt|ƒƒ¡ | d¡ | jd }t dtt|ƒƒ¡ | |¡ d S d S )Nz_virtualenv.pthz%create virtualenv import hook file %szimport _virtualenvú_virtualenv.pyz	create %s)Úenv_patch_textÚpurelibÚloggingÚdebugr   ÚstrÚ
write_text)r   ÚtextÚpthÚ	dest_pathr   r   r   r@   [   s   


úzViaGlobalRefApi.install_patchc              
   C   sh   | j  ttƒjd ¡�}| ¡ }| dttj	 
t| jƒt| jƒ¡ƒ¡W  d  ƒ S 1 s-w   Y  dS )zIPatch the distutils package to not be derailed by its configuration filesrB   z"__SCRIPT_DIR__"N)r>   Úensure_extractedr   Ú__file__ÚparentÚ	read_textÚreplaceÚreprÚosÚpathÚrelpathrG   Ú
script_dirrD   )r   Úresolved_pathrI   r   r   r   rC   e   s   $$þzViaGlobalRefApi.env_patch_textc                    s   t t| ƒ ¡ d| jfg S )NÚglobal)r   r!   Ú_argsr%   r   r   r   r   rX   k   s   zViaGlobalRefApi._argsc                    s&   t t| ƒ ¡  | jrdnd| jd< d S )NÚtrueÚfalsezinclude-system-site-packages)r   r!   Úset_pyenv_cfgr%   Ú	pyenv_cfgr   r   r   r   r[   n   s   zViaGlobalRefApi.set_pyenv_cfg)r   r   r   r   Ústaticmethodr"   Úclassmethodr7   rA   r@   rC   rX   r[   r    r   r   r   r   r!   !   s    

r!   )Ú
__future__r   r   rE   rR   Úabcr   Úsixr   Úvirtualenv.infor   Úvirtualenv.util.pathr   Úvirtualenv.util.sixr   Úcreatorr
   r   r   r!   r   r   r   r   Ú<module>   s    