o
    éT•j¨  ã                   @   sÆ   d Z ddlZddlZddlZddlZddlm  mZ	 ddl
m  mZ ddl
mZmZmZ ddlmZ G dd„ de	jƒZG dd„ dejƒZd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zeƒ  dS )a  
Apply Debian-specific patches to distutils commands.

Extracts the customized behavior from patches as reported
in pypa/distutils#2 and applies those customizations (except
for scheme definitions) to those commands.

Place this module somewhere in sys.path to take effect.
é    N)Úto_filenameÚ	safe_nameÚsafe_version)ÚDistutilsOptionErrorc                       sF   e Zd Zeejjƒdg Z‡ fdd„Z‡ fdd„Z‡ fdd„Z	‡  Z
S )Úinstall)zinstall-layout=Nz7installation layout to choose (known values: deb, unix)c                    ó   t ƒ  ¡  d | _d | _d S ©N©ÚsuperÚinitialize_optionsÚprefix_optionÚinstall_layout©Úself©Ú	__class__© ú,/usr/lib/python3.10/_distutils_system_mod.pyr       ó   

zinstall.initialize_optionsc                    s    |dkrH| j r| j  ¡ dv rd}n7| j  ¡ dv rd}n-tdƒ‚| jr+tj | j¡dks.tƒ r1d}ntj | j¡dkrFd | _| _	d | _
| _d}tƒ  |¡ d S )	NÚposix_prefix)ÚdebÚ
deb_system)Úunixú"unknown value for --install-layoutú
/usr/localú/usrÚposix_local)r   Úlowerr   r   ÚosÚpathÚnormpathÚprefixÚis_virtual_environmentÚexec_prefixÚinstall_baseÚinstall_platbaser
   Úselect_scheme)r   Únamer   r   r   r&   %   s&   ÿÿzinstall.select_schemec                    s   | j | _tƒ  ¡  d S r   )r!   r   r
   Úfinalize_unixr   r   r   r   r(   :   s   zinstall.finalize_unix)Ú__name__Ú
__module__Ú__qualname__ÚlistÚorig_installr   Úuser_optionsr   r&   r(   Ú__classcell__r   r   r   r   r      s    
ÿr   c                       sF   e Zd Zeejjƒdg Z‡ fdd„Z‡ fdd„Ze	dd„ ƒZ
‡  ZS )Úinstall_egg_info)zinstall-layoutNzcustom installation layoutc                    r   r   r	   r   r   r   r   r   D   r   z#install_egg_info.initialize_optionsc                    s&   |   dd¡ |   dd¡ tƒ  ¡  d S )Nr   )r   r   )r   r   )Úset_undefined_optionsr
   Úfinalize_optionsr   r   r   r   r2   I   s   z!install_egg_info.finalize_optionsc                 C   s¨   | j r| j  ¡ dvrtdƒ‚| j  ¡ dk}n| jrd}nd}|r6dtt| j ¡ ƒƒtt| j 	¡ ƒƒf }|S dtt| j ¡ ƒƒtt| j 	¡ ƒƒgt
jd d… ¢R  }|S )	N)r   r   r   r   FTz%s-%s.egg-infoz%s-%s-py%d.%d.egg-infoé   )r   r   r   r   r   r   ÚdistributionÚget_namer   Úget_versionÚsysÚversion_info)r   Úno_pyverÚbasenamer   r   r   r:   N   s,   ÿþ
ûþýzinstall_egg_info.basename)r)   r*   r+   r,   Úorig_install_egg_infor0   r.   r   r2   Úpropertyr:   r/   r   r   r   r   r0   ?   s    
ÿr0   c                   C   s   t jt jkp
tt dƒS )NÚreal_prefix)r7   Úbase_prefixr!   Úhasattrr   r   r   r   r"   g   s   r"   c                 C   sH   | p
t j |¡dv }| r|S |rtƒ st j |ddd¡S t j |d¡S )N)r   r   ÚlibÚpython3zdist-packageszsite-packages)r   r   r    r"   Újoin)Ústandard_libÚ	libpythonÚearly_prefixr!   Úis_default_prefixr   r   r   Ú
_posix_libk   s   
rG   c                 C   sP   d|vr&| dkr|d }nt jd d }| dkr"d|vr"| dd¡}||d< |S )aN  
    Given a scheme name and the resolved scheme,
    if the scheme does not include headers, resolve
    the fallback scheme for the name and use headers
    from it. pypa/distutils#88

    headers: module headers install location (posix_local is /local/ prefixed)
    include: cpython headers (Python.h)
    See also: bpo-44445
    Úheadersr   Úincluder   z/local/z	/include/z/local/include/)r-   ÚINSTALL_SCHEMESÚreplace)r'   ÚschemerH   r   r   r   Ú_inject_headersu   s   
rM   c                    s   ‡ fdd„}|S )z�
    Implement the _inject_headers modification, above, but before
    _inject_headers() was introduced, upstream. So, slower and messier.
    c                     s&   ˆ ƒ } |   ¡ D ]	\}}t||ƒ q| S r   )ÚitemsrM   ©Úschemesr'   rL   ©Ú_load_schemesr   r   Úwrapped_load_schemes�   s   z2load_schemes_wrapper.<locals>.wrapped_load_schemesr   )rR   rS   r   rQ   r   Úload_schemes_wrapper‹   s   rT   c                 C   s2   dD ]}|| vrt j|dd�}t||ƒ| |< qdS )zR
    Ensure that the custom schemes we refer to above are present in schemes.
    )r   r   r   F)ÚexpandN)Ú	sysconfigÚ	get_pathsrM   rO   r   r   r   Úadd_debian_schemes˜   s   €ýrX   c                   C   sP   t t_ tt_ttj_ttdƒrtt_d S ttdƒr!t	tj
ƒt_
d S ttjƒ d S )NrM   rR   )r   r-   r0   r;   rG   Ú	distutilsrV   r?   rM   rT   rR   rX   rJ   r   r   r   r   Úapply_customizations¢   s   


rZ   )Ú__doc__r   r7   rV   Údistutils.sysconfigrY   Údistutils.command.installÚcommandr   r-   Ú"distutils.command.install_egg_infor0   r;   r   r   r   Údistutils.errorsr   r"   rG   rM   rT   rX   rZ   r   r   r   r   Ú<module>   s$    
%(


