o
    6‘ðiÆ6  ã                   @  sÜ  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< dFdd„Z!e!ƒ Z"e"srddlm#Z# e"rxej$Z%nej&Z%dFdd„Z'dGdd„Z(ej)dFdd„ƒZ*ej)dFdd„ƒZ+ej)dFdd„ƒZ,ej)dFd d!„ƒZ-ej)dFd"d#„ƒZ.ej)dHd)d*„ƒZ/dId+d,„Z0ej)d-dddd.œdJd4d5„ƒZ1	-			-	dKdLd9d:„Z2dMd;d<„Z3dMd=d>„Z4dNd@dA„Z5dMdBdC„Z6dMdDdE„Z7dS )Oé    )Ú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ÚreturnÚboolc                   C  s   t ttddƒƒS )ah  This function determines the value of _USE_SYSCONFIG.

    By default, pip uses sysconfig.
    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_SYSCONFIGT)r   ÚgetattrÚ	sysconfig© r   r   ú_/root/parts/websockify/install/lib/python3.10/site-packages/pip/_internal/locations/__init__.pyÚ_should_use_sysconfig-   s   r    ©Ú
_distutilsc                  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_44860K   s   þÿr*   Úschemeúdict[str, str]c                 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   )r+   r&   Ú	unpatchedr   r   r   Ú+_looks_like_red_hat_patched_platlib_purelibY   s   r2   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)r2   ©Ú.0Úkr#   r   r   Ú	<genexpr>k   s   € þ

þz*_looks_like_red_hat_lib.<locals>.<genexpr>)Úunix_prefixÚ	unix_home)r'   r$   Úallr   r   r#   r   Ú_looks_like_red_hat_libc   s   ýr;   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_schemer   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_schemez   s   	
þrJ   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)r+   Úexpandr.   r/   )r   r   Ú	get_pathsr(   ©Úpathsr   r   r   Ú_looks_like_slackware_schemeŽ   s   ÿrP   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)rL   c                 s  s,   � | ]}d |vod|v o|  d¡ V  qdS )ÚLibr   zsite-packagesN)Úendswith)r5   Úpr   r   r   r7   ª   s
   € ÿ
ÿz1_looks_like_msys2_mingw_scheme.<locals>.<genexpr>c                 3  s   � | ]}ˆ | V  qd S r3   r   )r5   ÚkeyrN   r   r   r7   ¬   s   € ©r&   r/   )r   rM   r:   r   r   rN   r   Ú_looks_like_msys2_mingw_schemež   s   þrW   Úoldúpathlib.PathÚnewrU   ÚNonec                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)rX   rZ   rU   Ú	issue_urlÚmessager   r   r   Ú_warn_mismatched°   s   ÿra   c                C  s   | |krdS t | ||d� dS )NF©rU   T)ra   )rX   rZ   rU   r   r   r   Ú_warn_if_mismatch»   s   rc   F©ÚuserÚhomeÚrootrH   re   rf   ú
str | Nonerg   rH   c                 C  s&   g d¢}t  td |¡| |||¡ d S )N)zAdditional context:z	user = %rz	home = %rz	root = %rzprefix = %rÚ
)r\   r]   r^   Újoin)re   rf   rg   rH   Úpartsr   r   r   Ú_log_contextÂ   s   rl   Ú	dist_nameÚisolatedr   c              	     sz  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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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 ƒƒ�r#tdd d d� ˆS |D ]\}	}
}t|	|
|d� �q%t ||||d� ˆS )N)re   rf   rg   rn   rH   ÚpypyrV   ÚpythonÚheadersr&   r   r   é   )ÚusrÚlocalrs   é   rt   T)Ú
check_home)rq   ÚincludeÚplatincludezscheme.)Úignore_config_filesc                 3  s"   � | ]}ˆ | t ˆ|ƒkV  qd S r3   )r   r4   ©Údefault_oldrX   r   r   r7   f  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_inrb   rd   )!r	   r   Ú_USE_SYSCONFIGr"   r   ÚpathlibÚPathr   rG   ÚimplementationÚnameÚparentÚ
startswithr   r;   r   r   r*   rP   r   rk   ÚlenrJ   r>   rW   r   Úis_python_buildÚappendÚdistutils_schemeÚanyr   ra   rl   )rm   re   rf   rg   rn   rH   rZ   Úwarning_contextsr6   Ú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_msys2_mingw_bugÚskip_cpython_buildrU   r   rz   r   r   Õ   sê   úú	ÿþ
ý
ü
úÿþýûÿþýûÿþüÿþýü
úÿÿýù	ø
r   c                  C  s<   t  ¡ } tr| S t ¡ }tt |¡t | ¡dd�rtƒ  |S )NÚ
bin_prefixrb   )r	   r   r   r"   rc   r€   r�   rl   ©rZ   rX   r   r   r   r   {  s   r   c                   C  s   t jddd�jS )NÚ T)re   )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)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�r"tƒ  |S )z,Return the default pure-Python lib location.r/   rb   )	r	   r   r   r"   rš   rc   r€   r�   rl   r–   r   r   r   r   ›  s   r   c                  C  sT   t  ¡ } tr| S ddlm} | ¡ }t|ƒr|S tt |¡t | ¡dd�r(t	ƒ  |S )z0Return the default platform-shared lib location.r   r!   r&   rb   )
r	   r   r   r—   r"   rš   rc   r€   r�   rl   )rZ   r"   rX   r   r   r   r   ©  s   r   )r   r   )r+   r,   r   r   )rX   rY   rZ   rY   rU   r   r   r[   )rX   rY   rZ   rY   rU   r   r   r   )
re   r   rf   rh   rg   rh   rH   rh   r   r[   )FNNFN)rm   r   re   r   rf   rh   rg   rh   rn   r   rH   rh   r   r   )r   r   )r™   r   r   r   )8Ú
__future__r   Ú	functoolsÚloggingrD   r€   rG   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__r\   r   r   Ú__annotations__r    r   r"   ÚDEBUGr^   ÚWARNINGr*   r2   Úcacher;   r>   rJ   rP   rW   ra   rc   rl   r   r   r   rš   r   r   r   r   r   r   Ú<module>   sp     	






ûú 
'


