3
ûâdeï  ã               @   s@  d Z ddlZddlZddl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 ddlmZ dd	lmZ dd
lmZ ddlmZ ejeƒZdddœee eee ee eeef dœdd„Z!d ee ee ee e ee edœdd„Z"edœdd„Z#edœdd„Z$edœdd„Z%eeeef dœdd„Z&dS )!z7Locations where we look for configs, install stuff, etcé    N)ÚCommand)ÚSCHEME_KEYS)Úinstall)Úget_python_lib)ÚDictÚListÚOptionalÚTupleÚUnionÚcast)ÚScheme)ÚWINDOWS)Úrunning_under_virtualenvé   )Úget_major_minor_versionF)Úignore_config_files)Ú	dist_nameÚuserÚhomeÚrootÚisolatedÚprefixr   Úreturnc            C   sú  ddl m} d| i}|r"dg|d< ||ƒ}	|sty|	jƒ  W n8 tk
rr   |	jƒ }
tjddjdd	„ |
D ƒƒƒ Y nX d
}|	jddd�}|d
k	s’t	‚t
t|ƒ}|o¢| sºt	d|› d|› �ƒ‚|oÀ| sØt	d|› d|› �ƒ‚|pà|j|_|sì|ròd|_|pú|j|_|�p|j|_|�p|j|_|jƒ  i }x tD ]}t|d| ƒ||< �q,W d|	jdƒk�rn|jt|j|jd�ƒ tƒ �rö|�r‚|}n|�r�|j}n|j}tjj|dddtƒ › �| ƒ|d< |d
k	�rötjjtjj|d ƒƒd }tjj||dd
… ƒ|d< |S )z+
    Return a distutils install scheme
    r   )ÚDistributionÚnamez--no-user-cfgÚscript_argsz6Ignore distutils configs in %s due to encoding errors.z, c             s   s   | ]}t jj|ƒV  qd S )N)ÚosÚpathÚbasename)Ú.0Úp© r!   úA/tmp/pip-build-red6nood/pip/pip/_internal/locations/_distutils.pyú	<genexpr>4   s    z#distutils_scheme.<locals>.<genexpr>Nr   T)Úcreatezuser=z prefix=zhome=Ú Úinstall_Úinstall_lib)ÚpurelibÚplatlibÚincludeÚsiteÚpythonÚheadersr   )Údistutils.distr   Úparse_config_filesÚUnicodeDecodeErrorÚfind_config_filesÚloggerÚwarningÚjoinÚget_command_objÚAssertionErrorr   Údistutils_install_commandr   r   r   r   Úfinalize_optionsr   ÚgetattrÚget_option_dictÚupdateÚdictr'   r   Úinstall_userbaser   r   r   Ú
splitdriveÚabspath)r   r   r   r   r   r   r   r   Ú	dist_argsÚdÚpathsÚobjÚiÚschemeÚkeyÚpath_no_driver!   r!   r"   Údistutils_scheme   s^    





rH   )r   r   r   r   r   r   r   c             C   s8   t | |||||ƒ}t|d |d |d |d |d d�S )a;  
    Get the "scheme" corresponding to the input parameters. The distutils
    documentation provides the context for the available schemes:
    https://docs.python.org/3/install/index.html#alternate-installation

    :param dist_name: the name of the package to retrieve the scheme for, used
        in the headers scheme path
    :param user: indicates to use the "user" scheme
    :param home: indicates to use the "home" scheme and provides the base
        directory for the same
    :param root: root under which other directories are re-based
    :param isolated: equivalent to --no-user-cfg, i.e. do not consider
        ~/.pydistutils.cfg (posix) or ~/pydistutils.cfg (non-posix) for
        scheme paths
    :param prefix: indicates to use the "prefix" scheme and provides the
        base directory for the same
    r)   r(   r-   ÚscriptsÚdata)r)   r(   r-   rI   rJ   )rH   r   )r   r   r   r   r   r   rE   r!   r!   r"   Ú
get_schemei   s    rK   )r   c              C   sr   t jjtjƒ} tr>t jj| dƒ}t jj|ƒs:t jj| dƒ}|S tjd d… dkrd| d d… dkrddS t jj| dƒS )NÚScriptsÚbiné   Údarwiné   z/System/Library/z/usr/local/bin)	r   r   ÚnormpathÚsysr   r   r4   ÚexistsÚplatform)r   Úbin_pyr!   r!   r"   Úget_bin_prefixŒ   s    "rV   c               C   s
   t dd�S )NF)Úplat_specific)r   r!   r!   r!   r"   Úget_purelib�   s    rX   c               C   s
   t dd�S )NT)rW   )r   r!   r!   r!   r"   Úget_platlib¡   s    rY   )r   r   c             C   s   t d| d�t d| d�fS )NF)rW   r   T)r   )r   r!   r!   r"   Úget_prefixed_libs¥   s    
rZ   )FNNFN)FNNFN)'Ú__doc__Úloggingr   rR   Údistutils.cmdr   ZDistutilsCommandÚdistutils.command.installr   r   r7   Údistutils.sysconfigr   Útypingr   r   r   r	   r
   r   Zpip._internal.models.schemer   Zpip._internal.utils.compatr   Zpip._internal.utils.virtualenvr   Úbaser   Ú	getLoggerÚ__name__r2   ÚstrÚboolrH   rK   rV   rX   rY   rZ   r!   r!   r!   r"   Ú<module>   s<    
    J    