3
ûâdeËl  ã               @   sH  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	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 d d	l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( d dl)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9 d dl:m;Z; d dl<m=Z=m>Z> d dl?m@Z@mAZAmBZB e4eCƒZDe#e@dœdd„ZEG dd„ deƒZFd/eGeeH eeH eGeeH e
eH d œd!d"„ZIeeH eGeGd#œd$d%„ZJd0eeG eeH eeH eeH eGeGd&œd'd(„ZKe
e* ee
eH  dd)œd*d+„ZLeMeGeGeHd,œd-d.„ZNdS )1é    N)ÚSUPPRESS_HELPÚValues)ÚIterableÚListÚOptional)Úcanonicalize_name)Ú
WheelCache)Ú
cmdoptions)Úmake_target_python)ÚRequirementCommandÚwarn_if_run_as_rootÚwith_cleanup)ÚERRORÚSUCCESS)ÚCommandErrorÚInstallationError)Ú
get_scheme)Úget_environment)ÚFormatControl)ÚConflictDetailsÚcheck_install_conflicts)Úinstall_given_reqs)ÚInstallRequirement)Úget_requirement_tracker)ÚWINDOWS)Úparse_distutils_args)Útest_writable_dir)Ú	getLogger)Ú
ensure_dirÚget_pip_versionÚ(protect_pip_from_modification_on_windowsÚwrite_output)ÚTempDirectory)Úrunning_under_virtualenvÚvirtualenv_no_global)ÚBinaryAllowedPredicateÚbuildÚ should_build_for_install_command)Úformat_controlÚreturnc                s   t tdœ‡ fdd„}|S )N)Úreqr)   c                s    t | jp
dƒ}ˆ j|ƒ}d|kS )NÚ Úbinary)r   ÚnameZget_allowed_formats)r*   Úcanonical_nameZallowed_formats)r(   © ú=/tmp/pip-build-red6nood/pip/pip/_internal/commands/install.pyÚcheck_binary_allowed5   s    
z6get_check_binary_allowed.<locals>.check_binary_allowed)r   Úbool)r(   r1   r/   )r(   r0   Úget_check_binary_allowed4   s    r3   c               @   sz   e Zd ZdZdZddœdd„Zeeee	 e
dœdd	„ƒZe	eedd
œdd„Zee ee dœdd„Zee	ddœdd„ZdS )ÚInstallCommandaI  
    Install packages from:

    - PyPI (and other indexes) using requirement specifiers.
    - VCS project urls.
    - Local project directories.
    - Local or remote source archives.

    pip also supports installing from "requirements files", which provide
    an easy way to specify a whole environment to be installed.
    a%  
      %prog [options] <requirement specifier> [package-index-options] ...
      %prog [options] -r <requirements file> [package-index-options] ...
      %prog [options] [-e] <vcs project url> ...
      %prog [options] [-e] <local project path> ...
      %prog [options] <archive url/path> ...N)r)   c             C   sj  | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jddddd dd� tj| j ƒ | j jddd	d
