o
    Wi                     @  s   d dl 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mZ d dlmZ e	rNd 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ZG dd deZG dd deeZddgZdS )    )annotationsN)ABC)Path)TYPE_CHECKING)CreatorCreatorMeta)fs_supports_symlink)ArgumentParser)Any)
PythonInfo)AppData)VirtualEnvOptionsc                      s:   e Zd Zd
 fddZedddZeddd	Z  ZS )ViaGlobalRefMetareturnNonec                   s*   t    d | _d | _t sd| _d S d S )Nz(the filesystem does not supports symlink)super__init__
copy_errorsymlink_errorr   self	__class__ X/home/ubuntu/.local/lib/python3.10/site-packages/virtualenv/create/via_global_ref/api.pyr      s   

zViaGlobalRefMeta.__init__boolc                 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r   r   )r   r   )__name__
__module____qualname__r   propertyr   r    __classcell__r   r   r   r   r      s    r   c                      s   e Zd Zd% fddZered&d
dZed&ddZed'ddZ	e
d( fddZd)ddZd)ddZd*ddZd+ fd!d"Zd) fd#d$Z  ZS ),ViaGlobalRefApioptionsr   interpreterr   r   r   c                   s&   t  || | || _|j| _d S r   )r   r   _should_symlinksymlinkssystem_siteenable_system_site_package)r   r(   r)   r   r   r   r   *   s   zViaGlobalRefApi.__init__r   c                 C     d S r   r   r   r   r   r   purelib1      zViaGlobalRefApi.purelibc                 C  r.   r   r   r   r   r   r   
script_dir4   r0   zViaGlobalRefApi.script_dirr   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(   r2   r+   copy_srcsym_srclevels_optc_optr   r   r   r*   7   s   zViaGlobalRefApi._should_symlinkparserr	   metar   app_datar   c                   s   t  |||| |jdddddd |js?|js?g }|jr'|d|j  |jr3|d|j  d	d
| }t	||
 }|jrP|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)r5   actiondesthelpz	symlink: zcopy: z*neither symlink or copy method supported: z, z
--symlinksTr+   zZtry to use symlinks rather than copies, when symlinks are not the default for the platformz--copiesz--always-copyr2   z[try to use copies rather than symlinks, even when symlinks are the default for the platform)r   add_parser_argumentsadd_argumentr    r   r   appendr   joinRuntimeErroradd_mutually_exclusive_group)clsr=   r)   r>   r?   errorsmsggroupr   r   r   rD   H   sF   
z$ViaGlobalRefApi.add_parser_argumentsc                 C  s   |    d S r   )install_patchr   r   r   r   createo   s   zViaGlobalRefApi.createc                 C  s\   |   }|r,| jd }td| |jddd | jd }td| |j|dd d S d S )Nz_virtualenv.pthz%create virtualenv import hook file %szimport _virtualenvutf-8encoding_virtualenv.pyz	create %s)env_patch_textr/   LOGGERdebug
write_text)r   textpth	dest_pathr   r   r   rN   r   s   

zViaGlobalRefApi.install_patchstrc              
   C  sl   | j ttjd !}|jdd}|dttj	
t| jt| jW  d   S 1 s/w   Y  dS )zJPatch the distutils package to not be derailed by its configuration files.rS   rP   rQ   z"__SCRIPT_DIR__"N)r?   ensure_extractedr   __file__parent	read_textreplacereprospathrelpathr[   r1   r/   )r   resolved_pathrX   r   r   r   rT   |   s   $$zViaGlobalRefApi.env_patch_textlist[tuple[str, Any]]c                   s   g t   d| jfS )Nglobal)r   _argsr-   r   r   r   r   rh      s   zViaGlobalRefApi._argsc                   s"   t    | jr
dnd| jd< d S )Ntruefalsezinclude-system-site-packages)r   set_pyenv_cfgr-   	pyenv_cfgr   r   r   r   rk      s   
zViaGlobalRefApi.set_pyenv_cfg)r(   r   r)   r   r   r   )r   r   )r(   r   r   r   )
r=   r	   r)   r   r>   r   r?   r   r   r   r!   )r   r[   )r   rf   )r"   r#   r$   r   r   r%   r/   r1   staticmethodr*   classmethodrD   rO   rN   rT   rh   rk   r&   r   r   r   r   r'   )   s     
&


r'   )
__future__r   loggingrb   abcr   pathlibr   typingr   virtualenv.create.creatorr   r   virtualenv.infor   argparser	   r
   python_discoveryr   virtualenv.app_data.baser   virtualenv.config.cli.parserr   	getLoggerr"   rU   r   r'   __all__r   r   r   r   <module>   s(    
c