B
    ãUvgë&  ã               @   sF  d Z 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mZ ddlmZmZmZmZmZ ddlmZ ddl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 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, e,�rddl-m.Z. dgZ/e 0e1¡Z2G dd„ de3ƒZ4G dd„ de4ƒZ5dS )z(Base Command class, and related routinesé    )Úabsolute_importN)Ú
cmdoptions)ÚConfigOptionParserÚUpdatingDefaultsHelpFormatter)ÚERRORÚPREVIOUS_BUILD_DIR_ERRORÚSUCCESSÚUNKNOWN_ERRORÚVIRTUALENV_NOT_FOUND)Ú
PipSession)Ú
BadCommandÚCommandErrorÚInstallationErrorÚPreviousBuildDirErrorÚUninstallationError)ÚPackageFinder)Úrunning_under_virtualenv)Úinstall_req_from_editableÚinstall_req_from_line)Úparse_requirements)Úsetup_logging)Úget_progÚnormalize_path)Úpip_version_check)ÚMYPY_CHECK_RUNNING)ÚOptionalÚCommandc               @   s@   e Zd ZdZdZdZdZddd„Zddd„Zdd„ Z	d	d
„ Z
dS )r   NFc             C   sr   | j dtƒ | jf tƒ d| j| j|dœ}tf |Ž| _d| j ¡  }t 	| j|¡| _
t tj| j¡}| j |¡ d S )Nz%s %sF)ÚusageÚprogÚ	formatterÚadd_help_optionÚnameÚdescriptionÚisolatedz
%s Options)r   r   r!   r   Ú__doc__r   ÚparserÚ
capitalizeÚoptparseÚOptionGroupÚcmd_optsr   Úmake_option_groupÚgeneral_groupÚadd_option_group)Úselfr#   Ú	parser_kwÚoptgroup_nameÚgen_opts© r1   ú?/tmp/pip-install-r_9ig3yj/pip/pip/_internal/cli/base_command.pyÚ__init__0   s    zCommand.__init__c             C   s˜   t |jrttj |jd¡ƒnd |d k	r*|n|j|jd�}|jrF|j|_	|j
rT|j
|_|js^|rr|d k	rj|n|j|_|jrˆ|j|jdœ|_|j |j_|S )NÚhttp)ÚcacheÚretriesÚinsecure_hosts)r4   Úhttps)r   Ú	cache_dirr   ÚosÚpathÚjoinr6   Útrusted_hostsÚcertÚverifyÚclient_certÚtimeoutÚproxyÚproxiesÚno_inputÚauthÚ	prompting)r-   Úoptionsr6   rA   Úsessionr1   r1   r2   Ú_build_sessionH   s    

