o
    f                     @   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$    
%(


