o
    $¼"b  ã                   @   sÐ   d Z ddlZddlZej e¡Zdd„ ZdZej	dkr?ddl
mZ ddlmZ dd	lmZ G d
d„ deƒZej deƒ ¡ dS ddlmZ ddlmZmZ G dd„ deeƒZG dd„ deeƒZej eƒ ¡ dS )z>Patches that are applied at runtime to the virtual environmenté    Nc                    s    | j j‰ ‡ fdd„}|| j _dS )a  
    Distutils allows user to configure some arguments via a configuration file:
    https://docs.python.org/3/install/index.html#distutils-configuration-files

    Some of this arguments though don't make sense in context of the virtual environment files, let's fix them up.
    c                    sj   ˆ | g|¢R i |¤Ž}|   d¡}d|v rttj tj¡f|d< dD ]}d |¡}||v r2| |d ¡ q!|S )NÚinstallÚprefix)ÚpurelibÚplatlibÚheadersÚscriptsÚdataz
install_{})	Úget_option_dictÚVIRTUALENV_PATCH_FILEÚosÚpathÚabspathÚsysr   ÚformatÚpop)ÚselfÚargsÚkwargsÚresultr   ÚbaseÚkey©Úold_parse_config_files© úN/usr/lib/python3/dist-packages/virtualenv/create/via_global_ref/_virtualenv.pyÚparse_config_files   s   

€z&patch_dist.<locals>.parse_config_filesN)ÚDistributionr   )Údistr   r   r   r   Ú
patch_dist
   s   r   )zdistutils.distzsetuptools.dist)é   é   )Úpartial)ÚMetaPathFinder)Ú	find_specc                   @   s:   e Zd ZdZdZg Zd	dd„Zedd„ ƒZedd„ ƒZ	dS )
Ú_FinderzFA meta path finder that allows patching the imported distutils modulesNc              	   C   s"  |t v r�| jd u r�t| jƒdkrdd l}| ¡ }| j |¡ | jd �` || _zOt||ƒ}|d urrt|j	dƒ}|r;dnd}t
|j	|ƒ}	|rH| jn| j}
|	|
urezt|j	|t|
|	ƒƒ W n	 tyd   Y nw |W d | _W  d   ƒ S W d | _nd | _w W d   ƒ d S 1 s†w   Y  d S d S d S )Nr   Úexec_moduleÚload_module)Ú_DISTUTILS_PATCHÚfullnameÚlenÚlockÚ	threadingÚLockÚappendr#   ÚhasattrÚloaderÚgetattrr%   r&   Úsetattrr!   ÚAttributeError)r   r(   r   Útargetr+   r*   ÚspecÚ
is_new_apiÚ	func_nameÚoldÚfuncr   r   r   r#   6   s6   
ÿï"ïóz_Finder.find_specc                 C   s"   | |ƒ |j tv rt|ƒ d S d S ©N©Ú__name__r'   r   )r7   Úmoduler   r   r   r%   W   s   
ÿz_Finder.exec_modulec                 C   s   | |ƒ}|j tv rt|ƒ |S r9   r:   )r7   Únamer<   r   r   r   r&   ]   s   
z_Finder.load_moduler9   )
r;   Ú
__module__Ú__qualname__Ú__doc__r(   r*   r#   Ústaticmethodr%   r&   r   r   r   r   r$   ,   s    
!
r$   )Úfind_module)ÚImpImporterÚ	ImpLoaderc                   @   s    e Zd Zddd„Zddd„ZdS )Ú_VirtualenvImporterNc                 C   s   t  | ¡ t | |¡ d S r9   )ÚobjectÚ__init__rC   )r   r   r   r   r   rG   k   s   
z_VirtualenvImporter.__init__c                 C   sD   |t v r zt|gt| d¡d |ƒ¢R Ž W S  ty   Y d S w d S )NÚ.éÿÿÿÿ)r'   Ú_VirtualenvLoaderrB   ÚsplitÚImportError)r   r(   r   r   r   r   rB   o   s   "þz_VirtualenvImporter.find_moduler9   )r;   r>   r?   rG   rB   r   r   r   r   rE   j   s    
rE   c                       s$   e Zd Zdd„ Z‡ fdd„Z‡  ZS )rJ   c                 C   s    t  | ¡ t | ||||¡ d S r9   )rF   rG   rD   )r   r(   ÚfileÚfilenameÚetcr   r   r   rG   x   s   
z_VirtualenvLoader.__init__c                    s"   t t| ƒ |¡}t|ƒ d |_|S r9   )ÚsuperrJ   r&   r   Ú
__loader__)r   r(   r<   ©Ú	__class__r   r   r&   |   s   z_VirtualenvLoader.load_module)r;   r>   r?   rG   r&   Ú__classcell__r   r   rR   r   rJ   w   s    rJ   )r@   r   r   r   ÚjoinÚ__file__r
   r   r'   Úversion_infoÚ	functoolsr!   Úimportlib.abcr"   Úimportlib.utilr#   r$   Ú	meta_pathÚinsertÚimprB   ÚpkgutilrC   rD   rF   rE   rJ   r-   r   r   r   r   Ú<module>   s"    
8