zCommand._build_sessionc             C   s   | j  |¡S )N)r%   Ú
parse_args)r-   Úargsr1   r1   r2   rJ   l   s    zCommand.parse_argsc             C   s  |   |¡\}}|j|j | _t| j|j|jd� |jr@dtj	d< |j
rXd |j
¡tj	d< |jr~| js~tƒ s~t d¡ t t¡ �z2y |  ||¡}t|tƒrž|S W �n tk
rà } z t t|ƒ¡ tjddd	� tS d }~X Y nÐ tttfk
�r$ } z t t|ƒ¡ tjddd	� tS d }~X Y nŒ tk
�r` } zt d
|¡ tjddd	� tS d }~X Y nP t k
�rŒ   t d¡ tjddd	� tS  t!k
�r®   tjddd	� t"S X W d t#|dƒ�oÎ|j$�pÌ|j% }|�r| j&|dt'd|j(ƒd�}|� t)||ƒ W d Q R X t* +¡  X t,S )N)Ú	verbosityÚno_colorÚuser_log_fileÚ1ÚPIP_NO_INPUTú ÚPIP_EXISTS_ACTIONz2Could not find an activated virtualenv (required).zException information:T)Úexc_infoz	ERROR: %szOperation cancelled by userz
Exception:Úno_indexr   é   )r6   rA   )-rJ   ÚverboseÚquietrL   r   rM   ÚlogrD   r:   ÚenvironÚexists_actionr<   Úrequire_venvÚignore_require_venvr   ÚloggerÚcriticalÚsysÚexitr
   ÚrunÚ
isinstanceÚintr   ÚstrÚdebugr   r   r   r   r   r   ÚKeyboardInterruptÚBaseExceptionr	   ÚhasattrÚdisable_pip_version_checkrT   rI   ÚminrA   r   ÚloggingÚshutdownr   )r-   rK   rG   ÚstatusÚexcÚallow_version_checkrH   r1   r1   r2   Úmainp   sb    







zCommand.main)F)NN)Ú__name__Ú
__module__Ú__qualname__r!   r   Úhiddenr\   r3   rI   rJ   rp   r1   r1   r1   r2   r   *   s   

$c               @   s"   e Zd Zedd„ ƒZddd„ZdS )ÚRequirementCommandc          	   C   s6  x<|j D ]2}x,t|d||||d�D ]}d|_|  |¡ q"W qW x.|D ]&}	t|	d|j|d�}d|_|  |¡ qDW x.|jD ]$}	t|	|j|d�}d|_|  |¡ qvW x:|jD ]0}x*t|||||d�D ]}d|_|  |¡ q¾W q¦W |j	| _	|�s2|j�s2|j�s2d|i}
|j
�r&tdt|
d |j
¡d	� ƒ‚ntd
|
 ƒ‚dS )z?
        Marshal cmd line args into a requirement set.
        T)Ú
constraintÚfinderrG   rH   Úwheel_cacheN)r#   rx   )rw   rG   rH   rx   r!   z^You must give at least one requirement to %(name)s (maybe you meant "pip %(name)s %(links)s"?)rQ   )ÚlinkszLYou must give at least one requirement to %(name)s (see "pip help %(name)s"))Úconstraintsr   Ú	is_directÚadd_requirementr   Úisolated_modeÚ	editablesr   ÚrequirementsÚrequire_hashesÚ
find_linksr   Údictr<   )Úrequirement_setrK   rG   rw   rH   r!   rx   ÚfilenameÚ
req_to_addÚreqÚoptsr1   r1   r2   Úpopulate_requirement_setÅ   sJ    	
z+RequirementCommand.populate_requirement_setNc             C   sV   |j g|j }|jr*t dd |¡¡ g }t|j|j||j	|j
|j||||||jd�S )zR
        Create a package finder appropriate to this requirement command.
        zIgnoring indexes: %sú,)r�   Úformat_controlÚ
index_urlsr=   Úallow_all_prereleasesÚprocess_dependency_linksrH   ÚplatformÚversionsÚabiÚimplementationÚprefer_binary)Ú	index_urlÚextra_index_urlsrT   r]   re   r<   r   r�   rŠ   r=   Úprer�   r’   )r-   rG   rH   rŽ   Úpython_versionsr�   r‘   r‹   r1   r1   r2   Ú_build_package_finderþ   s"    z(RequirementCommand._build_package_finder)NNNN)rq   rr   rs   Ústaticmethodrˆ   r—   r1   r1   r1   r2   ru   Ã   s   : ru   )6r$   Ú
__future__r   rk   Úlogging.configr'   r:   r_   Zpip._internal.clir   Úpip._internal.cli.parserr   r   Úpip._internal.cli.status_codesr   r   r   r	   r
   Úpip._internal.downloadr   Úpip._internal.exceptionsr   r   r   r   r   Úpip._internal.indexr   Úpip._internal.locationsr   Úpip._internal.req.constructorsr   r   Zpip._internal.req.req_filer   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   Úpip._internal.utils.outdatedr   Úpip._internal.utils.typingr   Útypingr   Ú__all__Ú	getLoggerrq   r]   Úobjectr   ru   r1   r1   r1   r2   Ú<module>   s4   
 