B
    Uvg&                 @   sF  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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mZmZmZ dd	lmZ dd
lmZ ddlm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+m,Z, e,rddl-m.Z. dgZ/e0e1Z2G dd de3Z4G dd de4Z5dS )z(Base Command class, and related routines    )absolute_importN)
cmdoptions)ConfigOptionParserUpdatingDefaultsHelpFormatter)ERRORPREVIOUS_BUILD_DIR_ERRORSUCCESSUNKNOWN_ERRORVIRTUALENV_NOT_FOUND)
PipSession)
BadCommandCommandErrorInstallationErrorPreviousBuildDirErrorUninstallationError)PackageFinder)running_under_virtualenv)install_req_from_editableinstall_req_from_line)parse_requirements)setup_logging)get_prognormalize_path)pip_version_check)MYPY_CHECK_RUNNING)Optional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   NFc             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 r1   ?/tmp/pip-install-r_9ig3yj/pip/pip/_internal/cli/base_command.py__init__0   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)r4   https)r   	cache_dirr   ospathjoinr6   trusted_hostscertverifyclient_certtimeoutproxyproxiesno_inputauth	prompting)r-   optionsr6   rA   sessionr1   r1   r2   _build_sessionH   s    

zCommand._build_sessionc             C   s   | j |S )N)r%   
parse_args)r-   argsr1   r1   r2   rJ   l   s    zCommand.parse_argsc             C   s  |  |\}}|j|j | _t| j|j|jd |jr@dtj	d< |j
rXd|j
tj	d< |jr~| js~t s~td tt z2y | ||}t|tr|S W n tk
r } z tt| tjddd	 tS d }~X Y n tttfk
r$ } z tt| tjddd	 tS d }~X Y n tk
r` } ztd
| tjddd	 tS d }~X Y nP t k
r   td tjddd	 tS  t!k
r   tjddd	 t"S X W d t#|do|j$p|j% }|r| j&|dt'd|j(d}| t)|| W d Q R X t*+  X t,S )N)	verbosityno_coloruser_log_file1PIP_NO_INPUT PIP_EXISTS_ACTIONz2Could not find an activated virtualenv (required).zException information:T)exc_infoz	ERROR: %szOperation cancelled by userz
Exception:no_indexr      )r6   rA   )-rJ   verbosequietrL   r   rM   logrD   r:   environexists_actionr<   require_venvignore_require_venvr   loggercriticalsysexitr
   run
isinstanceintr   strdebugr   r   r   r   r   r   KeyboardInterruptBaseExceptionr	   hasattrdisable_pip_version_checkrT   rI   minrA   r   loggingshutdownr   )r-   rK   rG   statusexcallow_version_checkrH   r1   r1   r2   mainp   sb    







zCommand.main)F)NN)__name__
__module____qualname__r!   r   hiddenr\   r3   rI   rJ   rp   r1   r1   r1   r2   r   *   s   

$c               @   s"   e Zd Zedd ZdddZdS )RequirementCommandc          	   C   s6  x<|j D ]2}x,t|d||||dD ]}d|_| | q"W qW x.|D ]&}	t|	d|j|d}d|_| | qDW x.|jD ]$}	t|	|j|d}d|_| | qvW x:|jD ]0}x*t|||||dD ]}d|_| | qW qW |j	| _	|s2|js2|js2d|i}
|j
r&tdt|
d|j
d	 ntd
|
 dS )z?
        Marshal cmd line args into a requirement set.
        T)
constraintfinderrG   rH   wheel_cacheN)r#   rx   )rw   rG   rH   rx   r!   z^You must give at least one requirement to %(name)s (maybe you meant "pip %(name)s %(links)s"?)rQ   )linkszLYou must give at least one requirement to %(name)s (see "pip help %(name)s"))constraintsr   	is_directadd_requirementr   isolated_mode	editablesr   requirementsrequire_hashes
find_linksr   dictr<   )requirement_setrK   rG   rw   rH   r!   rx   filename
req_to_addreqoptsr1   r1   r2   populate_requirement_set   sJ    	
z+RequirementCommand.populate_requirement_setNc             C   sV   |j g|j }|jr*tdd| g }t|j|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_linksrH   platformversionsabiimplementationprefer_binary)	index_urlextra_index_urlsrT   r]   re   r<   r   r   r   r=   prer   r   )r-   rG   rH   r   python_versionsr   r   r   r1   r1   r2   _build_package_finder   s"    z(RequirementCommand._build_package_finder)NNNN)rq   rr   rs   staticmethodr   r   r1   r1   r1   r2   ru      s   : ru   )6r$   
__future__r   rk   logging.configr'   r:   r_   Zpip._internal.clir   pip._internal.cli.parserr   r   pip._internal.cli.status_codesr   r   r   r	   r
   pip._internal.downloadr   pip._internal.exceptionsr   r   r   r   r   pip._internal.indexr   pip._internal.locationsr   pip._internal.req.constructorsr   r   Zpip._internal.req.req_filer   pip._internal.utils.loggingr   pip._internal.utils.miscr   r   pip._internal.utils.outdatedr   pip._internal.utils.typingr   typingr   __all__	getLoggerrq   r]   objectr   ru   r1   r1   r1   r2   <module>   s4   
 