3 ig@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)returnc sdtjkrdStjdjddttjd}y|dWntk rZdYnXt}tt}g}d}xD]}||krx|}PqxW|dk r|dkrtj dj d o|dk}|rt }j fd d |j d dD}|rx|D] } t| qWtj dt|} xH| jjD]<} | jtjkr&x&| j| jD]} |j| | jfqFWq&Wdd d|dDfdd |D}fdd |D}t|| jj} | rt| }dd |D}x|D]>}|d}|dr |ddddkr |d7}t|qWndd |jD}|j|jtj|}j dr~xN|D]$} | jtjkrT|| j| j7}qTWn t||} | rtt| }tdjfdd |Dtj ddS)z:Entry Point for completion of main and subcommand options.PIP_AUTO_COMPLETEN COMP_WORDS COMP_CWORDhelp-show uninstallcs0g|](}|jjr|jddkr|jqS)rN)canonical_name startswith).0dist)cwordslc?/tmp/pip-build-88gy_88q/pip/pip/_internal/cli/autocompletion.py 3s z autocomplete..T) local_onlycSsg|]}|jddqS)=r)split)rxrrrrFscs g|]\}}|kr||fqSrr)rr!v) prev_optsrrrGscs"g|]\}}|jr||fqSr)r)rkr")currentrrrIscSsg|] }|dfqS)rr)rpathrrrrTsrz--rcSsg|] }|jqSr) option_list)rirrrr^s csg|]}|jr|qSr)r)rr!)r%rrrks)rr) osenvironr int IndexErrorrlistrsysexitrr lowerZiter_installed_distributionsprintr parseroption_list_allroptparse SUPPRESS_HELP _long_opts _short_optsappendnargsget_path_completion_typeauto_complete_paths option_groupsr(r from_iterablejoin)cwordr4 subcommandsoptionssubcommand_namewordZshould_list_installedenv installedr subcommandoptopt_strcompletion_typepathsoption opt_labeloptsZflattened_optsr)r%rrr#r autocompletes~                  rP)rrArOr cCs|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&rRrSr)rr!rrr sz+get_path_completion_type..)rrr6r7strr metavarany)rrArOrIorrrr<os    r<)r%rKr c#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!)filenamerrrTsz&auto_complete_paths..rSr) r+r&r abspathaccessR_OKrYlistdirr@isfileisdir)r%rK directoryZ current_path file_listfrIZ comp_filer)rZrr=s     r=)__doc__r6r+r0 itertoolsrZtypingrrrrZpip._internal.cli.main_parserrZpip._internal.commandsrr Zpip._internal.metadatar rPrUr-r<r=rrrrs   a