d� | j jdddt	d� | j jdddd dd� | j jdddd dd� | j jtj
ƒ ƒ | j jdddd	dd� | j jdddddgdd� | j jddd	d d� | j jd!d"d#d	d$d� | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jd%d	d&d'd(d)� | j jd*dd&d+d,� | j jd-dd.d'd/d)� | j jd0dd1d'd2d)� | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ | j jtjƒ ƒ tjtj| jƒ}| jjd3|ƒ | jjd3| j ƒ d S )4Nz-tz--targetÚ
target_dirÚdirz¥Install packages into <dir>. By default this will not replace existing files/folders in <dir>. Use --upgrade to replace existing packages in <dir> with new versions.)ÚdestÚmetavarÚdefaultÚhelpz--userÚuse_user_siteÚ
store_truez¸Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on Windows. (See the Python documentation for site.USER_BASE for full details.))r7   Úactionr:   z	--no-userÚstore_falsez--rootÚ	root_pathz=Install everything relative to this alternate root directory.z--prefixÚprefix_pathzIInstallation prefix where lib, bin and other top-level folders are placedz-Uz	--upgradeÚupgradez‚Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.z--upgrade-strategyÚupgrade_strategyzonly-if-neededÚeageraG  Determines how dependency upgrading should be handled [default: %default]. "eager" - dependencies are upgraded regardless of whether the currently installed version satisfies the requirements of the upgraded package(s). "only-if-needed" -  are upgraded only when they do not satisfy the requirements of the upgraded package(s).)r7   r9   Úchoicesr:   z--force-reinstallÚforce_reinstallz;Reinstall all packages even if they are already up-to-date.z-Iz--ignore-installedÚignore_installedz°Ignore the installed packages, overwriting them. This can break your system if the existing package is of a different version or was installed with a different package manager!z	--compileÚcompileTz'Compile Python source files to bytecode)r=   r7   r9   r:   z--no-compilez.Do not compile Python source files to bytecode)r=   r7   r:   z--no-warn-script-locationÚwarn_script_locationz0Do not warn when installing scripts outside PATHz--no-warn-conflictsÚwarn_about_conflictsz%Do not warn about broken dependenciesr   )Úcmd_optsÚ
add_optionr	   ÚrequirementsÚconstraintsÚno_depsÚpreÚeditableZadd_target_python_optionsr   ÚsrcÚignore_requires_pythonZno_build_isolationÚ
use_pep517Zno_use_pep517Úinstall_optionsÚglobal_optionsÚ	no_binaryÚonly_binaryZprefer_binaryÚrequire_hashesZprogress_barÚmake_option_groupÚindex_groupÚparserÚinsert_option_group)ÚselfÚ
index_optsr/   r/   r0   Úadd_optionsQ   sÄ    
zInstallCommand.add_options)ÚoptionsÚargsr)   c       )         s8  |j r|jd k	rtdƒ‚tj|ƒ d}|jr2|j}tj|dd� |jpHg }t	j
dtƒ ƒ t|j |j|j|j|jd�|_ d }d }|jrÚd|_tjj|jƒ|_tjj|jƒrÀtjj|jƒ rÀtdƒ‚tdd	�}|j}| j|ƒ |jpâg }| j|ƒ}t|ƒ}	| j|||	|jd
�}
t|j|jƒ}| jt ƒ ƒ}t|j! ddd�}�yˆ| j"|||
|ƒ}x|D ]}d|_#�qPW t$||jƒ | j%|||||
|j d�}| j&||
|||j |j|j|j'||j(d�
}| j)|
ƒ |j*||j d�}y|j+dƒ}W n t,k
�rð   d}Y nX |j-d k}t.|d� t/|
jƒ‰ ‡ fdd„|j0j1ƒ D ƒ}t2||dg g d�\}}dd„ |D ƒ}|�rft3dj4dj5|ƒƒƒ‚x|D ]}|j(�sld|_6�qlW |j7|ƒ}d }|j8 �o |j9}|�r²| j:|ƒ}|j;}|j�sÈ|j�rÌd}t<||||j||j||j |j=d�	}t>|j ||j|j|jd�}t?|ƒ} |j@tAjBdƒd� g }!x^|D ]V}"|"jC}#y(| jD|#ƒ}$|$d k	�r\|#› d|$jE› �}#W n tFk
�rt   Y nX |!jG|#ƒ �q,W |d k	�r¤| jH|| jI|ƒd� d j5|!ƒ}%|%�r¾tJd!|%ƒ W nH tKk
�r }& z*| jLd"k}'tM|&|'|j ƒ}(t	jN|(|'d#� tOS d }&~&X nX |j�r.|�stP‚| jQ|j||jƒ tRƒ  tSS )$Nz'Can not combine '--user' and '--target'zto-satisfy-onlyT)Zcheck_targetzUsing %s)r@   r5   r?   Úisolated_modez=Target path exists but is not a directory, will not continue.Útarget)Úkind)r`   ÚsessionÚtarget_pythonrR   Úinstall)Údeleterd   Zglobally_managed)Ztemp_build_dirr`   Úreq_trackerre   Úfinderr;   )
Úpreparerrj   r`   Úwheel_cacher;   rF   rR   rE   rB   rS   )Zcheck_supported_wheelsÚpipF)Úmodifying_pipc                s   g | ]}t |ˆ ƒr|‘qS r/   )r'   )Ú.0Úr)r1   r/   r0   ú
<listcomp>c  s   z&InstallCommand.run.<locals>.<listcomp>)rl   ÚverifyÚbuild_optionsrU   c             S   s   g | ]}|j r|j‘qS r/   )rS   r-   )ro   rp   r/   r/   r0   rq   s  s    zYCould not build wheels for {}, which is required to install pyproject.toml-based projectsz, i°   )ÚrootÚhomeÚprefixrH   r;   Ú	pycompile)Úuserru   rt   rv   Úisolatedr-   )Úkeyú-)Úresolver_variantú zSuccessfully installed %sé   )Úexc_info)Tr;   r5   r   r	   Úcheck_install_build_globalrA   rB   Zcheck_dist_restrictionrT   ÚloggerÚverboser   Údecide_user_installr@   r?   rb   rF   ÚosÚpathÚabspathÚexistsÚisdirr"   Úenter_contextrU   Zget_default_sessionr
   Ú_build_package_finderrR   r   Ú	cache_dirr(   r   Úno_cleanZget_requirementsZpermit_editable_wheelsÚ'reject_location_related_install_optionsZmake_requirement_preparerZmake_resolverrE   rS   Ztrace_basic_infoÚresolveÚget_requirementÚKeyErrorÚsatisfied_byr    r3   rL   Úvaluesr&   r   ÚformatÚjoinZlegacy_install_reasonZget_installation_orderÚignore_dependenciesrI   Ú_determine_conflictsrH   r   rG   Úget_lib_location_guessesr   ÚsortÚoperatorÚ
attrgetterr-   Úget_distributionÚversionÚ	ExceptionÚappendÚ_warn_about_conflictsZdetermine_resolver_variantr!   ÚOSErrorÚ	verbosityÚcreate_os_error_messageÚerrorr   ÚAssertionErrorÚ_handle_target_dirr   r   ))r]   r`   ra   rB   rT   Útarget_temp_dirZtarget_temp_dir_pathrU   re   rf   rj   rl   ri   Ú	directoryÚreqsr*   rk   ÚresolverÚrequirement_setZpip_reqrn   Zreqs_to_buildÚ_Zbuild_failuresZpep517_build_failure_namesrp   Ú
to_installÚ	conflictsZshould_warn_about_conflictsrH   Ú	installedZlib_locationsÚenvÚitemsÚresultÚitemÚinstalled_distZinstalled_descr£   Úshow_tracebackÚmessager/   )r1   r0   Úrunð   s*   




























