3
zYði•F  ã               @   s   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yd dlZW n e	k
r`   dZY nX 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 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!m"Z" d dlm#Z# ej$e%ƒZ&G dd„ deƒZ'dd„ Z(dS )é    )Úabsolute_importN)ÚRequirementSet)ÚRequirementCommand)Úvirtualenv_no_globalÚdistutils_scheme)ÚInstallationErrorÚCommandErrorÚPreviousBuildDirError)Ú
cmdoptions)Ú
ensure_dirÚget_installed_version)ÚBuildDirectory)ÚRemovedInPip10Warning)Úcheck_path_owner)Ú
WheelCacheÚWheelBuilder)Úrunning_under_virtualenvc                   s4   e Zd ZdZdZdZdZ‡ fdd„Zdd„ Z‡  Z	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.
    Úinstalla%  
      %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> ...zInstall packages.c          
      sP  t t| ƒj||Ž d}tƒ r d}tjƒ dkr0d}| j}|jtj	ƒ ƒ |jtj
ƒ ƒ |jtjƒ ƒ |jtjƒ ƒ |jddddd dd	� |jd
dddddd dd	� |jtjƒ ƒ |jdddddd� |jdddddgdd� |jddddd� |jdd d!d|d"d#� |jtjƒ ƒ |jtjƒ ƒ |jtjƒ ƒ |jtjƒ ƒ |jd$d%d|d&d#� |jd'd%d(d)d� |jd*d+dd,d� |jd-d.dd d/d	� |jd0d1dd d2d	� |jd3dd4dd5d6� |jd7d(d4d8d9� |jtjƒ ƒ |jtjƒ ƒ |jtjƒ ƒ |jtjƒ ƒ |jtjƒ ƒ |jtjƒ ƒ |jtjƒ ƒ tjtj| jƒ}| jjd|ƒ | jjd|ƒ d S ):NTFr   z-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-dz
--downloadz--download-dirz--download-directoryÚdownload_dirz`Download packages into <dir> instead of installing them, regardless of what's already installed.z-Uz	--upgradeÚupgradeÚ
store_truez‚Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used.)r   Úactionr   z--upgrade-strategyÚupgrade_strategyÚeagerzonly-if-neededa3  Determines how dependency upgrading should be handled. "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).)r   r   Úchoicesr   z--force-reinstallÚforce_reinstallzKWhen upgrading, reinstall all packages even if they are already up-to-date.z-Iz--ignore-installedÚignore_installedz5Ignore the installed packages (reinstalling instead).)r   r   r   r   z--userÚuse_user_sitea  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.)  On Debian systems, this is the default when running outside of a virtual environment and not as root.z--systemÚstore_falsezDInstall using the system scheme (overrides --user on Debian systems)z--eggÚas_eggzâInstall packages as eggs, not 'flat', like pip normally does. This option is not about installing *from* eggs. (WARNING: Because this option overrides pip's normal install logic, requirements files may not behave as expected.)z--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	--compileÚcompilezCompile py files to pyc)r   r   r   r   z--no-compilezDo not compile py files to pyc)r   r   r   )Úsuperr   Ú__init__r   ÚosÚgeteuidÚcmd_optsÚ
add_optionr
   ÚconstraintsÚeditableÚrequirementsÚ	build_dirÚsrcÚignore_requires_pythonÚno_depsÚinstall_optionsÚglobal_optionsÚ	use_wheelÚno_use_wheelÚ	no_binaryÚonly_binaryÚpreÚno_cleanÚrequire_hashesÚmake_option_groupÚindex_groupÚparserÚinsert_option_group)ÚselfÚargsÚkwÚdefault_userr.   Ú
