a Re@sdZddlZddlZddlZddlmZddlmZmZm Z m Z ddl m Z ddl mZmZddlmZddd d Ze eeeee ed d d ZeeeedddZdS)zBLogic that powers autocompletion installed by ``pip completion``. N)chain)AnyIterableListOptional)create_main_parser) commands_dictcreate_command)get_default_environment)returncsdtjvrdStjdddttjd}z|dWntyXdYn0t}tt}g}d}D]}||vrt|}qqt|dur|dkrt d d o|d v}|r t } fd d |j d d D}|r |D] } t| qt dt|} | jjD]8} | jtjkr| j| jD]} || | jfq:qdd d|dDfdd |D}fdd |D}t|| jj} | rt| }dd |D}|D]>}|d}|dr|ddddkr|d7}t|qndd |jD}||jt|} drf|D]$} | jtjkr>|| j| j7}q>n t||} | rtt| }tdfdd |Dt ddS)z:Entry Point for completion of main and subcommand options.PIP_AUTO_COMPLETEN COMP_WORDS COMP_CWORDhelp-)show uninstallcs0g|](}|jr|jddvr|jqS)rN)canonical_name startswith).0dist)cwordslc/builddir/build/BUILDROOT/alt-python39-pip-21.3.1-2.el8.x86_64/opt/alt/python39/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py 2s z autocomplete..T) local_onlycSsg|]}|ddqS)=r)splitrxrrrrFcs g|]\}}|vr||fqSrr)rr"v) prev_optsrrrGr#cs"g|]\}}|r||fqSrr)rkr$currentrrrIr#cSsg|] }|dfqS)rr)rpathrrrrTr#rz--rcSsg|] }|jqSr) option_list)rirrrr^r# csg|]}|r|qSrr&r!r(rrrkr#) osenvironr int IndexErrorrlistrsysexitrr loweriter_installed_distributionsprintr parseroption_list_allroptparse SUPPRESS_HELP _long_opts _short_optsappendnargsget_path_completion_typeauto_complete_paths option_groupsr,r from_iterablejoin)cwordr9 subcommandsoptionssubcommand_namewordshould_list_installedenv installedr subcommandoptopt_strcompletion_typepathsoption opt_labeloptsflattened_optsr)r)rrr%r autocompletes~                rW)rrFrUr cCs|dks||ddsdS|D]n}|jtjkr4q"t|dD]L}||ddd|krB|jrtdd|jdDrB|jSqBq"dS) 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|]}|dvVqdS))r*filedirNrr!rrr sz+get_path_completion_type..)rrr;r<strr metavarany)rrFrUrOorrrrAos   rA)r)rQr c#stj|\}tj|}t|tjs.dStjfddt|D}|D]`}tj||}tjtj||}|dkrtj |r|VqVtj |rVtj|dVqVdS)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$|]}tj|r|VqdS)N)r/r*normcaserr!filenamerrr[sz&auto_complete_paths..rZr) r/r*r abspathaccessR_OKr`listdirrEisfileisdir)r)rQ directory current_path file_listfrO comp_filerrarrBs     rB)__doc__r;r/r4 itertoolsrtypingrrrrpip._internal.cli.main_parserrpip._internal.commandsrr pip._internal.metadatar rWr\r1rArBrrrrs   a