a
    <BìjM7  ã                	   @  sL  U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
Z
 d dlmZ d dlmZ d dlmZ ddlmZ dd	lmZmZmZmZmZmZ g d
¢Ze e¡ZeeddƒZde d< ej!dkZ"ddœdd„Z#e#ƒ Z$e$sòddlm%Z% e"�re$�sej&Z'nej(Z'ddœdd„Z)dddœdd„Z*ej+ddœdd„ƒZ,ej+ddœdd„ƒZ-ej+ddœdd „ƒZ.ej+ddœd!d"„ƒZ/ej+ddœd#d$„ƒZ0ej+d%d%dd&d'œd(d)„ƒZ1d%d%ddd'œd*d+„Z2ej+d,dddd-œdd.d.d.d&d/œd0d1„ƒZ3dAddd.d.dd.d2d3œd4d5„Z4ddœd6d7„Z5ddœd8d9„Z6ddd:œd;d<„Z7ddœd=d>„Z8ddœd?d@„Z9dS )Bé    )ÚannotationsN)ÚSCHEME_KEYSÚScheme)ÚWINDOWS)Ú
deprecated)Úrunning_under_virtualenvé   )Ú
_sysconfig)ÚUSER_CACHE_DIRÚget_major_minor_versionÚget_src_prefixÚis_osx_frameworkÚsite_packagesÚ	user_site)
r
   Úget_bin_prefixÚget_bin_userr   Úget_platlibÚget_purelibÚ
get_schemer   r   r   Ú
platlibdirÚlibÚstrÚ_PLATLIBDIR)é   é
   Úbool)Úreturnc                   C  s   t ttdtƒƒS )ax  This function determines the value of _USE_SYSCONFIG.

    By default, pip uses sysconfig on Python 3.10+.
    But Python distributors can override this decision by setting:
        sysconfig._PIP_USE_SYSCONFIG = True / False
    Rationale in https://github.com/pypa/pip/issues/10647

    This is a function for testability, but should be constant during any one
    run.
    Z_PIP_USE_SYSCONFIG)r   ÚgetattrÚ	sysconfigÚ_USE_SYSCONFIG_DEFAULT© r    r    ú_/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pip/_internal/locations/__init__.pyÚ_should_use_sysconfig/   s    r"   ©Ú
_distutilsc                  C  s:   ddl m}  z| d d }W n ty0   Y dS 0 |dkS )zsThe resolution to bpo-44860 will change this incorrect platlib.

    See <https://bugs.python.org/issue44860>.
    r   ©ÚINSTALL_SCHEMESÚ	unix_userÚplatlibFz	$usersite)Údistutils.command.installr&   ÚKeyError)r&   Zunix_user_platlibr    r    r!   Ú_looks_like_bpo_44860M   s    r+   zdict[str, str])Úschemer   c                 C  sP   | d }d|v r$|  ddt› d�¡}d|vr0dS |  dd¡}|  dd¡| d	 kS )
Nr(   z/$platlibdir/ú/ú/lib64/Fz/lib/z
$platbase/z$base/Úpurelib)Úreplacer   )r,   r(   Z	unpatchedr    r    r!   Ú+_looks_like_red_hat_patched_platlib_purelib[   s    r1   c                     s"   ddl m‰  t‡ fdd„dD ƒƒS )z‘Red Hat patches platlib in unix_prefix and unix_home, but not purelib.

    This is the only way I can see to tell a Red Hat-patched Python.
    r   r%   c                 3  s"   | ]}|ˆ v ot ˆ | ƒV  qd S ©N)r1   ©Ú.0Úkr%   r    r!   Ú	<genexpr>m   s   þz*_looks_like_red_hat_lib.<locals>.<genexpr>)Úunix_prefixÚ	unix_home)r)   r&   Úallr    r    r%   r!   Ú_looks_like_red_hat_libe   s    ýr:   c                  C  s   ddl m}  d| v od| v S )z#Debian adds two additional schemes.r   r%   Z
deb_systemZ
unix_local)r)   r&   r%   r    r    r!   Ú_looks_like_debian_schemet   s    r;   c                  C  s^   ddl m}  ddlm} | |ƒ ƒ}| ¡  |jtj t	j¡› d�ko\|j
tj t	j
¡› d�kS )a\  Red Hat patches ``sys.prefix`` and ``sys.exec_prefix``.

    Red Hat's ``00251-change-user-install-location.patch`` changes the install
    command's ``prefix`` and ``exec_prefix`` to append ``"/local"``. This is
    (fortunately?) done quite unconditionally, so we create a default command
    object without any configuration to detect this.
    r   )Úinstall)ÚDistributionz/local)r)   r<   Údistutils.distr=   Úfinalize_optionsÚexec_prefixÚosÚpathÚnormpathÚsysÚprefix)r<   r=   Úcmdr    r    r!   Ú_looks_like_red_hat_scheme|   s    	
