3
zYði†.  ã               @   s,  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 ddl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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%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ dgZ,ej-e.ƒZ/G dd„ de0ƒZ1G dd„ de1ƒZ2dS )z(Base Command class, and related routinesé    )Úabsolute_importN)Ú
cmdoptions)ÚPackageFinder)Úrunning_under_virtualenv)Ú
PipSession)Ú
BadCommandÚInstallationErrorÚUninstallationErrorÚCommandErrorÚPreviousBuildDirError)Úlogging_dictConfig)ÚConfigOptionParserÚUpdatingDefaultsHelpFormatter)ÚInstallRequirementÚparse_requirements)ÚSUCCESSÚERRORÚUNKNOWN_ERRORÚVIRTUALENV_NOT_FOUNDÚPREVIOUS_BUILD_DIR_ERROR)ÚdeprecationÚget_progÚnormalize_path)ÚIndentingFormatter)Úpip_version_checkÚ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   NFúext://sys.stdoutúext://sys.stderrc             C   sr   | j dtƒ | jf tƒ d| j| j|dœ}tf |Ž| _d| jjƒ  }tj	| j|ƒ| _
tjtj| 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© r2   ú./tmp/pip-build-ue6tjl93/pip/pip/basecommand.pyÚ__init__)   s    zCommand.__init__c             C   s˜   t |jrttj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)r5   Úhttps)r   Ú	cache_dirr   ÚosÚpathÚjoinr7   Útrusted_hostsÚcertÚverifyÚclient_certÚtimeoutÚproxyÚproxiesÚno_inputÚauthÚ	prompting)r.   Úoptionsr7   rB   Úsessionr2   r2   r3   Ú_build_sessionA   s    

zCommand._build_sessionc             C   s   | j j|ƒS )N)r&   Ú
parse_args)r.   Úargsr2   r2   r3   rK   e   s    zCommand.parse_argsc                sÚ  | j |ƒ\}}|jr8|jdkr"d‰ |jdkr2d‰ qHd‰ n|jrDd‰ nd‰ ˆ }|jrVd}tddd	d
tjdœidtddœiˆ d| jd d	gddœdd| jd ddœdd|jpªddddœdœ|t	t
d dd|jrÌdnd gƒƒdœt‡ fdd„d2D ƒƒd"œƒ tjd d… d3k�rtjd$tjƒ |j�r(d%tjd&< |j�rBd'j|jƒtjd(< |j�rftƒ �sftjd)ƒ tjtƒ �z$y"| j||ƒ}t|tƒ�rˆ|S W � nü t k
�rÊ } z tjt!|ƒƒ tj"d*dd+� t#S d }~X nÀ t$t%t&fk
�r } z tjt!|ƒƒ tj"d*dd+� t'S d }~X n~ t(k
�rF } ztjd,|ƒ tj"d*dd+� t'S d }~X nD t)k
�rr   tjd-ƒ tj"d*dd+� t'S    tjd.dd+� t*S W d |j+ �rÔt,|d/dƒ �rÔ| j-|dt.d0|j/ƒd1��}t0|ƒ W d Q R X X t1S )4Né   ÚWARNINGé   r   ÚCRITICALÚDEBUGÚINFOFÚexclude_warningsz pip.utils.logging.MaxLevelFilter)z()ÚlevelÚindentz%(message)s)z()Úformatz(pip.utils.logging.ColorizedStreamHandlerr   )rT   ÚclassÚstreamÚfiltersr    )rT   rW   rX   r    z+pip.utils.logging.BetterRotatingFileHandlerz	/dev/nullT)rT   rW   ÚfilenameÚdelayr    )ÚconsoleÚconsole_errorsÚuser_logr\   r]   r^   )rT   Úhandlersc             3   s&   | ]}|d ˆ dkrdndifV  qdS )rT   rR   r   rN   rQ   N)rR   r   r2   )Ú.0r"   )rT   r2   r3   ú	<genexpr>¯   s   
zCommand.main.<locals>.<genexpr>úpip._vendorÚdistlibÚrequestsÚurllib3)ÚversionÚdisable_existing_loggersrY   Ú
formattersr_   ÚrootÚloggersé   z�Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6Ú1ÚPIP_NO_INPUTú ÚPIP_EXISTS_ACTIONz2Could not find an activated virtualenv (required).zException information:)Úexc_infoz	ERROR: %szOperation cancelled by userz
Exception:Úno_indexé   )r7   rB   )rb   rc   rd   re   )rO   rk   )2rK   ÚquietÚverboseÚlogr   ÚloggingrN   r   Úlog_streamsÚlistÚfilterÚdictÚsysÚversion_infoÚwarningsÚwarnr   ÚPython26DeprecationWarningrE   r;   ÚenvironÚexists_actionr=   Úrequire_venvr   ÚloggerÚcriticalÚexitr   ÚrunÚ
isinstanceÚintr   ÚstrÚdebugr   r   r	   r   r   r
   ÚKeyboardInterruptr   Údisable_pip_version_checkÚgetattrrJ   ÚminrB   r   r   )r.   rL   rH   Ú
