๓
^๊Wc           @@  s1  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m	 Z	 d d l
 m Z d d l m Z d d l m Z m Z m Z m Z d d l m Z m Z e j d	 e j  Z d
 e j f d     YZ d e f d     YZ d e j f d     YZ d e f d     YZ d S(   s   Base option parser setupi    (   t   absolute_importN(   t	   strtobool(   t   string_types(   t   configparser(   t   legacy_config_filet   config_basenamet   running_under_virtualenvt   site_config_files(   t   appdirst   get_terminal_sizes   ^PIP_t   PrettyHelpFormatterc           B@  s\   e  Z d  Z d   Z d   Z d d d  Z d   Z d   Z d   Z d	   Z	 d
   Z
 RS(   s4   A prettier/less verbose help formatter for optparse.c         O@  sC   d | d <d | d <t    d d | d <t j j |  | |  d  S(   Ni   t   max_help_positioni   t   indent_incrementi    i   t   width(   R	   t   optparset   IndentedHelpFormattert   __init__(   t   selft   argst   kwargs(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyR      s    

c         C@  s   |  j  | d d  S(   Ns    <%s>s   , (   t   _format_option_strings(   R   t   option(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   format_option_strings!   s    s    <%s>s   , c         C@  sถ   g  } | j  r& | j | j  d  n  | j rF | j | j d  n  t |  d k rk | j d |  n  | j   rฉ | j p | j j   } | j | | j    n  d j	 |  S(   s  
        Return a comma-separated list of option strings and metavars.

        :param option:  tuple of (short opt, long opt), e.g: ('-f', '--format')
        :param mvarfmt: metavar format string - evaluated as mvarfmt % metavar
        :param optsep:  separator
        i    i   t    (
   t   _short_optst   appendt
   _long_optst   lent   insertt   takes_valuet   metavart   destt   lowert   join(   R   R   t   mvarfmtt   optsept   optsR   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyR   $   s    		c         C@  s   | d k r d S| d S(   Nt   OptionsR   s   :
(    (   R   t   heading(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   format_heading;   s    c         C@  s#   d |  j  t j |  d  } | S(   sz   
        Ensure there is only one newline between usage and the first heading
        if there is no description.
        s   
Usage: %s
s     (   t   indent_linest   textwrapt   dedent(   R   t   usaget   msg(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   format_usage@   s    c         C@  sy   | rq t  |  j d  r! d } n d } | j d  } | j   } |  j t j |  d  } d | | f } | Sd Sd  S(   Nt   maint   Commandst   Descriptions   
s     s   %s:
%s
R   (   t   hasattrt   parsert   lstript   rstripR(   R)   R*   (   R   t   descriptiont   label(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   format_descriptionH   s    	c         C@  s   | r
 | Sd Sd  S(   NR   (    (   R   t   epilog(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   format_epilogZ   s    c         C@  s3   g  | j  d  D] } | | ^ q } d j |  S(   Ns   
(   t   splitR!   (   R   t   textt   indentt   linet	   new_lines(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyR(   a   s    &(   t   __name__t
   __module__t   __doc__R   R   R   R'   R-   R7   R9   R(   (    (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyR
      s   						t   UpdatingDefaultsHelpFormatterc           B@  s   e  Z d  Z d   Z RS(   sฎ   Custom help formatter for use in ConfigOptionParser.

    This is updates the defaults before expanding them, allowing
    them to show up correctly in the help listing.
    c         C@  s;   |  j  d  k	 r( |  j  j |  j  j  n  t j j |  |  S(   N(   R2   t   Nonet   _update_defaultst   defaultsR   R   t   expand_default(   R   R   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyRF   m   s    (   R?   R@   RA   RF   (    (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyRB   f   s   t   CustomOptionParserc           B@  s    e  Z d    Z e d    Z RS(   c         O@  s6   |  j  | |   } |  j j   |  j j | |  | S(   s*   Insert an OptionGroup at a given position.(   t   add_option_groupt   option_groupst   popR   (   R   t   idxR   R   t   group(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   insert_option_groupt   s    c         C@  s2   |  j  } x! |  j D] } | j | j   q W| S(   s<   Get a list of all options, including those in option groups.(   t   option_listRI   t   extend(   R   t   rest   i(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   option_list_all}   s    
(   R?   R@   RM   t   propertyRR   (    (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyRG   s   s   		t   ConfigOptionParserc           B@  se   e  Z d  Z e Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z RS(
   ss   Custom option parser which updates its defaults by checking the
    configuration files and environmental variablesc         O@  s   t  j   |  _ | j d  |  _ | j d t  |  _ |  j   |  _ |  j rd |  j j	 |  j  n  |  j ss t
  t j j |  | |  d  S(   Nt   namet   isolated(   R   t   RawConfigParsert   configRJ   RU   t   FalseRV   t   get_config_filest   filest   readt   AssertionErrorR   t   OptionParserR   (   R   R   R   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyR      s    	c         C@  sไ   t  j j d t  } | t  j k r( g  St t  } |  j s | re t  j j	 |  re | j
 |  q | j
 t  | j
 t  j j t j d  t   n  t   rเ t  j j t j t  } t  j j	 |  rเ | j
 |  qเ n  | S(   Nt   PIP_CONFIG_FILEt   pip(   t   ost   environt   getRY   t   devnullt   listR   RV   t   patht   existsR   R   R!   R   t   user_config_dirR   R   t   syst   prefix(   R   t   config_fileR[   t   venv_config_file(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyRZ      s&    					c         C@  sG   y | j  | |  SWn, t j k
 rB } d | GHt j d  n Xd  S(   Ns*   An error occurred during configuration: %si   (   t   check_valueR   t   OptionValueErrorRi   t   exit(   R   R   t   keyt   valt   exc(    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   check_defaultฟ   s
    	c         C@  s  i  } x6 d |  j  f D]% } | j |  j |  j |    q W|  j sg | j |  j |  j     n  t j |  j  |  _	 t
   } xG| j   D]9\ } } | sช q n  |  j |  } | d k rห q n  | j d k r้ t |  } nี | j d k r/| j   } g  | D] } |  j | | |  ^ q} n | j d k rฉ| j | j  | j   }	 | j |	 |  } | j pxd	 }
 | j pi  } | j | |	 | |  |
 |  n |  j | | |  } | | | j <q Wx$ | D] } t |  j	 |  | | <qึWd |  _	 | S(
   sข   Updates the given defaults with values from the config files and
        the environ. Does a little special handling for certain types of
        options (lists).t   globalt
   store_truet   store_falset   countR   t   callbackN(   s
   store_trues   store_falses   count(    (   RU   t   updatet   normalize_keyst   get_config_sectionRV   t   get_environ_varsR   t   ValuesRE   t   valuest   sett   itemst
   get_optionRC   t   actionR   R:   Rs   t   addR   t   get_opt_stringt   convert_valuet   callback_argst   callback_kwargsRx   t   getattr(   R   RE   RX   t   sectiont	   late_evalRp   Rq   R   t   vt   opt_strR   R   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyRD   ฦ   s@    		+	c         C@  sY   i  } xL | D]D \ } } | j  d d  } | j d  sG d | } n  | | | <q W| S(   s   Return a config dictionary with normalized keys regardless of
        whether the keys were specified in environment variables or in config
        filest   _t   -s   --s   --%s(   t   replacet
   startswith(   R   R   t
   normalizedRp   Rq   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyRz   ๛   s    c         C@  s&   |  j  j |  r" |  j  j |  Sg  S(   s    Get a section of a configuration(   RX   t   has_sectionR   (   R   RU   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyR{     s    c         c@  sS   xL t  j j   D]; \ } } t j |  r t j d |  j   | f Vq q Wd S(   s@   Returns a generator with all environmental vars with prefix PIP_R   N(   Ra   Rb   R   t   _environ_prefix_ret   searcht   subR    (   R   Rp   Rq   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyR|     s    c         C@  s   |  j  s t j |  j  S|  j |  j j    } x] |  j   D]O } | j | j  } t	 | t
  r> | j   } | j | |  | | j <q> q> Wt j |  S(   s   Overridding to make updating the defaults after instantiation of
        the option parser possible, _update_defaults() does the dirty work.(   t   process_default_valuesR   R}   RE   RD   t   copyt   _get_all_optionsRc   R   t
   isinstanceR   R   Rm   (   R   RE   R   t   defaultR   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   get_default_values  s    	 c         C@  s(   |  j  t j  |  j d d |  d  S(   Ni   s   %s
(   t   print_usageRi   t   stderrRo   (   R   R,   (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   error"  s    (   R?   R@   RA   RY   RV   R   RZ   Rs   RD   Rz   R{   R|   R   R   (    (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyRT      s   	
	(		5				(   RA   t
   __future__R    Ri   R   Ra   t   reR)   t   distutils.utilR   t   pip._vendor.sixR   t   pip._vendor.six.movesR   t   pip.locationsR   R   R   R   t	   pip.utilsR   R	   t   compilet   IR   R   R
   RB   R^   RG   RT   (    (    (    s_   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/baseparser.pyt   <module>   s    "O