zInstallCommand.run)r5   r¦   rA   r)   c                sV  t |ƒ g }td|jd�}|j}|j}|j}tjj|ƒrB|j|ƒ tjj|ƒr`||kr`|j|ƒ tjj|ƒrv|j|ƒ xÚ|D ]Ò}	xÌtj	|	ƒD ]¾}
|	|krÆtjj
||
ƒ‰ t‡ fdd„|d d… D ƒƒrÆqŒtjj
||
ƒ}tjj|ƒ�r4|sôtjd|ƒ qŒtjj|ƒ�rtjd|ƒ qŒtjj|ƒ�r*tj|ƒ n
tj|ƒ tjtjj
|	|
ƒ|ƒ qŒW q|W d S )	Nr+   )ru   c             3   s   | ]}|j ˆ ƒV  qd S )N)Ú
startswith)ro   Ús)Úddirr/   r0   ú	<genexpr>ñ  s    z4InstallCommand._handle_target_dir.<locals>.<genexpr>r~   zKTarget directory %s already exists. Specify --upgrade to force replacement.z„Target directory %s already exists and is a link. pip will not automatically replace links, please remove if replacement is desired.éÿÿÿÿ)r   r   r…   ÚpurelibÚplatlibÚdatar„   r‡   rž   Úlistdirr”   Úanyr�   ÚwarningÚislinkrˆ   ÚshutilÚrmtreeÚremoveÚmove)r]   r5   r¦   rA   Úlib_dir_listÚschemeÚpurelib_dirÚplatlib_dirZdata_dirÚlib_dirr²   Útarget_item_dirr/   )r¹   r0   r¥   Ö  sD    




