o
    Wij                     @  s   d Z ddlmZ ddlZddlZddlZddlmZ er,ddlZddl	m
Z
 ddlmZ ejeZdddZdZG dd dZejde  dS )z?Patches that are applied at runtime to the virtual environment.    )annotationsN)TYPE_CHECKING)Callable)
ModuleSpecdisttypes.ModuleTypereturnNonec                   s"   | j j d 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.

    argsobjectkwargsr   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datainstall_)get_option_dictVIRTUALENV_PATCH_FILEospathabspathsysr   pop)selfr
   r   resultr   basekeyold_parse_config_files `/home/ubuntu/.local/lib/python3.10/site-packages/virtualenv/create/via_global_ref/_virtualenv.pyparse_config_files   s   

z&patch_dist.<locals>.parse_config_filesN)r
   r   r   r   r   r   )Distributionr$   )r   r$   r"   r    r#   
patch_dist   s   r&   )zdistutils.distzsetuptools.distc                   @  s@   e Zd ZdZdZg Zddd
dZedddZedddZ	dS )_FinderzGA meta path finder that allows patching the imported distutils modules.Nfullnamestrr   r   targetr   ModuleSpec | Nonec              	   C  sP  zt }W n
 ty   Y d S w ||v r| jd u rt| jdkr-dd l}| }| j| ddlm	} ddl
m} | jd ` || _zO|||}	|	d urt|	jd}
|
rVdnd}t|	j|}|
rc| jn| j}||urzt|	j|||| W n	 ty   Y nw |	W d | _W  d    S W d | _nd | _w W d    d S 1 sw   Y  d S )Nr   )partial)	find_specexec_moduleload_module)_DISTUTILS_PATCH	NameErrorr(   lenlock	threadingLockappend	functoolsr,   importlib.utilr-   hasattrloadergetattrr.   r/   setattrAttributeError)r   r(   r   r*   distutils_patchr4   r3   r,   r-   spec
is_new_api	func_nameoldfuncr"   r"   r#   r-   :   sH   

z_Finder.find_specrB   Callable[..., object]moduler   r	   c                 C  sl   | | zt }W n
 ty   Y d S w |j|v r4tt t| W d    d S 1 s-w   Y  d S d S Nr0   r1   __name__
contextlibsuppressr&   )rB   rE   r>   r"   r"   r#   r.   f   s   

"z_Finder.exec_moduleCallable[..., types.ModuleType]namec                 C  sj   | |}zt }W n ty   | Y S w |j|v r3tt t| W d    |S 1 s.w   Y  |S rF   rG   )rB   rL   rE   r>   r"   r"   r#   r/   r   s   


z_Finder.load_modulerF   )r(   r)   r   r   r*   r   r   r+   )rB   rD   rE   r   r   r	   )rB   rK   rL   r)   r   r   )
rH   
__module____qualname____doc__r(   r3   r-   staticmethodr.   r/   r"   r"   r"   r#   r'   0   s    ,r'   )r   r   r   r	   )rO   
__future__r   rI   r   r   typingr   typescollections.abcr   importlib.machineryr   r   r   __file__r   r&   r0   r'   	meta_pathinsertr"   r"   r"   r#   <module>   s    
P