B
    Kkd1                 @   s  d Z ddlmZ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	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-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3 e3rjddl4m5Z5m6Z6m7Z7m8Z8 ddlm9Z9 ddl:m;Z; ddl<m=Z= dgZ>e?e@ZAG dd deBZCG dd deCZDdS )z(Base Command class, and related routines    )absolute_importprint_functionN)
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)
deprecated)BrokenStdoutLoggingErrorsetup_logging)get_prognormalize_pathredact_password_from_url)pip_version_check)MYPY_CHECK_RUNNING)OptionalListTupleAny)Values)
WheelCache)RequirementSetCommandc               @   sH   e Zd ZdZdZdZdZdddZ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 r;   ?/tmp/pip-install-gxxfd9b7/pip/pip/_internal/cli/base_command.py__init__8   s    zCommand.__init__c             C   s   t d S )N)NotImplementedError)r7   optionsargsr;   r;   r<   runQ   s    zCommand.runc             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)rB   https)r   	cache_dirr   ospathjoinrD   trusted_hostscertverifyclient_certtimeoutproxyproxiesno_inputauth	prompting)r7   r?   rD   rO   sessionr;   r;   r<   _build_sessionU   s    

zCommand._build_sessionc             C   s   | j |S )N)r/   
parse_args)r7   r@   r;   r;   r<   rW   z   s    zCommand.parse_argsc       	      C   s  |  |\}}|j|j | _t| j|j|jd}tjd d dkrRt	dd dd n8tjd d dkrd}t
 d	kr|d
| }t	|d d d |jrdtjd< |jrd|jtjd< |jr| jst std tt zry | ||}t|tr|S W nL 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 n t$k
r   t%dtj&d |t'j(krt)j*tj&d t"S  t+k
r&   td tjddd t"S  t,k
rH   tjddd t-S X W d t.|doh|j/pf|j0 }|r| j1|dt2d|j3d}| t4|| W d Q R X t'5  X t6S )N)	verbosityno_coloruser_log_file   )      zPython 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won't be maintained after March 2019 (cf PEP 429).z19.2)replacementgone_in)r[      z9A future version of pip will drop support for Python 2.7.CPythonzPython 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. 1PIP_NO_INPUT PIP_EXISTS_ACTIONz2Could not find an activated virtualenv (required).zException information:T)exc_infoz	ERROR: %sz ERROR: Pipe to stdout was broken)filezOperation cancelled by userz
Exception:no_indexr      )rD   rO   )7rW   verbosequietrX   r   rY   logsysversion_infor   platformpython_implementationrR   rH   environexists_actionrJ   require_venvignore_require_venvr   loggercriticalexitr   rA   
isinstanceintr   strdebugr   r   r   r   r   r   r   printstderrloggingDEBUG	traceback	print_excKeyboardInterruptBaseExceptionr
   hasattrdisable_pip_version_checkrh   rV   minrO   r   shutdownr	   )	r7   r@   r?   level_numbermessagestatusexcallow_version_checkrU   r;   r;   r<   main   s    








zCommand.main)F)NN)__name__
__module____qualname__r+   r'   hiddenrt   r=   rA   rV   rW   r   r;   r;   r;   r<   r&   2   s   

%c               @   s"   e Zd Zedd ZdddZdS )RequirementCommandc          	   C   sB  x<|j D ]2}x,t|d||||dD ]}d|_| | q"W qW x2|D ]*}	t|	d|j|j|d}d|_| | qDW x2|jD ](}	t|	|j|j|d}d|_| | qzW x>|j	D ]4}x.t||||||jdD ]}d|_| | qW qW |j
| _
|s>|js>|j	s>d|i}
|jr2tdt|
d|jd	 ntd
|
 dS )z?
        Marshal cmd line args into a requirement set.
        T)
constraintfinderr?   rU   wheel_cacheN)r-   
use_pep517r   )r   r?   rU   r   r   r+   z^You must give at least one requirement to %(name)s (maybe you meant "pip %(name)s %(links)s"?)rd   )linkszLYou must give at least one requirement to %(name)s (see "pip help %(name)s"))constraintsr   	is_directadd_requirementr   isolated_moder   	editablesr   requirementsrequire_hashes
find_linksr   dictrJ   )requirement_setr@   r?   r   rU   r+   r   filename
req_to_addreqoptsr;   r;   r<   populate_requirement_set   sP    
z+RequirementCommand.populate_requirement_setNc             C   s\   |j g|j }|jr4tddd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,c             s   s   | ]}t |V  qd S )N)r   ).0urlr;   r;   r<   	<genexpr>E  s    z;RequirementCommand._build_package_finder.<locals>.<genexpr>)r   format_control
index_urlsrK   allow_all_prereleasesrU   ro   versionsabiimplementationprefer_binary)	index_urlextra_index_urlsrh   ru   r{   rJ   r   r   r   rK   prer   )r7   r?   rU   ro   python_versionsr   r   r   r;   r;   r<   _build_package_finder4  s$    z(RequirementCommand._build_package_finder)NNNN)r   r   r   staticmethodr   r   r;   r;   r;   r<   r      s
   G   r   )Er.   
__future__r   r   r~   logging.configr1   rH   ro   rm   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.deprecationr   pip._internal.utils.loggingr   r   pip._internal.utils.miscr   r   r   pip._internal.utils.outdatedr   pip._internal.utils.typingr   typingr   r    r!   r"   r#   pip._internal.cacher$   Zpip._internal.req.req_setr%   __all__	getLoggerr   ru   objectr&   r   r;   r;   r;   r<   <module>   s@   
 >