Re@sdZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZerddlmZmZmZmZd 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 rodYnXt}tt}g}d}x!|D]}||kr|}PqW|dk r|dkrtj d|dkoj d  }|rg}j } xRt d d D]A} | j j | r| j |ddkr|j| j qW|rx|D]} t| qpWtj dt|} xW| jjD]I} | jtjkrx.| j| jD]} |j| | jfqWqWd d|d|dDfdd|D}fdd|D}t||| jj}|rt|}dd|D}x$|D]H}|d}|dr|ddddkr|d7}t|qWndd|jD}|j|jtj|}j d r^xd|D],} | jtjkr+|| j| j7}q+Wn-t|||}|rtt|}tdjfdd|Dtj ddS)z?Entry Point for completion of main and subcommand options. PIP_AUTO_COMPLETEN COMP_WORDS COMP_CWORDhelpshow uninstall- local_onlyTcSs#g|]}|jddqS)=r)split).0xr/builddir/build/BUILDROOT/alt-python35-pip-20.2.4-5.el8.x86_64/opt/alt/python35/lib/python3.5/site-packages/pip/_internal/cli/autocompletion.py Hs z autocomplete..cs.g|]$\}}|kr||fqSrr)rrv) prev_optsrrrIs cs1g|]'\}}|jr||fqSr) startswith)rkr)currentrrrKs cSsg|]}|dfqS)rr)rpathrrrrTs rz--rcSsg|]}|jqSr) option_list)rirrrr^s  cs%g|]}|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(dSx|D]}|jtjkrJq/xtt|jdD]]}||djdd|kr`|j stdd|jjdDr`|jSq`Wq/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|tjsCdStjjfddtj|D}x|D]}tjj||}tjjtjj||}|dkrtjj |r|Vq~tjj |r~tjj|dVq~WdS)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 Nc3s0|]&}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   " _