þrG   c                  C  sH   t du rdS ztjddd�} W n ty2   Y dS 0 d| d v oFdt vS )zÌSlackware patches sysconfig but fails to patch distutils and site.

    Slackware changes sysconfig's user scheme to use ``"lib64"`` for the lib
    path, but does not do the same to the site module.
    NFÚ
posix_user)r,   Úexpandr.   r/   )r   r   Ú	get_pathsr*   ©Úpathsr    r    r!   Ú_looks_like_slackware_scheme�   s    rM   c                     s.   t jddd�‰ tdd„ ‡ fdd„dD ƒD ƒƒS )a‰  MSYS2 patches distutils and sysconfig to use a UNIX-like scheme.

    However, MSYS2 incorrectly patches sysconfig ``nt`` scheme. The fix is
    likely going to be included in their 3.10 release, so we ignore the warning.
    See msys2/MINGW-packages#9319.

    MSYS2 MINGW's patch uses lowercase ``"lib"`` instead of the usual uppercase,
    and is missing the final ``"site-packages"``.
    ÚntF)rI   c                 s  s*   | ]"}d |vo d|v o |  d¡ V  qdS )ÚLibr   zsite-packagesN)Úendswith)r4   Úpr    r    r!   r6   ¬   s   ÿz1_looks_like_msys2_mingw_scheme.<locals>.<genexpr>c                 3  s   | ]}ˆ | V  qd S r2   r    )r4   ÚkeyrK   r    r!   r6   ®   ó    ©r(   r/   )r   rJ   r9   r    r    rK   r!   Ú_looks_like_msys2_mingw_scheme    s    þrU   zpathlib.PathÚNone)ÚoldÚnewrR   r   c                C  s    d}d}t  t|||| |¡ d S )Nz(https://github.com/pypa/pip/issues/10151zSValue for %s does not match. Please report this to <%s>
distutils: %s
sysconfig: %s)ÚloggerÚlogÚ_MISMATCH_LEVEL)rW   rX   rR   Z	issue_urlÚmessager    r    r!   Ú_warn_mismatched²   s    ÿr]   c                C  s   | |krdS t | ||d� dS )NF©rR   T)r]   )rW   rX   rR   r    r    r!   Ú_warn_if_mismatch½   s    r_   F©ÚuserÚhomeÚrootrE   z
str | None)ra   rb   rc   rE   r   c                 C  s&   g d¢}t  td |¡| |||¡ d S )N)zAdditional context:z	user = %rz	home = %rz	root = %rzprefix = %rÚ
)rY   rZ   r[   Újoin)ra   rb   rc   rE   Úpartsr    r    r!   Ú_log_contextÄ   s    rg   r   )Ú	dist_namera   rb   rc   ÚisolatedrE   r   c              	     s°  t j| |||||d�}tr|S tj| |||||d�‰g }tD �]î}t tˆ|ƒ¡}	t t||ƒ¡}
|	|
krlq<tj	j
dkoª|d uoª|dv oª|	j|
jkoª|	j
 d¡oª|
j
 d¡}|r²q<|oÞtƒ oÞ|dkoÞ|	jj|
jkoÞ|	jj
 d¡}|ræq<|dkrötƒ röq<|�o|dk�ot �otdk�otƒ }|�r&q<|�oB|dv �oBt �oBtƒ }|�rLq<|�pb|�pb|�pbtƒ  �oÈ|	jdd	… d
