3
LY.                 @   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   b/private/var/folders/7d/20zwc49s3kn54d3vgq8bd4640000gn/T/pip-build-an2lx5zf/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pddddd|t	t
d dd|jrd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+ rt,|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   zPython 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| qW qW |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.   
 _