o g @sdZddlZddlZddlZddlmZddlmZmZm Z m Z ddl m Z ddl mZmZddlmZdd d Zd e ed ed eede efddZdededeefddZdS)zBLogic that powers autocompletion installed by ``pip completion``. N)chain)AnyIterableListOptional)create_main_parser) commands_dictcreate_command)get_default_environmentreturncsdtjvrdStjdddttjd}z|dWn ty,dYnwt}tt}g}d}D] }||vrD|}nq:|dur|dkrSt d d o\|d v}|rt } fd d |j d d D}|r|D]} t| qxt d d o|dk} | rtdD]} t| qt dt|} | jjD]} | jtjkr| j| jD] }||| jfqqdd d|dDfdd |D}fdd |D}t|| jj}|rt|}dd |D}|D]}|d}|dr|ddddkr|d7}t|qnMdd |jD}||jt|} drI|D]} | jtjkrF|| j| j7}q5nt||}|rYtt|}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)cwordslcB/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py 2s z autocomplete..T) local_onlyinstallpathcSsg|] }|ddqS)=r)splitrxrrrrNcs g|] \}}|vr||fqSrr)rr$v) prev_optsrrrOs cs"g|] \}}|r||fqSrr)rkr&currentrrrQs"cSsg|]}|dfqS)rr)rr rrrr\srz--r!cSsg|]}|jqSr) option_list)rirrrrfs csg|] }|r|qSrr(r#r*rrrsr%) osenvironr"int IndexErrorrlistrsysexitrr loweriter_installed_distributionsprintauto_complete_pathsr parseroption_list_allroptparse SUPPRESS_HELP _long_opts _short_optsappendnargsget_path_completion_type option_groupsr-r from_iterablejoin)cwordr; subcommandsoptionssubcommand_namewordshould_list_installedenv installedrshould_list_installablesr subcommandoptopt_strcompletion_typepathsoption opt_labeloptsflattened_optsr)r+rrr'r autocompletes                   rYrrGrWcCs|dks ||ddsdS|D]7}|jtjkrqt|dD]&}||ddd|krG|jr@tdd|jdDrG|jSq!qdS) 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 s z+get_path_completion_type..)rrr=r>strr"metavarany)rrGrWrQorrrrCws   rCr+rSc#stj|\}tj|}t|tjsdStjfddt|D}|D]0}tj||}tjtj||}|dkrNtj |rN|Vq,tj |r\tj|dVq,dS)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)r0r normcaserr#filenamerrr]s  z&auto_complete_paths..r\r) r0r r"abspathaccessR_OKrblistdirrFisfileisdir)r+rS directory current_path file_listfrQ comp_filerrcrr:s$    r:)r N)__doc__r=r0r5 itertoolsrtypingrrrrpip._internal.cli.main_parserrpip._internal.commandsrr pip._internal.metadatar rYr^r2rCr:rrrrs(    h