ó
…¾^Yc           @` sÈ   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l m Z d d d „  ƒ  YZ e j	 j
 d ƒ rµ y d d l Z Wn e k
 rŸ e j d ƒ n Xe ƒ  Z d	 „  Z n d
 „  Z d Z d S(   s)	  allow bash-completion for argparse with argcomplete if installed
needs argcomplete>=0.5.6 for python 3.2/3.3 (older versions fail
to find the magic string, so _ARGCOMPLETE env. var is never set, and
this does not need special code.

argcomplete does not support python 2.5 (although the changes for that
are minor).

Function try_argcomplete(parser) should be called directly before
the call to ArgumentParser.parse_args().

The filescompleter is what you normally would use on the positional
arguments specification, in order to get "dirname/" after "dirn<TAB>"
instead of the default "dirname ":

   optparser.add_argument(Config._file_or_dir, nargs='*'
                               ).completer=filescompleter

Other, application specific, completers should go in the file
doing the add_argument calls as they need to be specified as .completer
attributes as well. (If argcomplete is not installed, the function the
attribute points to will not be used).

SPEEDUP
=======
The generic argcomplete script for bash-completion
(/etc/bash_completion.d/python-argcomplete.sh )
uses a python program to determine startup script generated by pip.
You can speed up completion somewhat by changing this script to include
  # PYTHON_ARGCOMPLETE_OK
so the the python-argcomplete-check-easy-install-script does not
need to be called to find the entry point of the code and see if that is
marked  with PYTHON_ARGCOMPLETE_OK

INSTALL/DEBUGGING
=================
To include this support in another application that has setup.py generated
scripts:
- add the line:
    # PYTHON_ARGCOMPLETE_OK
  near the top of the main python entry point
- include in the file calling parse_args():
    from _argcomplete import try_argcomplete, filescompleter
   , call try_argcomplete just before parse_args(), and optionally add
   filescompleter to the positional arguments' add_argument()
If things do not work right away:
- switch on argcomplete debugging with (also helpful when doing custom
  completers):
    export _ARC_DEBUG=1
- run:
    python-argcomplete-check-easy-install-script $(which appname)
    echo $?
  will echo 0 if the magic line has been found, 1 if not
- sometimes it helps to find early on errors using:
    _ARGCOMPLETE=1 _ARC_DEBUG=1 appname
  which should throw a KeyError: 'COMPLINE' (which is properly set by the
  global argcomplete script).
i    (   t   absolute_importt   divisiont   print_functionN(   t   globt   FastFilesCompleterc           B` s#   e  Z d  Z e d „ Z d „  Z RS(   s   Fast file completer classc         C` s   | |  _  d  S(   N(   t   directories(   t   selfR   (    (    s4   /tmp/pip-build-hU8Cw8/pytest/_pytest/_argcomplete.pyt   __init__C   s    c         K` s   t  j j | d k r; t t  j j | ƒ t  j j ƒ } n d } g  } g  } d | k r¢ d | k r¢ | d t  j j k r• | j t | d ƒ ƒ n  | d 7} n  | j t | ƒ ƒ xD t | ƒ D]6 } t  j j | ƒ rç | d 7} n  | j	 | | ƒ qÂ W| S(   s%   only called on non option completionsi   i    t   *t   ?iÿÿÿÿs   .*t   /(
   t   ost   patht   sept   lent   dirnamet   extendR   t   sortedt   isdirt   append(   R   t   prefixt   kwargst
   prefix_dirt
   completiont   globbedt   x(    (    s4   /tmp/pip-build-hU8Cw8/pytest/_pytest/_argcomplete.pyt   __call__F   s    %(   t   __name__t
   __module__t   __doc__t   TrueR   R   (    (    (    s4   /tmp/pip-build-hU8Cw8/pytest/_pytest/_argcomplete.pyR   A   s   t   _ARGCOMPLETEiÿÿÿÿc         C` s   t  j |  ƒ d  S(   N(   t   argcompletet   autocomplete(   t   parser(    (    s4   /tmp/pip-build-hU8Cw8/pytest/_pytest/_argcomplete.pyt   try_argcompleteb   s    c         C` s   d  S(   N(    (   R"   (    (    s4   /tmp/pip-build-hU8Cw8/pytest/_pytest/_argcomplete.pyR#   e   s    (    (   R   t
   __future__R    R   R   t   sysR   R   R   t   environt   gett   argcomplete.completersR    t   ImportErrort   exitt   filescompleterR#   t   None(    (    (    s4   /tmp/pip-build-hU8Cw8/pytest/_pytest/_argcomplete.pyt   <module>;   s   		