
^V,                 @   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/ Gd d   d e0  Z1 Gd d   d e1  Z2 d 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               @   sa   e  Z d  Z d Z d Z d Z d Z d d d  Z d d d d  Z d	 d
   Z	 d d   Z
 d S)r   NFext://sys.stdoutext://sys.stderrc             C   s   i |  j  d 6d t   |  j f d 6t   d 6d d 6|  j d 6|  j d 6| d	 6} t |   |  _ d
 |  j j   } t j	 |  j |  |  _
 t j t j |  j  } |  j j |  d  S)Nusagez%s %sprog	formatterF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-9m6vxulb/pip/pip/basecommand.py__init__)   s    




zCommand.__init__c             C   s   t  d | j r- t t j j | j d   n d  d | d  k	 rE | n | j d | j  } | j rr | j | _	 n  | j
 r | j
 | _ n  | j s | r | d  k	 r | n | j | _ n  | j r i | j d 6| j d 6| _ n  | j | j _ | S)Ncachehttpretriesinsecure_hosts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                s7  |  j  |  \ } } | j rW | j d k r6 d   n  | j d k rN d   qo d   n | j ri d   n d   t i d d 6d	 d
 6i i d d 6t j d 6d 6d 6i i t d 6d d 6d 6d 6i i   d 6d d 6|  j d d 6d g d 6d d 6d 6i d d 6d d 6|  j d d 6d d 6d 6i d d 6d d 6| j p<d d 6d d 6d d 6d  6d! 6i   d 6t	 t
 d  d d | j r~d  n d  g   d! 6d" 6t   f d# d$   d% d& d' d( g D  d) 6 t j d  d  d: k rt j d+ t j  n  | j r
d, t j d- <n  | j r/d. j | j  t j d/ <n  | j rat   sat j d0  t j t  qan  zty) |  j | |  } t | t  r| SWnDt  k
 r} z/ t j t! |   t j" d1 d2 d t# SWYd  d  } ~ Xn t$ t% t& f k
 r5} z/ t j t! |   t j" d1 d2 d t' SWYd  d  } ~ Xn t( k
 r} z, t j d3 |  t j" d1 d2 d t' SWYd  d  } ~ XnT t) k
 rt j d4  t j" d1 d2 d t' SYn t j d5 d2 d t* SYn XWd  | j+ r2t, | d6 d	  r2|  j- | d7 d d8 t. d9 | j/   } t0 |  Wd  QXn  Xt1 S);N   WARNING   r   CRITICALDEBUGINFOversionFdisable_existing_loggersz pip.utils.logging.MaxLevelFilterz()levelexclude_warningsfiltersz%(message)sformatindent
formattersz(pip.utils.logging.ColorizedStreamHandlerclassr   streamr    consoleconsole_errorsz+pip.utils.logging.BetterRotatingFileHandlerz	/dev/nullfilenameTdelayuser_loghandlersrootc             3   s4   |  ]* } | i   d k r! d n d d 6f Vq d S)rR   r   rN   rQ   rU   N)zINFOzERRORr2   ).0r"   )rU   r2   r3   	<genexpr>   s   
zCommand.main.<locals>.<genexpr>zpip._vendordistlibrequestsurllib3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_indexr7   rB      )rO   rj   )2rK   quietverboser   loggingrN   r   log_streamslog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   statusexcrI   r2   )rU   r3   maini   s    						
	#
				
zCommand.main)r   r   )__name__
__module____qualname__r"   r   hiddenru   r4   rJ   rK   r   r2   r2   r2   r3   r   #   s   $c               @   s.   e  Z d  Z e d d    Z d d   Z d S)RequirementCommandc             C   s  xS | j  D]H } x? t | d d d | d | d | d | D] } |  j |  q; Wq
 Wx6 | D]. } |  j t j | d d | j d |  q] Wx? | j D]4 } |  j t j | d	 | j d | j d |  q Wd
 }	 xS | j	 D]H } x? t | d | d | d | d | D] } d }	 |  j |  qWq W| j
 |  _
 | pK| j pK|	 si | d 6}
 | j rd t |
 d d j | j  } n
 d |
 } t j |  n  d S)z?
        Marshal cmd line args into a requirement set.
        
constraintTfinderrH   rI   wheel_cacheNr$   default_vcsFr"   z^You must give at least one requirement to %(name)s (maybe you meant "pip %(name)s %(links)s"?)linksrm   zLYou 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_linksry   r=   r   warning)requirement_setrL   rH   r   rI   r"   r   r_   reqfound_req_in_fileoptsmsgr2   r2   r3   populate_requirement_set   sF    			"z+RequirementCommand.populate_requirement_setc             C   s~   | j  g | j } | j r> t j d d j |   g  } n  t d | j d | j d | d | j	 d | j
 d | 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   )	index_urlextra_index_urlsrp   r   infor=   r   r   r   r>   prer   )r.   rH   rI   r   r2   r2   r3   _build_package_finder4  s    							z(RequirementCommand._build_package_finderN)r   r   r   staticmethodr   r   r2   r2   r2   r3   r      s   7r   )3r%   
__future__r   rt   r;   rz   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,   ((	