o
    Hb                     @   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_prefixZinstall_baseZ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   )Zset_undefined_optionsr
   finalize_optionsr   r   r   r   r/   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   ZdistributionZget_namer   Zget_versionsysversion_info)r   Zno_pyverbasenamer   r   r   r3   N   s,   
zinstall_egg_info.basename)r'   r(   r)   r*   orig_install_egg_infor.   r,   r   r/   propertyr3   r-   r   r   r   r   r.   ?   s    
r.   c                   C   s   t jt jkp
tt dS )NZreal_prefix)r1   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   ZlibZpython3zdist-packageszsite-packages)r   r   r    r"   join)Zstandard_libZ	libpythonZearly_prefixr!   Zis_default_prefixr   r   r   
_posix_libk   s   
r9   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   Zincluder   z/local/z	/include/z/local/include/)r+   INSTALL_SCHEMESreplace)r%   schemer:   r   r   r   _inject_headersu   s   
r>   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   )itemsr>   Zschemesr%   r=   _load_schemesr   r   wrapped_load_schemes   s   z2load_schemes_wrapper.<locals>.wrapped_load_schemesr   )rB   rC   r   rA   r   load_schemes_wrapper   s   rD   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)	sysconfigZ	get_pathsr>   r@   r   r   r   add_debian_schemes   s   rG   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 )Nr>   rB   )r   r+   r.   r4   r9   	distutilsrF   r7   r>   rD   rB   rG   r;   r   r   r   r   apply_customizations   s   


rI   )__doc__r   r1   rF   Zdistutils.sysconfigrH   Zdistutils.command.installZcommandr   r+   Z"distutils.command.install_egg_infor.   r4   r   r   r   Zdistutils.errorsr   r"   r9   r>   rD   rG   rI   r   r   r   r   <module>   s$    
%(


