3
ûâdel8  ã               @   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 d
ddddddddddgZ ej!e"ƒZ#ej$j%dƒrîej&Z'nej(Z'e)eddƒZ*e+*ej,dDkZ-e.dœdd„Z/ee+e+f e.dœdd„Z0e j1dd �e.dœd!d"„ƒZ2e j1dd �e.dœd#d$„ƒZ3e j1dd �e.dœd%d&„ƒZ4e j1dd �e.dœd'd(„ƒZ5ee+ e	e+ d)œd*d+„Z6e j1dd �ej7ej7e+dd,œd-d.„ƒZ8ej7ej7e+e.d,œd/d0„Z9e j1dd �d1dddd2œe.ee+ ee+ ee+ dd3œd4d5„ƒZ:dEe+e.ee+ ee+ e.ee+ ed6œd7d„Z;e+dœd8d„Z<e+dœd9d„Z=e+e.d:œd;d<„Z>e+dœd=d„Z?e+dœd>d„Z@e+e+e
e+ d?œd@dA„ZAe+e
e+ dBœdCd„ZBdS )Fé    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_siter   Ú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é   é
   )Úreturnc              C   s:   ddl m}  y| d d }W n tk
r0   dS X |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_platlib© r&   ú?/tmp/pip-build-red6nood/pip/pip/_internal/locations/__init__.pyÚ_looks_like_bpo_448603   s    r(   )Úschemer    c             C   s\   | d }d|kr0t tdƒr0|jddtj› d�ƒ}d|kr<dS |jddƒ}|jdd	ƒ| d
 kS )Nr#   z/$platlibdir/r   ú/z/lib64/Fz/lib/z
$platbase/z$base/Úpurelib)ÚhasattrÚsysÚreplacer   )r)   r#   Z	unpatchedr&   r&   r'   Ú+_looks_like_red_hat_patched_platlib_purelibA   s    r/   )Ú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"   | ]}|ˆ kot ˆ | ƒV  qd S )N)r/   )Ú.0Úk)r!   r&   r'   ú	<genexpr>T   s   z*_looks_like_red_hat_lib.<locals>.<genexpr>Úunix_prefixÚ	unix_home)r4   r5   )r$   r!   Úallr&   r&   )r!   r'   Ú_looks_like_red_hat_libK   s    
r7   c              C   s   ddl m}  d| kod| k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ƒ  |jtjjt	jƒ› d�ko\|j
tj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Únormpathr-   Úprefix)r;   r<   Úcmdr&   r&   r'   Ú_looks_like_red_hat_schemeb   s    	
rE   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 |ko d|ko |j dƒ V  qdS )ÚLibr   zsite-packagesN)Úendswith)r1   Úpr&   r&   r'   r3   ƒ   s   z1_looks_like_msys2_mingw_scheme.<locals>.<genexpr>c             3   s   | ]}ˆ | V  qd S )Nr&   )r1   Úkey)Úpathsr&   r'   r3   „   s    r#   r+   )r#   r+   )Ú	sysconfigÚ	get_pathsr6   r&   r&   )rL   r'   Ú_looks_like_msys2_mingw_schemev   s    rO   )Úpartsr    c             c   sr   t jdƒ}ttdd ƒ}| s.| s.|j|ƒ r<| E d H  d S x0| D ](}|j|ƒrd|d dt|ƒ … }|V  qBW d S )NÚ	LDVERSIONÚabiflagsr   )rM   Úget_config_varÚgetattrr-   rI   Úlen)rP   Z	ldversionrR   Úpartr&   r&   r'   Ú_fix_abiflagsˆ   s    



