
§|j†.  ã               @   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-5c7ija6t/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é   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_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,   ((	Þ