z!InstallCommand._handle_target_dir)r¬   r)   c             C   s,   yt |ƒS  tk
r&   tjdƒ d S X d S )NzwError while checking for conflicts. Please file an issue on pip's issue tracker: https://github.com/pypa/pip/issues/new)r   r�   r�   Ú	exception)r]   r¬   r/   r/   r0   r–     s    z#InstallCommand._determine_conflicts)Úconflict_detailsr|   r)   c          
   C   s  |\}\}}| r| rd S g }|dkr4|j dƒ n|dks@t‚|j dƒ xH|D ]@}|| d }x.|| D ]"}	dj|||	d d�}
|j |
ƒ qjW qPW x\|D ]T}|| d }xB|| D ]6\}}}d	j||||||dkrØd
ndd�}
|j |
ƒ q´W qšW tjdj|ƒƒ d S )NÚlegacyz¤pip's legacy dependency resolver does not consider dependency conflicts when selecting packages. This behaviour is the source of the following dependency conflicts.z2020-resolverz§pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.r   z@{name} {version} requires {requirement}, which is not installed.r~   )r-   rœ   Úrequirementzg{name} {version} requires {requirement}, but {you} have {dep_name} {dep_version} which is incompatible.Úyouzyou'll)r-   rœ   rÐ   Údep_nameÚdep_versionrÑ   Ú
)rž   r¤   r“   r�   Úcriticalr”   )r]   rÎ   r|   Zpackage_setÚmissingZconflictingÚpartsÚproject_namerœ   Ú
dependencyrµ   rÒ   rÓ   r*   r/   r/   r0   rŸ     s<    

z$InstallCommand._warn_about_conflicts)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úusager_   r   r   r   ÚstrÚintr¶   r"   r2   r¥   r   r   r   r–   rŸ   r/   r/   r/   r0   r4   =   s      g5r4   F)rx   ru   rt   ry   rv   r)   c             C   s    t d| ||||d�}|j|jgS )Nr+   )rx   ru   rt   ry   rv   )r   r¼   r½   )rx   ru   rt   ry   rv   rÈ   r/   r/   r0   r—   O  s    r—   )rt   ry   r)   c             C   s   t dd„ tt| |d�ƒD ƒƒS )Nc             s   s   | ]}t |ƒV  qd S )N)r   )ro   Údr/   r/   r0   rº   c  s   z)site_packages_writable.<locals>.<genexpr>)rt   ry   )ÚallÚsetr—   )rt   ry   r/   r/   r0   Úsite_packages_writablea  s    rä   )r;   r@   r5   r?   rb   r)   c             C   s¦   | dk	r|  rt jdƒ dS | rH|r,tdƒ‚tƒ r:tdƒ‚t jdƒ dS | dksTt‚|s\|rjt jdƒ dS tjs~t jd	ƒ dS t||d
�r˜t jdƒ dS t j	dƒ dS )aZ  Determine whether to do a user install based on the input options.

    If use_user_site is False, no additional checks are done.
    If use_user_site is True, it is checked for compatibility with other
    options.
    If use_user_site is None, the default behaviour depends on the environment,
    which is provided by the other arguments.
    Nz$Non-user install by explicit requestFzVCan not combine '--user' and '--prefix' as they imply different installation locationszZCan not perform a '--user' install. User site-packages are not visible in this virtualenv.z User install by explicit requestTz3Non-user install due to --prefix or --target optionz4Non-user install because user site-packages disabled)rt   ry   z0Non-user install because site-packages writeablezMDefaulting to user installation because normal site-packages is not writeable)
