B
    ãUvgrU  ã               @   sz  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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 d d	l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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, d dl-m.Z. yd dl/Z/W n e0k
r>   dZ/Y nX d dlm1Z1 e 2e3¡Z4G dd„ deƒZ5dd„ Z6dd„ Z7dS )é    )Úabsolute_importN)ÚSUPPRESS_HELP)Úpkg_resources)Ú
WheelCache)Ú
cmdoptions)ÚRequirementCommand)ÚERROR)ÚCommandErrorÚInstallationErrorÚPreviousBuildDirError)Údistutils_schemeÚvirtualenv_no_global)Úcheck_install_conflicts)ÚRequirementPreparer)ÚRequirementSetÚinstall_given_reqs)ÚRequirementTracker)ÚResolver)Úcheck_path_owner)Ú
ensure_dirÚget_installed_versionÚ(protect_pip_from_modification_on_windows)ÚTempDirectory)ÚWheelBuilder)Úrunning_under_virtualenvc                   sD   e Zd ZdZdZdZdZ‡ fdd„Zdd„ Z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                s‚  t t| ƒj||Ž | j}| t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t 	¡ ¡ | t 
¡ ¡ |jddddd dd | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ |jddd	d
d |jddd	td |jdddd dd |jdddd dd |jddd	dd | t ¡ ¡ | t ¡ ¡ |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 | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ |jd'd	d(d)d*d+ |jd,d-d(d.d/ |jd0d-d1d)d2d+ |jd3d-d4d)d5d+ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ | t ¡ ¡ t tj| j¡}| j d6|¡ | j d6|¡ d S )7Nz-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_truea  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.)r   Úactionr"   z	--no-userÚuse_system_locationz--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--systemzDInstall using the system scheme (overrides --user on Debian systems)z-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).)r   r!   Úchoicesr"   z--force-reinstallÚforce_reinstallz;Reinstall all packages even if they are already up-to-date.z-Iz--ignore-installedÚignore_installedz5Ignore the installed packages (reinstalling instead).z	--compileÚcompileTz'Compile Python source files to bytecode)r%   r   r!   r"   z--no-compileÚstore_falsez.Do not compile Python source files to bytecode)r%   r   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   ) Úsuperr   Ú__init__Úcmd_optsÚ
add_optionr   ÚrequirementsÚconstraintsÚno_depsÚpreÚeditableÚplatformÚpython_versionÚimplementationÚabir   Ú	build_dirÚsrcÚignore_requires_pythonÚno_build_isolationÚinstall_optionsÚglobal_optionsÚ	no_binaryÚonly_binaryÚprefer_binaryÚno_cleanÚrequire_hashesÚprogress_barÚmake_option_groupÚindex_groupÚparserÚinsert_option_group)ÚselfÚargsÚkwr5   Ú
index_opts)Ú	__class__© ú?/tmp/pip-install-r_9ig3yj/pip/pip/_internal/commands/install.pyr4   B   sÒ    	zInstallCommand.__init__c              C   s‚  t  |¡ d}|jr|j}|jr0tj |j¡|_t j|dd |j	rN|j	g}nd }|j
s‚|js‚|js‚|js‚tƒ s‚t ¡ dkr‚d|_
|jrŽd|_
tj |j¡|_|jp¦g }|j
rÞ|jr¼tdƒ‚tƒ rÊtdƒ‚| d¡ | d	¡ td
d}|jrFd|_tj |j¡|_tj |j¡r.tj |j¡s.tdƒ‚| ¡  | d|j ¡ |jpPg }|  |¡ }| j|||j||j|j d}	|j!pˆ|j }
t"|j#|j$ƒ}|j#rÂt%|j#ƒsÂt& 'd|j#¡ d |_#t(ƒ Š}t|j|
ddl}t)|j*|j d}z6yÈ|  +||||	|| j,|¡ t-|j|jd d |j.|j/|d}t0||	|||j
||j1|j2|j3|j|j4d}| 5|¡ t6| 7d¡d t8rª|j#rªt9|	||g g d}|j:|j; <¡ |dd | =|¡}|j2 oÂ|j>}|rÔ|  ?|¡ |j@}|jræd}tA||||jB|j|j|jC||j
d	}tD|j
|j|jB|j|j4d}tE F|¡}tG|tH Id¡d}g }xZ|D ]R}|j,}y$tJ|j,|d}|rx|d| 7 }W n tKk
r   Y nX | |¡ qLW d L|¡}|r¾t& Md |¡ W nf tNk
r
 } z*| jOd!k}tP|||j
ƒ}t&jQ||d" tRS d }~X Y n tSk
r&   d|_!‚ Y nX W d |j!sD| T¡  | U¡  X W d Q R X W d Q R X W d Q R X |jr~|  V|j||j¡ |S )#Nzto-satisfy-onlyT)Úcheck_targetr   FzVCan 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=Útarget)Úkindz=Target path exists but is not a directory, will not continue.z--home=)ÚoptionsÚsessionr<   Úpython_versionsr?   r>   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.r   )ÚdeleterY   )rJ   Úcheck_supported_wheels)r@   Úsrc_dirÚdownload_dirÚwheel_download_dirrK   Úbuild_isolationÚreq_tracker)ÚpreparerÚfinderr[   Úwheel_cacher#   r*   r-   Úignore_dependenciesrB   r.   ÚisolatedÚpip)Úmodifying_pip)Úbuild_optionsrE   )r[   Úautobuilding)ÚrootÚhomeÚprefixÚ	pycompiler1   r#   )Úuserrn   rm   ro   rh   Úname)Úkey)Úworking_setú-ú zSuccessfully installed %sé   )Úexc_info)Wr   Úcheck_install_build_globalr)   r*   r@   ÚosÚpathÚabspathÚcheck_dist_restrictionr=   r#   r(   r   r&   r   Úgeteuidr_   rD   r	   r   r
   Úappendr   r.   ÚexistsÚisdirÚcreaterE   Ú_build_sessionÚ_build_package_finderr<   r?   r>   rI   r   Ú	cache_dirÚformat_controlr   ÚloggerÚwarningr   r   rJ   Úpopulate_requirement_setrr   r   rK   rb   r   r-   rg   rB   Úisolated_modeÚresolver   Úhas_requirementÚwheelr   Úbuildr7   ÚvaluesÚget_installation_orderr2   Ú_warn_about_conflictsr1   r   r'   r/   Úget_lib_location_guessesr   Ú
