o
    Ëý°jÒC  ã                   @   s,  U 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m	Z	m
Z
mZm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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%e&e'd< ej(dkZ)de*fdd„Z+e+ƒ Z,e)r…e,s…ej-Z.nej/Z.de*fdd„Z0dee&e&f de*fdd„Z1e j2dd�de*fdd„ƒZ3e j2dd�de*fdd„ƒZ4e j2dd�de*fdd„ƒZ5e j2dd�de*fdd„ƒZ6e j2dd�de*fd d!„ƒZ7d"ee& de	e& fd#d$„Z8e j2dd�d%ej9d&ej9d'e&ddfd(d)„ƒZ:d%ej9d&ej9d'e&de*fd*d+„Z;e j2dd�d,dddd-œd.e*d/ee& d0ee& d1ee& ddf
d2d3„ƒZ<	,			,	dLd4e&d.e*d/ee& d0ee& d5e*d1ee& defd6d7„Z=de&fd8d9„Z>de&fd:d;„Z?d<e&de*fd=d>„Z@de&fd?d@„ZAde&fdAdB„ZBdCe&dDe&de
e& fdEdF„ZCdGe&de*fdHdI„ZDd1e&de
e& fdJdK„ZEdS )Mé    N)ÚAnyÚDictÚIteratorÚListÚOptionalÚTuple)ÚSCHEME_KEYSÚScheme)ÚWINDOWS)Ú
deprecated)Úrunning_under_virtualenvé   )Ú
_distutilsÚ
_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_prefixed_libsÚget_purelibÚ
get_schemer   r   r   Ú
platlibdirÚlibÚ_PLATLIBDIR)é   é
   Ú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.
    Ú_PIP_USE_SYSCONFIG)ÚboolÚgetattrÚ	sysconfigÚ_USE_SYSCONFIG_DEFAULT© r'   r'   ú“/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/pip/_internal/locations/__init__.pyÚ_should_use_sysconfig/   s   r)   c                  C   s8   ddl m}  z| d d }W |dkS  ty   Y dS w )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+   Úunix_user_platlibr'   r'   r(   Ú_looks_like_bpo_44860G   s   þÿr1   Úschemec                 C   sP   | d }d|v r|  ddt› d�¡}d|vrdS |  dd¡}|  dd¡| d	 kS )
Nr-   z/$platlibdir/ú/ú/lib64/Fz/lib/z
$platbase/z$base/Úpurelib)Úreplacer   )r2   r-   Ú	unpatchedr'   r'   r(   Ú+_looks_like_red_hat_patched_platlib_purelibU   s   r8   )Úmaxsizec                      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)r8   ©Ú.0Úkr*   r'   r(   Ú	<genexpr>g   s   € þ

þz*_looks_like_red_hat_lib.<locals>.<genexpr>)Úunix_prefixÚ	unix_home)r.   r+   Úallr'   r'   r*   r(   Ú_looks_like_red_hat_lib_   s   ýrB   c                  C   s   ddl m}  d| v od| v S )z#Debian adds two additional schemes.r   r*   Ú
deb_systemÚ
unix_local)r.   r+   r*   r'   r'   r(   Ú_looks_like_debian_schemen   s   rE   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.   rF   Údistutils.distrG   Úfinalize_optionsÚexec_prefixÚosÚpathÚnormpathÚsysÚprefix)rF   rG   Úcmdr'   r'   r(   Ú_looks_like_red_hat_schemev   s   	
þrQ   c                  C   sH   t du rdS z	tjddd�} W n
 ty   Y dS w d| d v o#d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)r2   Úexpandr4   r5   )r   r%   Ú	get_pathsr/   ©Úpathsr'   r'   r(   Ú_looks_like_slackware_schemeŠ   s   ÿrW   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)rS   c                 s   s,   � | ]}d |vod|v o|  d¡ V  qdS )ÚLibr   zsite-packagesN)Úendswith©r<   Úpr'   r'   r(   r>   ¦   s
   € ÿ
