a
    <Bìj3  ã                   @  sÂ   d Z ddlm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 ddlmZmZ ddlmZmZ dd	lmZ dd
lmZmZ ddgZddœdd„Zdddœdd„Zdddœdd„ZdS )z<A single place for constructing and exposing the main parseré    )ÚannotationsN)Úescape)Úget_runnable_pip)Ú
cmdoptions)ÚConfigOptionParserÚUpdatingDefaultsHelpFormatter)Úcommands_dictÚget_similar_commands)ÚCommandError)Úget_pip_versionÚget_progÚcreate_main_parserÚparse_commandr   )Úreturnc                  C  sl   t ddtƒ dtƒ d�} |  ¡  tƒ | _t tj| ¡}|  	|¡ d| _
dgdd„ t ¡ D ƒ }d	 |¡| _| S )
z1Creates and returns the main parser for pip's CLIz
%prog <command> [options]FÚglobal)ÚusageÚadd_help_optionÚ	formatterÚnameÚprogTÚ c                 S  s(   g | ] \}}d |d›dt |jƒ› �‘qS )z[optparse.longargs]Z27z[/] )r   Úsummary)Ú.0r   Úcommand_info© r   ú\/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pip/_internal/cli/main_parser.pyÚ
<listcomp>+   s   ÿz&create_main_parser.<locals>.<listcomp>Ú
)r   r   r   Údisable_interspersed_argsr   Úversionr   Úmake_option_groupÚgeneral_groupÚadd_option_groupÚmainr   ÚitemsÚjoinÚdescription)ÚparserÚgen_optsr&   r   r   r   r      s"    û

þÚstrz
str | None)Úpythonr   c                 C  sN   t j | ¡rJt j | ¡rFdD ]&}t j | |¡}t j |¡r|  S qn| S d S )N)z
bin/pythonzScripts/python.exe)ÚosÚpathÚexistsÚisdirr%   )r*   ZexeÚpyr   r   r   Úidentify_python_interpreter4   s    r0   z	list[str]ztuple[str, list[str]])Úargsr   c              
   C  sŽ  t ƒ }| | ¡\}}|jrÆdtjvrÆt|jƒ}|d u rFtd|j› �ƒ‚|tƒ g}| | ¡ dtjd< d}zt	 
|¡}|j}W n> t	jtfyº } z td|› d|› �ƒ‚W Y d }~n
d }~0 0 t |¡ |jrðtj |j¡ tj tj¡ t ¡  |�r|d dk�r"t|ƒdk�r"| ¡  t ¡  |d }	|	tv�rpt|	ƒ}
d	|	› d
�g}|
�rb| d|
› d
�¡ td |¡ƒ‚| d d … }| |	¡ |	|fS )NZ_PIP_RUNNING_IN_SUBPROCESSz$Could not locate Python interpreter Ú1r   zFailed to run pip under z: Úhelpé   zunknown command "ú"zmaybe you meant "z - )r   Ú
parse_argsr*   r+   Úenvironr0   r
   r   ÚextendÚ
subprocessÚrunÚ
returncodeÚSubprocessErrorÚOSErrorÚsysÚexitr   ÚstdoutÚwriteÚlinesepÚlenÚ
print_helpr   r	   Úappendr%   Úremove)r1   r'   Úgeneral_optionsÚ	args_elseÚinterpreterÚpip_cmdr;   ÚprocÚexcÚcmd_nameÚguessÚmsgÚcmd_argsr   r   r   r   G   sJ    	

ÿþ



*
"

)Ú__doc__Ú
__future__r   r+   r9   r>   Zpip._vendor.rich.markupr   Úpip._internal.build_envr   Zpip._internal.clir   Úpip._internal.cli.parserr   r   Úpip._internal.commandsr   r	   Úpip._internal.exceptionsr
   Úpip._internal.utils.miscr   r   Ú__all__r   r0   r   r   r   r   r   Ú<module>   s   