WorkingSetÚsortedÚoperatorÚ
attrgetterr   Ú	ExceptionÚjoinÚinfoÚEnvironmentErrorÚ	verbosityÚcreate_env_error_messageÚerrorr   r   Úcleanup_filesÚcleanupÚ_handle_target_dir) rP   rZ   rQ   r*   r\   rD   Útarget_temp_dirrE   r[   re   Úbuild_deleterf   rc   Ú	directoryÚrequirement_setrd   ÚresolverÚwbÚ
to_installÚshould_warn_about_conflictsr1   Ú	installedÚlib_locationsrt   ÚreqsÚitemsÚreqÚitemÚinstalled_versionr   Úshow_tracebackÚmessagerU   rU   rV   ÚrunÝ   s,   




















(zInstallCommand.runc          	      sp  t |ƒ g }|T td|jd}|d }|d }|d }tj |¡rP| |¡ tj |¡rn||krn| |¡ tj |¡r„| |¡ xÜ|D ]Ô}	xÎt |	¡D ]À}
|	|krÔtj ||
¡‰ t‡ fdd„|d d… D ƒƒrÔqštj ||
¡}tj |¡rD|st	 
d	|¡ qštj |¡r t	 
d
|¡ qštj |¡r:t |¡ n
t |¡ t tj |	|
¡|¡ qšW qŠW W d Q R X d S )NÚ )rn   ÚpurelibÚplatlibÚdatac             3   s   | ]}|  ˆ ¡V  qd S )N)Ú
startswith)Ú.0Ús)ÚddirrU   rV   ú	<genexpr>Ð  s    z4InstallCommand._handle_target_dir.<locals>.<genexpr>éÿÿÿÿ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{   rz   r€   r   Úlistdirr˜   Úanyr‡   rˆ   Úislinkr   ÚshutilÚrmtreeÚremoveÚmove)rP   r   r¡   r)   Úlib_dir_listÚschemeÚpurelib_dirÚplatlib_dirÚdata_dirÚlib_dirr®   Útarget_item_dirrU   )rº   rV   r    ¶  sJ    




z!InstallCommand._handle_target_dirc          
   C   sž   t |ƒ\}}|\}}x>|D ]6}|| d }x$|| D ]}t d|||d ¡ q4W qW xD|D ]<}|| d }x*|| D ]\}	}
}t d||||	|
¡ qtW qZW d S )Nr   z*%s %s requires %s, which is not installed.rw   zF%s %s has requirement %s, but you'll have %s %s which is incompatible.)r   r‡   Úcritical)rP   r§   Úpackage_setÚ	_dep_infoÚmissingÚconflictingÚproject_nameÚversionÚ
dependencyÚdep_nameÚdep_versionr­   rU   rU   rV   r‘   î  s    

z$InstallCommand._warn_about_conflicts)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rr   ÚusageÚsummaryr4   r²   r    r‘   Ú__classcell__rU   rU   )rT   rV   r   +   s     Z8r   c              O   s   t d| ž|Ž}|d |d gS )Nr³   r´   rµ   )r³   )r   )rQ   ÚkwargsrÅ   rU   rU   rV   r’     s    r’   c             C   sš   g }|  d¡ |s,|  d¡ |  t| ƒ¡ n
|  d¡ |d  d7  < | jtjkrˆd}d}|st| |d| ¡ g¡ n
|  |¡ |  d	¡ d
 |¡ ¡ d S )z{Format an error message for an EnvironmentError

    It may occur anytime during the execution of the install command.
    z5Could not install packages due to an EnvironmentErrorz: Ú.r¼   Ú
z"Consider using the `--user` optionzCheck the permissionsz or z.
r³   )r   ÚstrÚerrnoÚEACCESÚextendÚlowerr˜   Ústrip)r   r°   Úusing_user_siteÚpartsÚuser_option_partÚpermissions_partrU   rU   rV   rœ   
  s"    




rœ   )8Ú
__future__r   rà   Úloggingr•   rz   rÀ   Úoptparser   Úpip._vendorr   Úpip._internal.cacher   Zpip._internal.clir   Úpip._internal.cli.base_commandr   Úpip._internal.cli.status_codesr   Úpip._internal.exceptionsr	   r
   r   Úpip._internal.locationsr   r   Úpip._internal.operations.checkr   Ú pip._internal.operations.preparer   Zpip._internal.reqr   r   Úpip._internal.req.req_trackerr   Úpip._internal.resolver   Úpip._internal.utils.filesystemr   Úpip._internal.utils.miscr   r   r   Úpip._internal.utils.temp_dirr   Úpip._internal.wheelr   r   ÚImportErrorr   Ú	getLoggerrÕ   r‡   r   r’   rœ   rU   rU   rU   rV   Ú<module>   sD   

   ]