ÿz1_looks_like_msys2_mingw_scheme.<locals>.<genexpr>c                 3   s   � | ]}ˆ | V  qd S r:   r'   )r<   ÚkeyrU   r'   r(   r>   ¨   ó   € ©r-   r5   )r%   rT   rA   r'   r'   rU   r(   Ú_looks_like_msys2_mingw_schemeš   s   þr`   Úpartsc                 c   sj   � t  d¡}ttdd ƒ}|r|r| |¡s| E d H  d S | D ]}| |¡r/|d dt|ƒ … }|V  qd S )NÚ	LDVERSIONÚabiflagsr   )r%   Úget_config_varr$   rN   rZ   Úlen)ra   Ú	ldversionrc   Úpartr'   r'   r(   Ú_fix_abiflags¬   s   €


ýrh   ÚoldÚnewr]   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)ri   rj   r]   Ú	issue_urlÚmessager'   r'   r(   Ú_warn_mismatched¼   s   ÿrp   c                C   s   | |krdS t | ||d� dS )NF©r]   T)rp   )ri   rj   r]   r'   r'   r(   Ú_warn_if_mismatchÇ   s   rr   F©ÚuserÚhomeÚrootrO   rt   ru   rv   rO   c                 C   s&   g d¢}t  td |¡| |||¡ d S )N)zAdditional context:z	user = %rz	home = %rz	root = %rzprefix = %rÚ
)rk   rl   rm   Újoin)rt   ru   rv   rO   ra   r'   r'   r(   Ú_log_contextÎ   s   ry   Ú	dist_nameÚisolatedc              	      s¼  t j| |||||d�}tr|S tj| |||||d�‰g }tD ]þ}t tˆ|ƒ¡}	t t||ƒ¡}
|	|
kr5qtj	j
dkoT|d uoT|dv oT|	j|
jkoT|	j
 d¡oT|
j
 d¡}|rXq|ontƒ on|dkon|	jj|
jkon|	jj
 d¡}|rrq|dkrztƒ rzq|oŽ|dkoŽt oŽtjdkoŽtdkoŽtƒ }|r’q|o�|dv o�t o�tƒ }|r¡q|p©|p©|p©tƒ  oÕ|	jd	d
… dkoÕt|
jƒd	koÕ|
jd	 dkoÕt|
jƒd
k pÏ|
jd dkoÕtƒ pÕtƒ }|rÙqtjdk oît oî|dv oîtt|	jƒƒ|
jk}|ròqtoú|dv oútƒ }|rþqtjdd��ot �o|dv }|�rq| |	|
d|› �f¡ q|�s"ˆS tj| |||||dd�‰ t ‡ ‡fdd„tD ƒƒ�rDt!dd d d� ˆS |D ]\}	}
}t"|	|
|d� �qFt#||||d� ˆS )N)rt   ru   rv   r{   rO   Úpypyr_   ÚpythonÚheadersr-   )r   é	   r   r   r   )ÚusrÚlocalr€   é   r�   )r   é   )r~   r-   r5   T)Ú
check_home)r~   ÚincludeÚplatincludezscheme.)Úignore_config_filesc                 3   s"   � | ]}ˆ | t ˆ|ƒkV  qd S r:   )r$   r;   ©Údefault_oldri   r'   r(   r>   ~  s   €  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_inrq   rs   )$r   r   Ú_USE_SYSCONFIGr   r   ÚpathlibÚPathr$   rN   ÚimplementationÚnameÚparentÚ
startswithr   rB   r
   Úversion_infor   r1   rW   r   ra   re   rQ   rE   Útuplerh   r`   r%   Úis_python_buildÚappendÚdistutils_schemeÚanyr   rp   ry   )rz   rt   ru   rv   r{   rO   rj   Úwarning_contextsr=   Úold_vÚnew_vÚskip_pypy_special_caseÚ$skip_osx_framework_user_special_caseÚskip_bpo_44860Úskip_slackware_user_schemeÚskip_linux_system_special_caseÚskip_sysconfig_abiflag_bugÚskip_msys2_mingw_bugÚskip_cpython_buildr]   r'   rˆ   r(   r   á   s   úú	ÿþ
