a
    il8                  	   @   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j$%drej&Z'nej(Z'e)eddZ*e+e,d< ej-dkZ.e/dddZ0ee+e+f e/dddZ1e j2dde/dddZ3e j2dde/dddZ4e j2dde/dddZ5e j2dde/dddZ6ee+ e	e+ dd d!Z7e j2ddej8ej8e+dd"d#d$Z9ej8ej8e+e/d"d%d&Z:e j2ddd'dddd(e/ee+ ee+ ee+ dd)d*d+Z;d@e+e/ee+ ee+ e/ee+ ed,d-d.Z<e+dd/d0Z=e+dd1d2Z>e+e/d3d4d5Z?e+dd6d7Z@e+dd8d9ZAe+e+e
e+ d:d;d<ZBe+e
e+ d=d>d?ZCdS )A    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   Z"_PIP_LOCATIONS_NO_WARN_ON_MISMATCH
platlibdirlib_PLATLIBDIR)   
   )returnc                  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#   unix_user_platlib r)   b/home/ec2-user/npost_license/.venv/lib/python3.9/site-packages/pip/_internal/locations/__init__.py_looks_like_bpo_448603   s    r+   )schemer!   c                 C   s\   | d }d|v r0t tdr0|ddtj d}d|vr<dS |dd}|dd	| d
 kS )Nr%   z/$platlibdir/r   /z/lib64/Fz/lib/z
$platbase/z$base/purelib)hasattrsysreplacer   )r,   r%   	unpatchedr)   r)   r*   +_looks_like_red_hat_patched_platlib_purelibA   s    r3   )maxsizec                      s"   ddl m  t fdddD S )zRed 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)r3   .0kr"   r)   r*   	<genexpr>S   s   z*_looks_like_red_hat_lib.<locals>.<genexpr>)unix_prefix	unix_home)r&   r#   allr)   r)   r"   r*   _looks_like_red_hat_libK   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_schemeZ   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&   rA   distutils.distrB   finalize_optionsexec_prefixospathnormpathr0   prefix)rA   rB   cmdr)   r)   r*   _looks_like_red_hat_schemeb   s    	
rK   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)expandc                 s   s*   | ]"}d |vo d|v o | d V  qdS )Libr   zsite-packagesN)endswith)r7   pr)   r)   r*   r9      s   z1_looks_like_msys2_mingw_scheme.<locals>.<genexpr>c                 3   s   | ]} | V  qd S r5   r)   )r7   keypathsr)   r*   r9          r%   r.   )	sysconfig	get_pathsr<   r)   r)   rR   r*   _looks_like_msys2_mingw_schemev   s    rX   )partsr!   c                 c   sh   t d}ttdd }|r(|r(||s6| E d H  d S | D ](}||r\|d dt|  }|V  q:d S )N	LDVERSIONabiflagsr   )rV   get_config_vargetattrr0   rO   len)rY   	ldversionr[   partr)   r)   r*   _fix_abiflags   s    


ra   )oldnewrQ   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)rb   rc   rQ   	issue_urlmessager)   r)   r*   _warn_mismatched   s    ri   c                C   s   | |krdS t | ||d dS )NFrQ   T)ri   )rb   rc   rQ   r)   r)   r*   _warn_if_mismatch   s    rk   FuserhomerootrI   )rm   rn   ro   rI   r!   c                 C   s&   g d}t td|| ||| d S )N)zAdditional context:z	user = %rz	home = %rz	root = %rzprefix = %r
)rd   re   rf   join)rm   rn   ro   rI   rY   r)   r)   r*   _log_context   s    rr   )	dist_namerm   rn   ro   isolatedrI   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}|rq<|ot o|dko|	jj|
jko|	jj
d}|rq<|dkrt rq<|o(|dko(t o(tjdko(tdko(t }|r2q<|pH|pH|pHt  o|	jd	d
 dkot|
jd	ko|
jd	 dkot|
jd
k s|
jd dkot pt }|rq<tjdk ot o|dv ott|	j|
jk}|rq<to|dv ot }|rq<tjddo,t o,|dv }|r6q<||	|
d| f q<|sXS tj| |||||dd t fddtD rt dd d d S |D ]\}	}
}t!|	|
|d qt"||||d S )N)rm   rn   ro   rt   rI   pypyrU   pythonheadersr%   )r   	   r   r   r   )usrlocalry      rz   )r      )rw   r%   r.   T)
check_home)rw   includeplatincludezscheme.)ignore_config_filesc                 3   s    | ]} | t |kV  qd S r5   )r]   r6   default_oldrb   r)   r*   r9   O  rT   zget_scheme.<locals>.<genexpr>zConfiguring 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_inrj   rl   )#r   r   _USE_SYSCONFIGr   r   pathlibPathr]   r0   implementationnameparent
startswithr   r=   r
   version_infor   r+   r   rY   r^   rK   r@   tuplera   rX   rV   is_python_buildappenddistutils_schemeanyr   ri   rr   )rs   rm   rn   ro   rt   rI   rc   warning_contextsr8   old_vnew_vskip_pypy_special_case$skip_osx_framework_user_special_caseskip_bpo_44860skip_linux_system_special_caseskip_sysconfig_abiflag_bugskip_msys2_mingw_bugskip_cpython_buildrQ   r)   r   r*   r      s    	



	
r   c                  C   s<   t  } tr| S t }tt|t| ddr8t  |S )N
bin_prefixrj   )r   r   r   r   rk   r   r   rr   rc   rb   r)   r)   r*   r   d  s    r   c                   C   s   t jdddjS )N T)rm   )r   r   scriptsr)   r)   r)   r*   r   o  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_packagess  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.   rj   )	r   r   r   r   r   rk   r   r   rr   r   r)   r)   r*   r     s    r   c                  C   sH   t  } tr| S t }t|r$|S tt|t| ddrDt  |S )z0Return the default platform-shared lib location.r%   rj   )	r   r   r   r   r   rk   r   r   rr   r   r)   r)   r*   r     s    r   )v1v2r!   c                 C   s   | |kr| gS | |gS )zDeduplicate values from a list.r)   )r   r   r)   r)   r*   _deduplicated  s    r   )rI   r!   c                 C   sz   t | \}}trt||S t| \}}tt|t|ddtt|t|ddg}t|rpt	| d t||S )z*Return the lib locations under ``prefix``.zprefixed-purelibrj   zprefixed-platlib)rI   )
r   r   r   r   r   rk   r   r   r   rr   )rI   new_purenew_platold_pureold_platwarnedr)   r)   r*   r     s$    

r   )FNNFN)D	functoolsloggingrF   r   r0   rV   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__rd   environgetDEBUGrf   WARNINGr]   r   str__annotations__r   r   boolr+   r3   	lru_cacher=   r@   rK   rX   ra   r   ri   rk   rr   r   r   r   r   r   r   r   r   r)   r)   r)   r*   <module>   s   
  	









      (