
}_.                 @   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   d |  j  d d t   |  j f d t   d d d |  j d |  j d	 | i } t |   |  _ d
 |  j j   } t j	 |  j |  |  _
 t j t j |  j  } |  j j |  d  S)Nusageprogz%s %s	formatteradd_help_optionF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-3_sjtvrs/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 ro | j | _	 | j
 r | j
 | _ | j s | r | d  k	 r | n | j | _ | j r d | j d | j i | _ | 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                s  |  j  |  \ } } | j rT | j d k r3 d   | j d k rK d   ql d   n | j rf d   n d     } | j r d } t d d d	 d
 d d d d d t j i i d d d t d d i i d d d   d d d |  j d d d g d d i d d d d d d |  j d d d i d d d d d d | j p7d d  d! d d i i d" d | d t	 t
 d  d d | j rsd n d  g   i d# t   f d$ d%   d& d' d( d) g D  i  t j d  d  d: k rt j d+ t j  | j rd, t j d- <| j rd. j | j  t j d/ <| j rDt   sDt j d0  t j t  zty) |  j | |  } t | t  ro| SWnDt  k
 r} z/ t j t! |   t j" d1 d2 d! t# SWYd  d  } ~ Xn t$ t% t& f k
 r} z/ t j t! |   t j" d1 d2 d! t' SWYd  d  } ~ Xn t( k
 rc} 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+ rt, | d6 d
  r|  j- | d7 d d8 t. d9 | j/   } t0 |  Wd  QRXXt1 S);N   WARNING   r   CRITICALDEBUGINFOversiondisable_existing_loggersFfiltersexclude_warningsz()z pip.utils.logging.MaxLevelFilterlevel
formattersindentformatz%(message)shandlersconsoleclassz(pip.utils.logging.ColorizedStreamHandlerstreamr   r    console_errorsuser_logz+pip.utils.logging.BetterRotatingFileHandlerfilenamez	/dev/nulldelayTrootloggersc             3   s3   |  ]) } | d    d k r! d n d i f Vq d S)rW   rR   r   rN   rQ   N)rR   r   r2   ).0r"   )rW   r2   r3   	<genexpr>   s   
zCommand.main.<locals>.<genexpr>zpip._vendordistlibrequestsurllib3   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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   )rW   r3   maini   s    									

				
zCommand.main)r   r   )__name__
__module____qualname__r"   r   hiddenrv   r4   rJ   rK   r   r2   r2   r2   r3   r   #   s   $c               @   s:   e  Z d  Z e d d    Z d d d d 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d | i }
 | j rd t |
 d d j | j  } n
 d |
 } t j |  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   ra   reqfound_req_in_fileoptsmsgr2   r2   r3   populate_requirement_set  sF    			"z+RequirementCommand.populate_requirement_setNc             C   s   | j  g | j } | j r; t j d d j |   g  } t d | j d | j d | d | j	 d | j
 d | j d	 | d
 | d | d | 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_urlsrp   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)r   r   r   staticmethodr   r   r2   r2   r2   r3   r     s   8r   )3r%   
__future__r   ru   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,   ((	