U
    KQh.                     @   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-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)zext://sys.stdoutzext://sys.stderrc                 C   sr   | j dt | jf t d| j| j|d}tf || _d| j  }t	| j|| _
tt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 r0   ./tmp/pip-build-tlro1kwj/pip/pip/basecommand.py__init__)   s     
zCommand.__init__c                 C   s   t |jrtt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)r3   https)r   	cache_dirr   ospathjoinr5   trusted_hostscertverifyclient_certtimeoutproxyproxiesno_inputauth	prompting)r,   optionsr5   r@   sessionr0   r0   r1   _build_sessionA   s(    

zCommand._build_sessionc                 C   s   | j |S )N)r$   
parse_args)r,   argsr0   r0   r1   rI   e   s    zCommand.parse_argsc                    s  |  |\}}|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dD d tjd d d krtd!tj |jr(d"tjd#< |jrBd$|jtjd%< |jrft sftd& tt zjz*| #||}t$|t%r|W W FS W n: t&k
r } z.tt'| tj(d*dd+ t) W Y W  S d }~X Y n t*t+t,fk
r2 } z,tt'| tj(d*dd+ t- W Y W S d }~X Y n t.k
rz } z*td,| tj(d*dd+ t- W Y W hS d }~X Y nV t/k
r   td- tj(d*dd+ t- Y W (S    tjd.dd+ t0 Y W S X W 5 |jst|d'ds| j|dt d(|j!d)}t"| W 5 Q R X X t1S )/N   WARNING   r   CRITICALDEBUGINFOFexclude_warningsz pip.utils.logging.MaxLevelFilter)()levelindentz%(message)s)rR   formatz(pip.utils.logging.ColorizedStreamHandlerr   )rS   classstreamfiltersr   )rS   rV   rW   r   z+pip.utils.logging.BetterRotatingFileHandlerz	/dev/nullT)rS   rV   filenamedelayr   )consoleconsole_errorsuser_logr[   r\   r]   )rS   handlersc                 3   s&   | ]}|d  dkrdndifV  qdS )rS   )rP   r   rL   rO   Nr0   ).0r    rS   r0   r1   	<genexpr>   s   zCommand.main.<locals>.<genexpr>)zpip._vendordistlibrequestsurllib3)versiondisable_existing_loggersrX   
formattersr^   rootloggers)rM      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).no_index   )r5   r@   zException information:)exc_infoz	ERROR: %szOperation cancelled by userz
Exception:)2rI   quietverboselogr   loggingrL   r   log_streamslistfilterdictsysversion_infowarningswarnr   Python26DeprecationWarningrC   r9   environexists_actionr;   require_venvr   loggercriticalexitr   disable_pip_version_checkgetattrrH   minr@   r   run
isinstanceintr   strdebugr   r   r	   r   r   r
   KeyboardInterruptr   r   )r,   rJ   rF   
root_levelrG   statusexcr0   r`   r1   maini   s    

?





zCommand.main)F)NN)__name__
__module____qualname__r    r   hiddenrv   r2   rH   rI   r   r0   r0   r0   r1   r   #   s   

$c                   @   s"   e Zd Zedd ZdddZdS )RequirementCommandc              	   C   s  |j D ](}t|d||||dD ]}| | qq|D ]}| tj|d|j|d q4|jD ] }| tj||j|j|d qZd}	|j	D ]*}t|||||dD ]}d}	| | qq|j
| _
|s|js|	sd|i}
|jrd	t|
d
|jd }nd|
 }t| dS )z?
        Marshal cmd line args into a requirement set.
        T)
constraintfinderrF   rG   wheel_cacheN)r"   r   )default_vcsr"   r   F)r   rF   rG   r   r    z^You must give at least one requirement to %(name)s (maybe you meant "pip %(name)s %(links)s"?)rm   )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_linksry   r;   r   warning)requirement_setrJ   rF   r   rG   r    r   rY   reqfound_req_in_fileoptsmsgr0   r0   r1   populate_requirement_set  sd    
   
  
	
  
z+RequirementCommand.populate_requirement_setNc                 C   sR   |j g|j }|jr*tdd| 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_linksrG   platformversionsabiimplementation)	index_urlextra_index_urlsro   r   r   r;   r   r   r   r<   prer   )r,   rF   rG   r   python_versionsr   r   r   r0   r0   r1   _build_package_finder:  s"    z(RequirementCommand._build_package_finder)NNNN)r   r   r   staticmethodr   r   r0   r0   r0   r1   r     s   
7      r   )3r#   
__future__r   ru   r9   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   r0   r0   r0   r1   <module>   s.   
 _