3
[/R                 @   sn  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 ej1e2Z3G dd deZ4dd Z5dd Z6d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)WheelBuilderc                   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                sp  t t| j|| | j}|jtj  |jtj  |jtj  |jtj	  |jtj
  |jd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td |jdddd dd |jdddd dd |jtj  |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(d) |jd*dd&d+d, |jd-dd.d'd/d) |jd0dd1d'd2d) |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d3| | jjd3| d S )4Nz-tz--target
target_dirdirzInstall 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_truezInstall 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.))r   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upgradezUpgrade 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-compilez.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_binaryZprefer_binaryno_cleanrequire_hashesprogress_barmake_option_groupindex_groupparserinsert_option_group)selfargskwr3   
index_opts)	__class__ ?/tmp/pip-install-65viz3iy/pip/pip/_internal/commands/install.pyr2   A   s    	zInstallCommand.__init__c           .   C   sD  t j| d}|jr|j}|jr0tjj|j|_t j|dd |j	rN|j	g}nd }tjj|j
|_
|jpjg }|jr|jrtdt rtd|jd |jd tdd	}|jrd|_tjj|j|_tjj|jrtjj|j rtd
|j  |jd|j  |jpg }| j| }| j|||j||j|jd}	|jpJ|j }
t|j |j!}|j rt"|j  rt#j$d|j  d |_ t% }t|j|
ddj}t&|j'|j d}z4y| j(||||	|| j)| t*|j|j
d d |j+|j,|d}t-||	|||j||j.|j/|j0|j|j1d}|j2| t3|j4dd t5rn|j rnt6|	||g g d}|j7|j8j9 |dd |j:|}|j/ o|j;}|r| j<| |j=}|jrd}t>||||j?|j|j|j@||jd	}tA|j|j|j?|j|j1d}tBjC|}tD|tEjFdd}g }xZ|D ]R}|j)}y$tG|j)|d}|r<|d| 7 }W n tHk
rT   Y nX |j| qW djI|}|rt#jJd| W nd tKk
r } z*| jLd k}tM|||j}t#jN||d! tOS d }~X n tPk
r   d|_ Y nX W d |js|jQ  |jR  X W d Q R X W d Q R X W d Q R X |jr@| jS|j||j |S )"Nzto-satisfy-onlyT)Zcheck_targetzVCan 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<   zThe 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   )deleterU   )rG   Zcheck_supported_wheels)r>   src_dirdownload_dirwheel_download_dirrH   build_isolationreq_tracker)preparerfinderrW   wheel_cacher"   r)   r,   ignore_dependenciesr@   r-   isolatedpip)Zmodifying_pip)build_optionsrC   )rW   autobuildingF)roothomeprefix	pycompiler/   r"   )userrh   rg   ri   rc   name)key)working_set- zSuccessfully installed %s   )exc_info)Tr   check_install_build_globalr(   r)   r>   ospathabspathZcheck_dist_restrictionr;   rZ   rB   r"   r'   r	   r   r
   appendr   r   r-   existsisdircreaterC   _build_session_build_package_finderr:   r=   r<   rF   r   	cache_dirformat_controlr   loggerwarningr   r   rG   populate_requirement_setrl   r   rH   r]   r   r,   rb   r@   isolated_moderesolver   has_requirementwheelr   buildr5   valuesget_installation_orderr0   _warn_about_conflictsr/   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) rM   rV   rN   r)   rX   rB   target_temp_dirrC   rW   r`   build_deletera   r^   	directoryrequirement_setr_   resolverwb
to_installshould_warn_about_conflictsr/   	installedZlib_locationsrn   reqsitemsreqiteminstalled_versionr   show_tracebackmessagerR   rR   rS   run   s    




















(zInstallCommand.runc                sp  t | g }|T td|jd}|d }|d }|d }tjj|rP|j| tjj|rn||krn|j| tjj|r|j| x|D ]}	xtj|	D ]}
|	|krtjj||
 t fdd|d d D rqtjj||
}tjj|rD|st	j
d	| qtjj|r t	j
d
| qtjj|r:tj| n
tj| tjtjj|	|
| qW qW W d Q R X d S )N )rh   purelibplatlibdatac             3   s   | ]}|j  V  qd S )N)
startswith).0s)ddirrR   rS   	<genexpr>  s    z4InstallCommand._handle_target_dir.<locals>.<genexpr>rq   zKTarget directory %s already exists. Specify --upgrade to force replacement.zTarget directory %s already exists and is a link. Pip will not automatically replace links, please remove if replacement is desired.)r   r   ru   rt   rx   rw   listdirr   anyr   r   islinkry   shutilrmtreeremovemove)rM   r   r   r(   lib_dir_listschemepurelib_dirplatlib_dirdata_dirlib_dirr   target_item_dirrR   )r   rS   r     sJ    




z!InstallCommand._handle_target_dirc          	   C   s   t |\}}|\}}x>|D ]6}|| d }x$|| D ]}tjd|||d  q4W qW xD|D ]<}|| d }x*|| D ]\}	}
}tjd||||	|
 qtW qZW d S )Nr   z*%s %s requires %s, which is not installed.rq   zF%s %s has requirement %s, but you'll have %s %s which is incompatible.)r   r   critical)rM   r   package_set	_dep_infomissingconflictingproject_nameversion
dependencydep_namedep_versionr   rR   rR   rS   r     s    

z$InstallCommand._warn_about_conflicts)__name__
__module____qualname____doc__rl   usagesummaryr2   r   r   r   __classcell__rR   rR   )rQ   rS   r   *   s     Q8r   c              O   s   t d| |}|d |d gS )Nr   r   r   )r   )r   )rN   kwargsr   rR   rR   rS   r     s    r   c             C   s   g }|j d |s,|j d |j t|  n
|j d |d  d7  < | jtjkrd}d}|st|j|d|j g n
|j | |j d	 d
j|j 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: .rq   
z"Consider using the `--user` optionzCheck the permissionsz or z.
r   r   )rw   strerrnoEACCESextendlowerr   strip)r   r   using_user_sitepartsuser_option_partpermissions_partrR   rR   rS   r     s"    




r   )7
__future__r   r   loggingr   rt   r   optparser   pip._vendorr   pip._internal.cacher   Zpip._internal.clir   Zpip._internal.cli.base_commandr   Z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   Z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   ImportError	getLoggerr   r   r   r   r   rR   rR   rR   rS   <module>   sB   

   J