r�   Údebugr   r$   r   r¤   ÚsiteÚENABLE_USER_SITErä   Úinfo)r;   r@   r5   r?   rb   r/   r/   r0   rƒ   h  s2    




rƒ   )rL   r`   r)   c             C   sž   t t tt dœdd„}g }x8| D ]0}|j}t|ƒ}|r"|jdj||jƒ ƒ|ƒƒ q"W |r~t|ƒ}|r~|jdj||jƒ ƒƒƒ |s†dS tdjdj	|ƒƒƒ‚dS )	z’If any location-changing --install-option arguments were passed for
    requirements or on the command-line, then show a deprecation warning.
    )Úoption_namesr)   c             S   s   dd„ | D ƒS )Nc             S   s   g | ]}d j |jddƒƒ‘qS )z--{}r«   r{   )r“   Úreplace)ro   r-   r/   r/   r0   rq   ­  s    zSreject_location_related_install_options.<locals>.format_options.<locals>.<listcomp>r/   )ré   r/   r/   r0   Úformat_options¬  s    z?reject_location_related_install_options.<locals>.format_optionsz{!r} from {}z{!r} from command lineNz˜Location-changing options found in --install-option: {}. This is unsupported, use pip-level options like --user, --prefix, --root, and --target instead.z; )
r   rß   r   rT   r   rž   r“   Úkeysr   r”   )rL   r`   rë   Z	offendersrÐ   rT   Zlocation_optionsr/   r/   r0   r�   ¥  s&    
r�   )r£   r´   Úusing_user_siter)   c             C   sÒ   g }|j dƒ |s,|j dƒ |j t| ƒƒ n
|j dƒ |d  d7  < | jtjkr’d}d}tƒ  r~| r~|j|d|jƒ gƒ n
|j |ƒ |j d	ƒ trÀ| jtjkrÀ| j	rÀt
| j	ƒd
krÀ|j dƒ dj|ƒjƒ d S )zrFormat an error message for an OSError

    It may occur anytime during the execution of the install command.
    z,Could not install packages due to an OSErrorz: Ú.r~   rÔ   z"Consider using the `--user` optionzCheck the permissionsz or z.
i  zÉHINT: This error might have occurred since this system does not have Windows Long Path support enabled. You can find information on how to enable this at https://pip.pypa.io/warnings/enable-long-paths
r+   r»   )rž   rß   ÚerrnoÚEACCESr#   ÚextendÚlowerr   ÚENOENTÚfilenameÚlenr”   Ústrip)r£   r´   rí   r×   Zuser_option_partZpermissions_partr/   r/   r0   r¢   Ì  s0    




r¢   )FNNFN)NNNF)Orï   r™   r„   rÃ   ræ   Úoptparser   r   Útypingr   r   r   Úpip._vendor.packaging.utilsr   Zpip._internal.cacher   Zpip._internal.clir	   Zpip._internal.cli.cmdoptionsr
   Zpip._internal.cli.req_commandr   r   r   Zpip._internal.cli.status_codesr   r   Zpip._internal.exceptionsr   r   Zpip._internal.locationsr   Zpip._internal.metadatar   Z#pip._internal.models.format_controlr   Zpip._internal.operations.checkr   r   Zpip._internal.reqr   Zpip._internal.req.req_installr   Zpip._internal.req.req_trackerr   Zpip._internal.utils.compatr   Z"pip._internal.utils.distutils_argsr   Zpip._internal.utils.filesystemr   Zpip._internal.utils.loggingr   Zpip._internal.utils.miscr   r   r    r!   Zpip._internal.utils.temp_dirr"   Zpip._internal.utils.virtualenvr#   r$   Zpip._internal.wheel_builderr%   r&   r'   rÚ   r�   r3   r4   r2   rß   r—   rä   rƒ   r�   r    r¢   r/   r/   r/   r0   Ú<module>   sf   	        	   8&