root_levelÚstatusÚexcrI   r2   )rT   r3   Úmaini   s°    










zCommand.main)r   r   )F)NN)Ú__name__Ú
__module__Ú__qualname__r"   r   Úhiddenrw   r4   rJ   rK   r’   r2   r2   r2   r3   r   #   s   

$c               @   s"   e Zd Zedd„ ƒZddd„ZdS )ÚRequirementCommandc          	   C   s"  x6|j D ],}x&t|d||||d�D ]}| j|ƒ q"W qW x&|D ]}| jtj|d|j|d�ƒ q>W x*|jD ] }| jtj||j|j|d�ƒ qhW d}	x8|j	D ].}x(t|||||d�D ]}d}	| j|ƒ q°W q˜W |j
| _
|pÞ|jpÞ|	�sd|i}
|j�rd	t|
d
j|jƒd� }nd|
 }tj|ƒ dS )z?
        Marshal cmd line args into a requirement set.
        T)Ú
constraintÚfinderrH   rI   Úwheel_cacheN)r$   rš   )Údefault_vcsr$   rš   F)r™   rH   rI   rš   r"   z^You must give at least one requirement to %(name)s (maybe you meant "pip %(name)s %(links)s"?)rn   )ÚlinkszLYou must give at least one requirement to %(name)s (see "pip help %(name)s"))Úconstraintsr   Úadd_requirementr   Ú	from_lineÚisolated_modeÚ	editablesÚfrom_editabler›   ÚrequirementsÚrequire_hashesÚ
find_linksrz   r=   rƒ   Úwarning)Úrequirement_setrL   rH   r™   rI   r"   rš   rZ   ÚreqÚfound_req_in_fileÚoptsÚmsgr2   r2   r3   Úpopulate_requirement_set  sF    
z+RequirementCommand.populate_requirement_setNc             C   sR   |j g|j }|jr*tjddj|ƒƒ g }t|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_linksrI   ÚplatformÚversionsÚabiÚimplementation)Ú	index_urlÚextra_index_urlsrq   rƒ   rŠ   r=   r   r¥   r®   r>   Úprer±   )r.   rH   rI   r²   Úpython_versionsr´   rµ   r¯   r2   r2   r3   Ú_build_package_finder:  s     z(RequirementCommand._build_package_finder)NNNN)r“   r”   r•   Ústaticmethodr¬   rº   r2   r2   r2   r3   r—     s   8 r—   )3r%   Ú
__future__r   rv   r;   r{   r(   r}   Úpipr   Ú	pip.indexr   Úpip.locationsr   Úpip.downloadr   Úpip.exceptionsr   r   r	   r
   r   Ú
pip.compatr   Úpip.baseparserr   r   Úpip.reqr   r   Úpip.status_codesr   r   r   r   r   Ú	pip.utilsr   r   r   Úpip.utils.loggingr   Úpip.utils.outdatedr   Ú__all__Ú	getLoggerr“   rƒ   Úobjectr   r—   r2   r2   r2   r3   Ú<module>   s.   
 _