k�oÈt|
jƒdk�oÈ|
jd dk�oÈt|
jƒd	k �s¼|
jd dk�oÈtƒ �pÈtƒ }|�rÒq<t�oæ|dv �oætƒ }|�rðq<tjdd��ot �o|dv }|�rq<| |	|
d|› �f¡ q<|�s8ˆS tj| |||||dd�‰ t‡ ‡fdd„tD ƒƒ�r|tdd d d� ˆS |D ]\}	}
}t|	|
|d� �q€t ||||d� ˆS )N)ra   rb   rc   ri   rE   ÚpypyrT   ÚpythonÚheadersr(   r   r   r   )ÚusrÚlocalrm   é   rn   T)Ú
check_home)rl   ÚincludeÚplatincludezscheme.)Zignore_config_filesc                 3  s    | ]}ˆ | t ˆ|ƒkV  qd S r2   )r   r3   ©Zdefault_oldrW   r    r!   r6   h  rS   zget_scheme.<locals>.<genexpr>zöConfiguring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621)ÚreasonÚreplacementÚgone_inr^   r`   )!r	   r   Ú_USE_SYSCONFIGr$   r   ÚpathlibÚPathr   rD   ÚimplementationÚnameÚparentÚ
startswithr   r:   r   r   r+   rM   r   rf   ÚlenrG   r;   rU   r   Úis_python_buildÚappendÚdistutils_schemeÚanyr   r]   rg   )rh   ra   rb   rc   ri   rE   rX   Zwarning_contextsr5   Zold_vZnew_vZskip_pypy_special_caseZ$skip_osx_framework_user_special_caseZskip_bpo_44860Zskip_slackware_user_schemeZskip_linux_system_special_caseZskip_msys2_mingw_bugZskip_cpython_buildrR   r    rs   r!   r   ×   sê    úú	
ÿþ
ý
ü
úÿþýûÿþýûÿþüÿþýüúÿÿýù	ø
r   c                  C  s<   t  ¡ } tr| S t ¡ }tt |¡t | ¡dd�r8tƒ  |S )NZ
bin_prefixr^   )r	   r   rw   r$   r_   rx   ry   rg   ©rX   rW   r    r    r!   r   }  s    r   c                   C  s   t jddd�jS )NÚ T)ra   )r	   r   Úscriptsr    r    r    r!   r   ˆ  s    r   )Úvaluer   c                 C  s   t ƒ s
dS | dkrdS dS )aõ  Check if the value is Debian's APT-controlled dist-packages.

    Debian's ``distutils.sysconfig.get_python_lib()`` implementation returns the
    default package path controlled by APT, but does not patch ``sysconfig`` to
    do the same. This is similar to the bug worked around in ``get_scheme()``,
    but here the default is ``deb_system`` instead of ``unix_local``. Ultimately
    we can't do anything about this Debian bug, and this detection allows us to
    skip the warning when needed.
    Fz/usr/lib/python3/dist-packagesT)r;   )r†   r    r    r!   Ú$_looks_like_deb_system_dist_packagesŒ  s
    
r‡   c                  C  sH   t  ¡ } tr| S t ¡ }t|ƒr$|S tt |¡t | ¡dd�rDtƒ  |S )z,Return the default pure-Python lib location.r/   r^   )	r	   r   rw   r$   r‡   r_   rx   ry   rg   rƒ   r    r    r!   r   �  s    r   c                  C  sT   t  ¡ } tr| S ddlm} | ¡ }t|ƒr0|S tt |¡t | ¡dd�rPt	ƒ  |S )z0Return the default platform-shared lib location.r   r#   r(   r^   )
r	   r   rw   r„   r$   r‡   r_   rx   ry   rg   )rX   r$   rW   r    r    r!   r   «  s    r   )FNNFN):Ú
__future__r   Ú	functoolsÚloggingrA   rx   rD   r   Úpip._internal.models.schemer   r   Úpip._internal.utils.compatr   Úpip._internal.utils.deprecationr   Úpip._internal.utils.virtualenvr   r„   r	   Úbaser
   r   r   r   r   r   Ú__all__Ú	getLoggerÚ__name__rY   r   r   Ú__annotations__Úversion_infor   r"   rw   r$   ÚWARNINGr[   ÚDEBUGr+   r1   Úcacher:   r;   rG   rM   rU   r]   r_   rg   r   r   r   r‡   r   r   r    r    r    r!   Ú<module>   sp    	



û     ú '