U
    @vg                     @   sR  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 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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' ddl(m)Z) ddl*m+Z+ ddl,m-Z- e+r.ddl.m/Z/m0Z0m1Z1 ddlm2Z2 dgZ3e4e5Z6G dd deZ7dS )z(Base Command class, and related routines    )absolute_importprint_functionN)
cmdoptions)CommandContextMixIn)ConfigOptionParserUpdatingDefaultsHelpFormatter)ERRORPREVIOUS_BUILD_DIR_ERRORSUCCESSUNKNOWN_ERRORVIRTUALENV_NOT_FOUND)
BadCommandCommandErrorInstallationErrorPreviousBuildDirErrorUninstallationError)
deprecated)check_path_owner)BrokenStdoutLoggingErrorsetup_logging)get_prognormalize_path)global_tempdir_manager)MYPY_CHECK_RUNNING)running_under_virtualenv)ListTupleAny)ValuesCommandc                       sN   e Zd ZdZdZd fdd	Zdd Zdd Zd	d
 Zdd Z	dd Z
  ZS )r   NFc                    s   t t|   | jdt |f t d|| 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)superr   __init__r    r   r   __doc__r$   summaryr   parser
capitalizeoptparseOptionGroupcmd_optsr   make_option_groupgeneral_groupadd_option_group)selfr$   r*   r&   	parser_kwoptgroup_namegen_opts	__class__ B/tmp/pip-unpacked-wheel-gw11q0wt/pip/_internal/cli/base_command.pyr(   6   s&    
zCommand.__init__c                 C   s   t |drtdS )zf
        This is a no-op so that commands by default do not do the pip version
        check.
        no_indexN)hasattrAssertionError)r3   optionsr9   r9   r:   handle_pip_version_checkR   s    z Command.handle_pip_version_checkc                 C   s   t d S N)NotImplementedError)r3   r>   argsr9   r9   r:   run\   s    zCommand.runc                 C   s   | j |S r@   )r+   
parse_argsr3   rB   r9   r9   r:   rD   `   s    zCommand.parse_argsc              
   C   s>   z.|   | |W  5 Q R  W S Q R X W 5 t   X d S r@   )loggingshutdownmain_context_mainrE   r9   r9   r:   maine   s    
$zCommand.mainc              
   C   s  |  t  | |\}}|j|j | _t| j|j|jd}t	j
d d dkrz|jszd}t dkrld| }t|d d d |jrtdd	d
dd |jrdtjd< |jrd|jtjd< |jr| jst std t	t |jrt|j|_t|jstd|j d |_zz*| !||}t"|t#r<|W W S W n t$k
r } z.tt%| tj&ddd t' W Y W RS d }~X Y n> t(t)t*fk
r } z.tt%| tj&ddd t+ W Y W  S d }~X Y n t,k
r* } z*td| tj&ddd t+ W Y W S d }~X Y n t-k
rn   t.dt	j/d |t0j1krbt2j3t	j/d t+ Y W fS  t4k
r   td tj&ddd t+ Y W 2S  t5k
r   tjddd t6 Y W S X W 5 |  | X t7S )N)	verbosityno_coloruser_log_file   )rN      zA future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-supportCPythonzPython 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. )replacementgone_inz<--skip-requirements-regex is unsupported and will be removedzXmanage requirements/constraints files explicitly, possibly generating them from metadataz20.1i  )rQ   rR   issue1PIP_NO_INPUT PIP_EXISTS_ACTIONz2Could not find an activated virtualenv (required).zThe directory '%s' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.zException information:T)exc_infoz%sz ERROR: Pipe to stdout was broken)filezOperation cancelled by userz
Exception:)8enter_contextr   rD   verbosequietrK   r   rL   logsysversion_infono_python_version_warningplatformpython_implementationr   skip_requirements_regexno_inputosenvironexists_actionjoinrequire_venvignore_require_venvr   loggercriticalexitr   	cache_dirr   r   warningr?   rC   
isinstanceintr   strdebugr	   r   r   r   r   r   r   printstderrrF   DEBUG	traceback	print_excKeyboardInterruptBaseExceptionr   r
   )r3   rB   r>   level_numbermessagestatusexcr9   r9   r:   rI   m   s    

 
zCommand._main)F)__name__
__module____qualname__r    rj   r(   r?   rC   rD   rJ   rI   __classcell__r9   r9   r7   r:   r   2   s   
)8r)   
__future__r   r   rF   logging.configr-   re   ra   r^   rw   Zpip._internal.clir   !pip._internal.cli.command_contextr   pip._internal.cli.parserr   r   pip._internal.cli.status_codesr   r	   r
   r   r   pip._internal.exceptionsr   r   r   r   r   pip._internal.utils.deprecationr   pip._internal.utils.filesystemr   pip._internal.utils.loggingr   r   pip._internal.utils.miscr   r   pip._internal.utils.temp_dirr   pip._internal.utils.typingr   pip._internal.utils.virtualenvr   typingr   r   r   r   __all__	getLoggerr   rk   r   r9   r9   r9   r:   <module>   s4   