rW   )ÚoldÚnewrK   r    c            C   s    d}d}t j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   rY   rK   Z	issue_urlÚmessager&   r&   r'   Ú_warn_mismatched˜   s    r^   c            C   s   | |krdS t | ||d� dS )NF)rK   T)r^   )rX   rY   rK   r&   r&   r'   Ú_warn_if_mismatch£   s    r_   F)ÚuserÚhomeÚrootrC   )r`   ra   rb   rC   r    c             C   s,   dddddg}t jtdj|ƒ| |||ƒ d S )NzAdditional context:z	user = %rz	home = %rz	root = %rzprefix = %rÚ
)rZ   r[   r\   Újoin)r`   ra   rb   rC   rP   r&   r&   r'   Ú_log_contextª   s    	re   )Ú	dist_namer`   ra   rb   ÚisolatedrC   r    c          	      sÚ  t j| |||||d�}tr|S tj| |||||d�‰g }�xtD �]}tjtˆ|ƒƒ}	tjt||ƒƒ}
|	|
krpq@tj	j
dko®|d k	o®|dko®|	j|
jko®|	j
jdƒo®|
j
jdƒ}|r¶q@|oâtƒ oâ|dkoâ|	jj|
jkoâ|	jj
jdƒ}|rêq@|dkrútƒ rúq@|�o,|dk�o,t �o,tjdk�o,td	k�o,tƒ }|�r6q@|�pL|�pL|�pLtƒ  �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jdk �oìt �oì|dk�oìtt|	jƒƒ|
jk}|�röq@t�o
|d k�o
tƒ }|�rq@tjdd��o0t �o0|d!k}|�r:q@|j|	|
d|› �fƒ q@W |�s^ˆS tj| |||||dd�‰ t‡ ‡fdd„tD ƒƒ�r¢t dd d d� ˆS x"|D ]\}	}
}t!|	|
|d� �q¨W t"||||d� ˆS )"N)r`   ra   rb   rg   rC   Zpypyr#   r+   ÚpythonÚheadersr   é	   r   r   ÚusrÚlocalé   é   T)Ú
check_homeÚincludeÚplatincludezscheme.)Zignore_config_filesc             3   s    | ]}ˆ | t ˆ|ƒkV  qd S )N)rT   )r1   r2   )Údefault_oldrX   r&   r'   r3   O  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ÚreplacementZgone_in)rK   )r`   ra   rb   rC   )r#   r+   )r   rj   )rk   rl   )r   rn   )ri   r#   r+   )r#   r+   )ri   rp   rq   )#r   r   Ú_USE_SYSCONFIGr   r   ÚpathlibÚPathrT   r-   ÚimplementationÚnameÚparentÚ
startswithr   r7   r
   Úversion_infoÚ_PLATLIBDIRr(   r   rP   rU   rE   r:   ÚtuplerW   rO   rM   Úis_python_buildÚappendÚdistutils_schemeÚanyr   r^   re   )rf   r`   ra   rb   rg   rC   rY   Zwarning_contextsr2   Zold_vZnew_vZskip_pypy_special_caseZ$skip_osx_framework_user_special_caseZskip_bpo_44860Zskip_linux_system_special_caseZskip_sysconfig_abiflag_bugZskip_msys2_mingw_bugZskip_cpython_buildrK   r&   )rr   rX   r'   r   ½   s´    

 
c              C   s<   t jƒ } tr| S tjƒ }ttj|ƒtj| ƒdd�r8tƒ  |S )NZ
bin_prefix)rK   )r   r   ru   r   r_   rv   rw   re   )rY   rX   r&   r&   r'   r   d  s    c               C   s   t jddd�jS )NÚ T)r`   )r   r   Úscriptsr&   r&   r&   r'   r   o  s    )Ú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 jƒ } tr| S tjƒ }t|ƒr$|S ttj|ƒtj| ƒdd�rDtƒ  |S )z,Return the default pure-Python lib location.r+   )rK   )	r   r   ru   r   r†   r_   rv   rw   re   )rY   rX   r&   r&   r'   r   „  s    c              C   sH   t jƒ } tr| S tjƒ }t|ƒr$|S ttj|ƒtj| ƒdd�rDtƒ  |S )z0Return the default platform-shared lib location.r#   )rK   )	r   r   ru   r   r†   r_   rv   rw   re   )rY   rX   r&   r&   r'   r   ’  s    )Ú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‰   )rC   r    c             C   sz   t j| ƒ\}}trt||ƒS tj| ƒ\}}ttj|ƒtj|ƒdd�ttj|ƒtj|ƒdd�g}t|ƒrpt	| d� t||ƒS )z*Return the lib locations under ``prefix``.zprefixed-purelib)rK   zprefixed-platlib)rC   )
r   r   ru   r‰   r   r_   rv   rw   r‚   re   )rC   Znew_pureZnew_platZold_pureZold_platZwarnedr&   r&   r'   r   §  s    


)r   r   )FNNFN)CÚ	functoolsÚloggingr@   rv   r-   rM   Útypingr   r   r   r   r   r   Zpip._internal.models.schemer   r	   Zpip._internal.utils.compatr
   Zpip._internal.utils.deprecationr   Zpip._internal.utils.virtualenvr   rƒ   r   r   Úbaser   r   r   r   r   r   Ú__all__Ú	getLoggerÚ__name__rZ   ÚenvironÚgetÚDEBUGr\   ÚWARNINGrT   r}   Ústrr|   ru   Úboolr(   r/   Ú	lru_cacher7   r:   rE   rO   rW   rw   r^   r_   re   r   r   r   r†   r   r   r‰   r   r&   r&   r&   r'   Ú<module>   s€      










     !