3
[&                 @   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j0e1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j  }tj	| j|| _
tjtj| 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-65viz3iy/pip/pip/_internal/cli/base_command.py__init__0   s    zCommand.__init__c             C   s   t |jrttj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 j|S )N)r%   
parse_args)r-   argsr1   r1   r2   rJ   l   s    zCommand.parse_argsc             C   s  | j |\}}|j|j | _t| j|j|jd |jr@dtj	d< |j
rXdj|j
tj	d< |jr| j rt stjd tjt z,y | j||}t|tr|S W n tk
r } z tjt| tjddd	 tS d }~X n tttfk
r" } z tjt| tjddd	 tS d }~X n tk
r\ } ztjd
| tjddd	 tS d }~X nP t k
r   tj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*j+  X t,S )N)	verbosityno_colorZ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_checkrS   rI   minrA   r   loggingshutdownr   )r-   rK   rG   statusexcZallow_version_checkrH   r1   r1   r2   mainp   sb    







zCommand.main)F)NN)__name__
__module____qualname__r!   r   hiddenr[   r3   rI   rJ   rn   r1   r1   r1   r2   r   *   s   

$c               @   s"   e Zd Zedd ZdddZdS )RequirementCommandc          	   C   s2  x<|j D ]2}x,t|d||||dD ]}d|_| j| q"W qW x.|D ]&}	t|	d|j|d}d|_| j| qDW x.|jD ]$}	t|	|j|d}d|_| j| qvW x:|jD ]0}x*t|||||dD ]}d|_| j| qW qW |j	| _	|p|jp|js.d|i}
|j
r"tdt|
dj|j
d	 ntd
|
 dS )z?
        Marshal cmd line args into a requirement set.
        T)
constraintfinderrG   rH   wheel_cacheN)r#   rv   )ru   rG   rH   rv   r!   z^You must give at least one requirement to %(name)s (maybe you meant "pip %(name)s %(links)s"?)rP   )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   ru   rH   r!   rv   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jddj| 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_urlsrS   r\   rd   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)ro   rp   rq   staticmethodr   r   r1   r1   r1   r2   rs      s   : rs   )6r$   
__future__r   rj   logging.configr'   r:   r^   Zpip._internal.clir   Zpip._internal.cli.parserr   r   Z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   Z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__	getLoggerro   r\   objectr   rs   r1   r1   r1   r2   <module>   s4   
 