a *eg@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)returncsdtjvrdStjdr&tjds*dStjdddttjd}z|dWntytdYn0t}tt}g}d}D]}||vr|}qq|dur`|dkrt d d o|d v}|r*t } fd d |jd d D}|r*|D]} t| qt d d o>|dk} | rjtdD]} t| qPt dt|} | jjD]2jtjkrz|fdd jjD7}qzdd d|dDfdd |D}fdd |D}t|| jj} | rt| }dd |D}|D]>}|d}|drR|ddddkrR|d7}t|qndd |jD}||jt|} dr|D]$jtjkr|jj7}qn 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)cwordslcJ/usr/local/lib/python3.9/site-packages/pip/_internal/cli/autocompletion.py 6s z autocomplete..T) local_onlyinstallpathcsg|]}|jfqSr)nargs)ropt_str)optrrrNscSsg|]}|ddqS)=r)splitrxrrrrScs g|]\}}|vr||fqSrr)rr'v) prev_optsrrrTr(cs"g|]\}}|r||fqSrr)rkr)currentrrrVr(cSsg|] }|dfqS)rr)rr rrrrar(rz--r$cSsg|] }|jqSr) option_list)rirrrrkr( csg|]}|r|qSrr+r&r-rrrxr() osenvirongetr%int IndexErrorrlistrsysexitrr loweriter_installed_distributionsprintauto_complete_pathsr parseroption_list_allroptparse SUPPRESS_HELP _long_opts _short_optsget_path_completion_type option_groupsappendr0r from_iterablejoin)cwordr? subcommandsoptionssubcommand_namewordshould_list_installedenv installedrZshould_list_installablesr subcommandcompletion_typepathsoption opt_labeloptsflattened_optsr)r.rrr#r*r autocompletes                    rY)rrJrWr 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/r$rcss|]}|dvVqdS))r filedirNrr&rrr sz+get_path_completion_type..)rrrArBstrr%metavarany)rrJrWr#orrrrE|s   rE)r.rSr c#stj|\}tj|}t|tjs.dStjfddt|D}|D]`}tj||}tjtj||}|dkrtj |r|VqVtj |rVtj|dVqVdS)atIf ``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 Nc3s$|]}tj|r|VqdS)N)r3r normcaserr&filenamerrr]sz&auto_complete_paths..r\r) r3r r%abspathaccessR_OKrblistdirrIisfileisdir)r.rS directory current_path file_listfr# comp_filerrcrr>s     r>)__doc__rAr3r9 itertoolsrtypingrrrrpip._internal.cli.main_parserrpip._internal.commandsrr pip._internal.metadatar rYr^r6rEr>rrrrs   n