U
    ©/e(  ã                   @   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 dd
lmZ G dd„ deƒZej deƒ ¡ nNd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                    sd   ˆ | f|ž|Ž}|   d¡}d|kr8ttj tj¡f|d< dD ]"}d |¡}||kr<| |d ¡ q<|S )NÚinstallÚprefix)ZpurelibZplatlibZheadersZscriptsÚdataz
install_{})	Zget_option_dictÚVIRTUALENV_PATCH_FILEÚosÚpathÚabspathÚsysr   ÚformatÚpop)ÚselfÚargsÚkwargsÚresultr   ÚbaseÚkey©Zold_parse_config_files© úN/home/serveradmin/notebook/work/env/lib/python3.8/site-packages/_virtualenv.pyÚparse_config_files   s    

z&patch_dist.<locals>.parse_config_filesN)ZDistributionr   )Zdistr   r   r   r   Ú
patch_dist
   s    r   )zdistutils.distzsetuptools.dist)é   é   )ÚMetaPathFinder)Ú	find_spec)ÚLock)Úpartialc                   @   s<   e Zd ZdZdZeƒ 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 krÈ| jd krÈ| jª || _z”t||ƒ}|d k	r²t|jdƒ}|rHdnd}t|j|ƒ}|rb| jn| j}||k	ržzt	|j|t
||ƒƒ W n tk
rœ   Y nX |W ¢W  5 Q R £ S W 5 d | _X W 5 Q R X d S )NÚexec_moduleÚload_module)Ú_DISTUTILS_PATCHÚfullnameÚlockr   ÚhasattrÚloaderÚgetattrr   r   Úsetattrr   ÚAttributeError)	r   r!   r   ÚtargetÚspecZ
is_new_apiZ	func_nameÚoldÚfuncr   r   r   r   3   s"    
z_Finder.find_specc                 C   s   | |ƒ |j tkrt|ƒ d S ©N©Ú__name__r    r   )r*   Úmoduler   r   r   r   H   s    
z_Finder.exec_modulec                 C   s   | |ƒ}|j tkrt|ƒ |S r,   r-   )r*   Únamer/   r   r   r   r   N   s    
z_Finder.load_module)N)r.   Ú
__module__Ú__qualname__Ú__doc__r!   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 r,   )ÚobjectÚ__init__r6   )r   r   r   r   r   r:   \   s    
z_VirtualenvImporter.__init__c                 C   sB   |t kr>z t|ft| d¡d |ƒžŽ W S  tk
r<   Y nX d S )NÚ.éÿÿÿÿ)r    Ú_VirtualenvLoaderr5   ÚsplitÚImportError)r   r!   r   r   r   r   r5   `   s     z_VirtualenvImporter.find_module)N)N)r.   r1   r2   r:   r5   r   r   r   r   r8   [   s   
r8   c                       s$   e Zd Zdd„ Z‡ fdd„Z‡  ZS )r=   c                 C   s    t  | ¡ t | ||||¡ d S r,   )r9   r:   r7   )r   r!   ÚfileÚfilenameZetcr   r   r   r:   i   s    
z_VirtualenvLoader.__init__c                    s"   t t| ƒ |¡}t|ƒ d |_|S r,   )Úsuperr=   r   r   Ú
__loader__)r   r!   r/   ©Ú	__class__r   r   r   m   s    z_VirtualenvLoader.load_module)r.   r1   r2   r:   r   Ú__classcell__r   r   rD   r   r=   h   s   r=   )r3   r   r	   r   ÚjoinÚ__file__r   r   r    Úversion_infoÚimportlib.abcr   Zimportlib.utilr   Z	threadingr   Z	functoolsr   r   Ú	meta_pathÚinsertZimpr5   Zpkgutilr6   r7   r9   r8   r=   Úappendr   r   r   r   Ú<module>   s"   
(