U
    ;»{j±!  ã                   @   sP  d 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
m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 dd
lmZmZmZmZ ddlmZ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/m0Z0 ddl1m2Z2 dgZ3e 4e5¡Z6G dd„ deƒZ7dS )z(Base Command class, and related routinesé    N)ÚValues)ÚListÚOptionalÚTuple)Úreconfigure)Ú	traceback)Ú
cmdoptions)ÚCommandContextMixIn)ÚConfigOptionParserÚUpdatingDefaultsHelpFormatter)ÚERRORÚPREVIOUS_BUILD_DIR_ERRORÚUNKNOWN_ERRORÚVIRTUALENV_NOT_FOUND)Ú
BadCommandÚCommandErrorÚDiagnosticPipErrorÚInstallationErrorÚNetworkConnectionErrorÚPreviousBuildDirError)Ú
deprecated)Úcheck_path_owner)ÚBrokenStdoutLoggingErrorÚsetup_logging)Úget_progÚnormalize_path)ÚTempDirectoryTypeRegistry)Úglobal_tempdir_managerÚtempdir_registry)Úrunning_under_virtualenvÚCommandc                       sØ   e Zd ZU dZeed< dZeed< deeeddœ‡ fdd„Zdd	œd
d„Z	e
ddœdd„Ze
ee edœdd„Zee
ee edœdd„Zee ee
ee f dœdd„Zee edœdd„Zee edœdd„Z‡  ZS )r    Ú ÚusageFÚignore_require_venvN)ÚnameÚsummaryÚisolatedÚreturnc              	      sŽ   t ƒ  ¡  || _|| _t| jtƒ › d|› �tƒ d|| j|d�| _	d | _
| j ¡ › d�}t | j	|¡| _t tj| j	¡}| j	 |¡ |  ¡  d S )Nú F)r"   ÚprogÚ	formatterÚadd_help_optionr$   Údescriptionr&   z Options)ÚsuperÚ__init__r$   r%   r
   r"   r   r   Ú__doc__Úparserr   Ú
capitalizeÚoptparseÚOptionGroupÚcmd_optsr   Úmake_option_groupÚgeneral_groupÚadd_option_groupÚadd_options)Úselfr$   r%   r&   Úoptgroup_nameÚgen_opts©Ú	__class__© ú?/tmp/pip-install-zsn1f9xv/pip/pip/_internal/cli/base_command.pyr.   1   s*    
ù
þzCommand.__init__©r'   c                 C   s   d S ©Nr>   )r9   r>   r>   r?   r8   O   s    zCommand.add_options)Úoptionsr'   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)r9   rB   r>   r>   r?   Úhandle_pip_version_checkR   s    z Command.handle_pip_version_check)rB   Úargsr'   c                 C   s   t ‚d S rA   )ÚNotImplementedError)r9   rB   rG   r>   r>   r?   Úrun[   s    zCommand.run)Úlevel_numberrB   rG   r'   c              
      s  t dœ‡ ‡‡fdd„}ˆjr.tjdd� |ƒ S z|ƒ }t|t ƒsDt‚|W S  tk
r– } z.tjd|ddid� tj	d	dd
� t
 W Y ¢S d }~X Y �nn tk
rÜ } z(t t|ƒ¡ tj	d	dd
� t W Y ¢S d }~X Y �n( tttfk
�r( } z(t t|ƒ¡ tj	d	dd
� t
 W Y ¢S d }~X Y nÜ tk
�rl } z&t d|¡ tj	d	dd
� t
 W Y ¢S d }~X Y n˜ tk
�r¬   tdtjd� |tjk�r¤tjtjd� t
 Y S  tk
�rÜ   t d¡ tj	d	dd
� t
 Y S  tk
�r   tjddd
� t Y S X d S )Nr@   c                	      s"   zˆ ˆˆ ¡W ¢S ˆ  ˆ¡ X d S rA   )rF   rI   r>   ©rG   rB   r9   r>   r?   Ú
_inner_run_   s    z(Command._run_wrapper.<locals>._inner_runT)Zshow_localsz%sZrich)ÚextrazException information:)Úexc_infoz ERROR: Pipe to stdout was broken)ÚfilezOperation cancelled by userz
Exception:)ÚintZ
debug_modeÚrich_tracebackÚinstallÚ
isinstancerE   r   ÚloggerÚerrorÚdebugr   r   ÚcriticalÚstrr   r   r   r   r   r   ÚprintÚsysÚstderrÚloggingÚDEBUGr   Ú	print_excÚKeyboardInterruptÚBaseExceptionr   )r9   rJ   rB   rG   rL   ÚstatusÚexcr>   rK   r?   Ú_run_wrapper^   sP    ý
zCommand._run_wrapper)rG   r'   c                 C   s   | j  |¡S rA   )r0   Ú
parse_args©r9   rG   r>   r>   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 rA   )r\   ÚshutdownZmain_contextÚ_mainre   r>   r>   r?   Úmain›   s    
$zCommand.mainc                 C   sP  |   tƒ ¡| _|   tƒ ¡ |  |¡\}}|j|j | _t|jd� t	| j|j|j
d�}t|jƒttjƒ@ }|r„t dd t|ƒ¡¡ |jr¨dtjkr¨t d¡ t t¡ |jr¸dtjd< |jrÐd	 |j¡tjd
< |jrö| jsötƒ söt d¡ t t¡ |j �r*t!|j ƒ|_ t"|j ƒ�s*t d|j ¡ d |_ |j#�rBt$ddddd� |  %|||¡S )N)Úno_color)Ú	verbosityri   Úuser_log_filez/The following features are always enabled: %s. z, Z_PIP_RUNNING_IN_SUBPROCESSzAThe --python option must be placed before the pip subcommand nameÚ1ÚPIP_NO_INPUTr(   ÚPIP_EXISTS_ACTIONz2Could not find an activated virtualenv (required).zêThe 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 should use sudo's -H flag.z*--no-python-version-warning is deprecated.z"to remove the flag as it's a no-opz25.1ib3  )ÚreasonÚreplacementÚgone_inÚissue)&Úenter_contextr   r   rd   ÚverboseÚquietrj   r   ri   r   ÚlogÚsetZfeatures_enabledr   ZALWAYS_ENABLED_FEATURESrT   ÚwarningÚjoinÚsortedÚpythonÚosÚenvironrW   rZ   Úexitr   Úno_inputÚexists_actionÚrequire_venvr#   r   r   Ú	cache_dirr   r   Zno_python_version_warningr   rc   )r9   rG   rB   rJ   Zalways_enabled_featuresr>   r>   r?   rg   ¢   s^    ý
ÿþ
ÿ



úüzCommand._main)F)Ú__name__Ú
__module__Ú__qualname__r"   rX   Ú__annotations__r#   Úboolr.   r8   r   rF   r   rP   rI   rc   r   rd   rh   rg   Ú__classcell__r>   r>   r<   r?   r    -   s   
	9 )8r/   r\   Úlogging.configr2   r|   rZ   r   r   Útypingr   r   r   Zpip._vendor.richr   rQ   Zpip._internal.clir   Z!pip._internal.cli.command_contextr	   Úpip._internal.cli.parserr
   r   Úpip._internal.cli.status_codesr   r   r   r   Úpip._internal.exceptionsr   r   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   ZTempDirRegistryr   r   Úpip._internal.utils.virtualenvr   Ú__all__Ú	getLoggerrƒ   rT   r    r>   r>   r>   r?   Ú<module>   s2    