index_opts)Ú	__class__© ú3/tmp/pip-build-ue6tjl93/pip/pip/commands/install.pyr+   7   sÊ    zInstallCommand.__init__c          &   C   sÜ  t j|ƒ t j|ƒ |jr&tjdtƒ |jr8tjdtƒ |jrJtjdtƒ |j	r\tjdtƒ |j
rttjdtƒ d|_|jrŠtjj|jƒ|_tjj|jƒ|_|jp¢g }|jrÚ|jr¸tdƒ‚tƒ rÆtdƒ‚|jd	ƒ |jd
ƒ d }|j�r<d|_tjƒ }tjj|jƒ|_tjj|jƒ�r.tjj|jƒ �r.tdƒ‚|jd| ƒ |j�pFg }| j|ƒ��P}| j||ƒ}|j �pn|j }t!|j"|j#ƒ}	|j"�rªt$|j"ƒ �rªt%j&d|j"ƒ d |_"t'|j|d���à}
t(|
|j|j
|j)|j*|j|j|j+|j,|j-|j|||j.|j/|	|j0d�}| j1|||||| j2|	ƒ |j3�s$d S �z\�y6|j
�sFt4 �sF|j" �rR|j5|ƒ nt6||g g d�}|j7dd� |j
�s6|j8|||j9|jd� t:|j||j9|j|j/d�}t;|j<t=j>dƒd�}g }xX|D ]P}|j2}y"t?|j2|ƒ}|�rî|d| 7 }W n t@k
�r   Y nX |j|ƒ �qÄW djA|ƒ}|�r^t%jBd|ƒ n(djAdd„ |jCD ƒƒ}|�r^t%jBd|ƒ W n tDk
�r~   d|_ ‚ Y nX W d |j �s”|jEƒ  X W d Q R X W d Q R X |j�rØtF|jƒ g }tGd|d�d }tGd|d�d }tjj|ƒ�rø|j|ƒ tjj|ƒ�r||k�r|j|ƒ x²|D ]ª}x¢tjH|ƒD ]”}tjjA|j|ƒ}tjj|ƒ�r¬|j)�sjt%j&d |ƒ �q0tjjI|ƒ�rˆt%j&d!|ƒ �q0tjj|ƒ�r¢tJjK|ƒ n
tjL|ƒ tJjMtjjA||ƒ|ƒ �q0W �q W tJjK|ƒ |S )"NzÉ--egg has been deprecated and will be removed in the future. This flag is mutually exclusive with large parts of pip, and actually using it invalidates pip's ability to manage the installation process.z�--allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z“--allow-all-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z‘--allow-unverified has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.z‰pip install --download has been deprecated and will be removed in the future. Pip now has a download command that should be used instead.TzVCan 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--userz	--prefix=z=Target path exists but is not a directory, will not continue.z--home=zÝThe directory '%s' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.)Údelete)r3   Úsrc_dirr   r   r   r&   r#   Úignore_dependenciesr5   r"   r$   r   ÚsessionÚ	pycompileÚisolatedÚwheel_cacher?   )Úbuild_optionsr8   )Úautobuilding)ÚrootÚprefix)ÚuserÚhomerU   rV   rQ   Úname)Úkeyú-ú zSuccessfully installed %sc             S   s   g | ]
}|j ‘qS rJ   )rY   )Ú.0ÚreqrJ   rJ   rK   ú
<listcomp>†  s   z&InstallCommand.run.<locals>.<listcomp>zSuccessfully downloaded %sÚ )rX   ÚpurelibÚplatlibzKTarget 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.)Nr
   Úresolve_wheel_no_use_binaryÚcheck_install_build_globalr&   ÚwarningsÚwarnr   Úallow_externalÚallow_all_externalÚallow_unverifiedr   r#   r3   r,   ÚpathÚabspathrM   r7   r$   r(   r   r   r   Úappendr   ÚtempfileÚmkdtempÚexistsÚisdirr8   Ú_build_sessionÚ_build_package_finderr>   r   Ú	cache_dirÚformat_controlr   ÚloggerÚwarningr   r   r   r   rN   r5   r"   r)   Úisolated_moder?   Úpopulate_requirement_setrY   Úhas_requirementsÚwheelÚprepare_filesr   Úbuildr   r'   Úget_lib_location_guessesÚsortedÚsuccessfully_installedÚoperatorÚ
attrgetterr   Ú	ExceptionÚjoinÚinfoÚsuccessfully_downloadedr	   Úcleanup_filesr   r   ÚlistdirÚislinkÚshutilÚrmtreeÚremoveÚmove)rD   ÚoptionsrE   r7   Útemp_target_dirr8   rO   ÚfinderÚbuild_deleterR   r3   Úrequirement_setÚwbÚpossible_lib_locationsÚreqsÚitemsr^   ÚitemÚinstalled_versionÚ	installedÚ
downloadedÚlib_dir_listÚpurelib_dirÚplatlib_dirÚlib_dirÚtarget_item_dirrJ   rJ   rK   ÚrunÒ   sD   

















zInstallCommand.run)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rY   ÚusageÚsummaryr+   rŸ   Ú__classcell__rJ   rJ   )rI   rK   r       s    r   c              O   s   t d| ž|Ž}|d |d gS )Nr`   ra   rb   )r`   )r   )rE   ÚkwargsÚschemerJ   rJ   rK   r}   Å  s    r}   ))Ú
__future__r   Úloggingr€   r,   rm   r‰   re   rz   ÚImportErrorÚpip.reqr   Úpip.basecommandr   Úpip.locationsr   r   Úpip.exceptionsr   r   r	   Úpipr
   Ú	pip.utilsr   r   Úpip.utils.buildr   Zpip.utils.deprecationr   Úpip.utils.filesystemr   Ú	pip.wheelr   r   r   Ú	getLoggerr    ru   r   r}   rJ   rJ   rJ   rK   Ú<module>   s6   

   (