3 Bu_@sdZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZerxddlmZmZmZmZd d Zd d Zd dZdS)zBLogic that powers autocompletion installed by ``pip completion``. N)chain)create_main_parser) commands_dictcreate_command)get_installed_distributions)MYPY_CHECK_RUNNING)AnyIterableListOptionalc sdtjkrdStjdjdd}ttjd}y||dWntk rZdYnXt}tt}g}d}x|D]}||krx|}PqxW|dk r>|dkrtj d|dkoj d  }|r6g}j } x}|d}|dr.|ddddkr.|d7}t|qWndd|jD}|j|jtj|}j d rxN|D]$} | jtjkrv|| j| j7}qvWn t|||}|rtt|}tdjfdd|Dtj ddS)z?Entry Point for completion of main and subcommand options. PIP_AUTO_COMPLETEN COMP_WORDS COMP_CWORDhelpshow uninstall-T) local_onlycSsg|]}|jddqS)=r)split).0xr/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-1.el7.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/cli/autocompletion.py Hsz autocomplete..cs g|]\}}|kr||fqSrr)rrv) prev_optsrrrIscs"g|]\}}|jr||fqSr) startswith)rkr)currentrrrKscSsg|] }|dfqS)rr)rpathrrrrTsrz--rcSsg|] }|jqSr) option_list)rirrrr^s csg|]}|jr|qSr)r)rr)r!rrrms)rr) osenvironrint IndexErrorrlistrsysexitrlowerrkeyappendprintrparseroption_list_allroptparse SUPPRESS_HELP _long_opts _short_optsnargsget_path_completion_typeauto_complete_paths option_groupsr$r from_iterablejoin)cwordscwordr2 subcommandsoptionssubcommand_namewordshould_list_installed installedlcdist subcommandoptopt_strcompletion_typepathsoption opt_labeloptsflattened_optsr)r!rr autocompletes~               rQcCs|dks||djd r dSxt|D]l}|jtjkr8q&xXt|jdD]F}||djdd|krH|j stdd|jjdDrH|jSqHWq&WdS) aLGet 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#rN/rrcss|]}|dkVqdS)r"filedirN)r"rSrTr)rrrrr sz+get_path_completion_type..)rrr4r5strrmetavarany)r>r?rOrIorrrr9qs    r9c#stjj|\}tjj|}tj|tjs.dStjjfddtj|D}xh|D]`}tjj||}tjjtjj||}|dkrtjj |r|VqXtjj |rXtjj|dVqXWdS)aoIf ``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`)i :return: A generator of regular files and/or directories Nc3s$|]}tjj|jr|VqdS)N)r'r"normcaser)rr)filenamerrrUsz&auto_complete_paths..rTr) r'r"rabspathaccessR_OKrZlistdirr=isfileisdir)r!rK directory current_path file_listfrI comp_filer)r[rr:s     r:)__doc__r4r'r, itertoolsrpip._internal.cli.main_parserrpip._internal.commandsrrpip._internal.utils.miscrpip._internal.utils.typingrtypingrr r r rQr9r:rrrrs    _