a
    ñ»j  ã                   @  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 ddlmZmZ dd	lmZ d
dœdd„Zdddddœdd„Zddddœdd„ZdS )zALogic that powers autocompletion installed by ``pip completion``.é    )ÚannotationsN)ÚIterable)Úchain)ÚAny)Úcreate_main_parser)Úcommands_dictÚcreate_command)Úget_default_environmentÚNone)Úreturnc                    sH  dt jvrdS t j d¡r&t j d¡s*dS t jd  ¡ dd… ‰tt jd ƒ} zˆ| d  ‰ W n tyt   d‰ Y n0 tƒ }ttƒ}g }d}ˆD ]}||v r�|} q¦q�|du�r |dkrÂt	 
d¡ ˆ  d¡ oÔ|d	v }|�r*tƒ }ˆ  ¡ ‰‡‡fd
d„|jdd�D ƒ}|�r*|D ]}	t|	ƒ �qt	 
d¡ ˆ  d¡ �o>|dk}
|
�rjtˆ dƒD ]}t|ƒ �qPt	 
d¡ t|ƒ}|jjD ]2‰ˆjtjk�rz|‡fdd„ˆjˆj D ƒ7 }�qzdd„ ˆd| d … D ƒ‰‡fdd„|D ƒ}‡ fdd„|D ƒ}tˆ| |jjƒ}|�rtˆ |ƒ}dd„ |D ƒ}|D ]>}|d }|d �rR|d dd… dk�rR|d7 }t|ƒ �qt‡fdd„| ¡ D ƒƒ�s:| ¡ D ]}| ˆ ¡�r‚t|ƒ �q‚nšdd„ |jD ƒ}| |j¡ t  |¡}ˆ  d¡�rþ|D ]$‰ˆjtjk�rÖ|ˆjˆj 7 }�qÖn tˆ| |ƒ}|�rttˆ |ƒƒ}td !‡ fdd„|D ƒ¡ƒ t	 
d¡ dS )z:Entry Point for completion of main and subcommand options.ÚPIP_AUTO_COMPLETENÚ
COMP_WORDSÚ
COMP_CWORDé   Ú Úhelpú-)ÚshowÚ	uninstallc                   s0   g | ](}|j  ˆ¡r|j ˆ d d… vr|j ‘qS )r   N)Úcanonical_nameÚ
startswith)Ú.0Údist)ÚcwordsÚlc© úFE:\soccer\ml_env\Lib\site-packages\pip/_internal/cli/autocompletion.pyÚ
<listcomp>8   s   ýz autocomplete.<locals>.<listcomp>T)Ú
local_onlyÚinstallÚpathc                   s   g | ]}|ˆ j f‘qS r   )Únargs)r   Úopt_str)Úoptr   r   r   P   s   c                 S  s   g | ]}|  d ¡d ‘qS )ú=r   )Úsplit©r   Úxr   r   r   r   U   ó    c                   s    g | ]\}}|ˆ vr||f‘qS r   r   )r   r'   Úv)Ú	prev_optsr   r   r   V   r(   c                   s"   g | ]\}}|  ˆ ¡r||f‘qS r   ©r   )r   Úkr)   ©Úcurrentr   r   r   X   r(   c                 S  s   g | ]}|d f‘qS )r   r   )r   r    r   r   r   r   c   r(   r   é   z--r$   c                 3  s   | ]}|ˆ v V  qd S ©Nr   )r   Úname)r   r   r   Ú	<genexpr>l   r(   zautocomplete.<locals>.<genexpr>c                 S  s   g | ]
}|j ‘qS r   )Úoption_list)r   Úir   r   r   r   s   r(   ú c                   s   g | ]}|  ˆ ¡r|‘qS r   r+   r&   r-   r   r   r   €   r(   )"ÚosÚenvironÚgetr%   ÚintÚ
IndexErrorr   Úlistr   ÚsysÚexitr   r	   ÚlowerÚiter_installed_distributionsÚprintÚauto_complete_pathsr   ÚparserÚoption_list_allr   ÚoptparseÚSUPPRESS_HELPÚ
_long_optsÚ_short_optsÚget_path_completion_typeÚanyZhandler_mapÚoption_groupsÚappendr3   r   Úfrom_iterableÚjoin)ÚcwordrB   ÚsubcommandsÚoptionsÚsubcommand_nameÚwordÚshould_list_installedÚenvÚ	installedr   Úshould_list_installablesr    Ú
subcommandÚcompletion_typeÚpathsÚoptionÚ	opt_labelÚhandler_nameÚoptsÚflattened_optsr   )r.   r   r   r#   r*   r   Úautocomplete   s˜    




þ
ÿ

ÿý
 
r_   z	list[str]r9   zIterable[Any]z
str | None)r   rN   r]   r   c                 C  s–   |dk s| |d    d¡sdS |D ]n}|jtjkr4q"t|ƒ d¡D ]L}| |d   d¡d |krB|jr€tdd„ |j d¡D ƒƒrB|j    S qBq"dS )	aL  Get the type of path completion (``file``, ``dir``, ``path`` or None)

    :param cwords: same as the environmental variable ``COMP_WORDS``
    :param cword: same as the environmental variable ``COMP_CWORD``
    :param opts: The available options to check
    :return: path completion type (``file``, ``dir``, ``path`` or None)
    r/   r   Nú/r$   r   c                 s  s   | ]}|d v V  qdS ))r    ÚfileÚdirNr   r&   r   r   r   r2   •   s   z+get_path_completion_type.<locals>.<genexpr>)r   r   rD   rE   Ústrr%   ÚmetavarrI   )r   rN   r]   r#   Úor   r   r   rH   „   s    

ÿrH   rc   zIterable[str])r.   rX   r   c                 #  s¼   t j | ¡\}‰ t j |¡}t  |t j¡s.dS t j ˆ ¡‰ ‡ fdd„t  |¡D ƒ}|D ]`}t j ||¡}t j t j ||¡¡}|dkršt j 	|¡rš|V  qVt j 
|¡rVt j |d¡V  qVdS )at  If ``completion_type`` is ``file`` or ``path``, list all regular files
    and directories starting with ``current``; otherwise only list directories
    starting with ``current``.

    :param current: The word to be completed
    :param completion_type: path completion type(``file``, ``path`` or ``dir``)
    :return: A generator of regular files and/or directories
    Nc                 3  s$   | ]}t j |¡ ˆ ¡r|V  qd S r0   )r6   r    Únormcaser   r&   ©Úfilenamer   r   r2   ¬   s   z&auto_complete_paths.<locals>.<genexpr>rb   r   )r6   r    r%   ÚabspathÚaccessÚR_OKrf   ÚlistdirrM   ÚisfileÚisdir)r.   rX   Ú	directoryÚcurrent_pathÚ	file_listÚfr#   Ú	comp_filer   rg   r   rA   œ   s    	
ÿrA   )Ú__doc__Ú
__future__r   rD   r6   r<   Úcollections.abcr   Ú	itertoolsr   Útypingr   Úpip._internal.cli.main_parserr   Úpip._internal.commandsr   r   Úpip._internal.metadatar	   r_   rH   rA   r   r   r   r   Ú<module>   s   s