ý
ü
úÿþýûÿþýüúÿþüÿþýü
ú
ÿþüÿÿýù	ø
r   c                  C   s<   t  ¡ } tr| S t ¡ }tt |¡t | ¡dd�rtƒ  |S )NÚ
bin_prefixrq   )r   r   rŽ   r   rr   r�   r�   ry   ©rj   ri   r'   r'   r(   r   “  s   r   c                   C   s   t jddd�jS )NÚ T)rt   )r   r   Úscriptsr'   r'   r'   r(   r   ž  s   r   Úvaluec                 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)rE   )rª   r'   r'   r(   Ú$_looks_like_deb_system_dist_packages¢  s
   
r«   c                  C   óH   t  ¡ } tr| S t ¡ }t|ƒr|S tt |¡t | ¡dd�r"tƒ  |S )z,Return the default pure-Python lib location.r5   rq   )	r   r   rŽ   r   r«   rr   r�   r�   ry   r§   r'   r'   r(   r   ³  ó   r   c                  C   r¬   )z0Return the default platform-shared lib location.r-   rq   )	r   r   rŽ   r   r«   rr   r�   r�   ry   r§   r'   r'   r(   r   Á  r­   r   Úv1Úv2c                 C   s   | |kr| gS | |gS )zDeduplicate values from a list.r'   )r®   r¯   r'   r'   r(   Ú_deduplicatedÏ  s   r°   rL   c                 C   s(   t jdd… dkrdS | dtƒ › d�kS )zAApple patches sysconfig to *always* look under */Library/Python*.Né   ÚdarwinFz/Library/Python/z/site-packages)rN   Úplatformr   )rL   r'   r'   r(   Ú_looks_like_apple_libraryÖ  s   r´   c                 C   s¢   t  | ¡\}}trt||ƒS t | ¡\}}t||ƒ}tdd„ |D ƒƒr,tdddd� |S tt 	|¡t 	|¡dd�tt 	|¡t 	|¡dd�g}t
|ƒrOt| d	� |S )
z*Return the lib locations under ``prefix``.c                 s   s   � | ]}t |ƒV  qd S r:   )r´   r[   r'   r'   r(   r>   ë  r^   z$get_prefixed_libs.<locals>.<genexpr>a&  Python distributed by Apple's Command Line Tools incorrectly patches sysconfig to always point to '/Library/Python'. This will cause build isolation to operate incorrectly on Python 3.10 or later. Please help report this to Apple so they can fix this. https://developer.apple.com/bug-reporting/NrŠ   zprefixed-purelibrq   zprefixed-platlib)rO   )r   r   rŽ   r°   r   rA   r   rr   r�   r�   rš   ry   )rO   Únew_pureÚnew_platÚold_pureÚold_platÚold_lib_pathsÚwarnedr'   r'   r(   r   Ý  s4   

÷ýýú
r   )FNNFN)FÚ	functoolsÚloggingrK   r�   rN   r%   Útypingr   r   r   r   r   r   Úpip._internal.models.schemer   r	   Úpip._internal.utils.compatr
   Úpip._internal.utils.deprecationr   Úpip._internal.utils.virtualenvr   r¨   r   r   Úbaser   r   r   r   r   r   Ú__all__Ú	getLoggerÚ__name__rk   r$   r   ÚstrÚ__annotations__r•   r&   r#   r)   rŽ   ÚWARNINGrm   ÚDEBUGr1   r8   Ú	lru_cacherB   rE   rQ   rW   r`   rh   r�   rp   rr   ry   r   r   r   r«   r   r   r°   r´   r   r'   r'   r'   r(   Ú<module>   s¦   
   	








 

ûþýüûúúÿþýüûú
ù 3