ó
„¾^Yc           @   s{   d  Z  d d l Z d d l Z d d l Z d d l Z e j e ƒ Z d Z	 d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d S(   s!   Config handling logic for Flake8.iÿÿÿÿNt   ConfigFileFindert   MergedConfigParserc           B   sb   e  Z d  Z d Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   s;   Encapsulate the logic for finding and reading config files.s	   setup.cfgs   tox.inic         C   së   | p	 g  } g  | D] } t  j j | ƒ ^ q |  _ t j d k |  _ t  j j d t  j j	 d ƒ ƒ |  _
 d | |  _ | |  _ d d |  j f |  _ t  j j t  j ƒ |  _ | s¿ d g } n  t  j j t  j j | ƒ ƒ |  _ |  _ d S(   sM  Initialize object to find config files.

        :param str program_name:
            Name of the current program (e.g., flake8).
        :param list args:
            The extra arguments passed on the command-line.
        :param list extra_config_files:
            Extra configuration files specified by the user to read.
        t   win32t   XDG_CONFIG_HOMEs	   ~/.configt   .s	   setup.cfgs   tox.iniN(   t   ost   patht   abspatht   extra_config_filest   syst   platformt
   is_windowst   environt   gett
   expandusert   xdg_homet   program_configt   program_namet   project_filenamest   curdirt   local_directoryt   commonprefixt   parentt   tail(   t   selfR   t   argsR   t   f(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   __init__   s    (	c         C   sV   t  j ƒ  } y | j |  ƒ } Wn* t  j k
 rK t j d |  ƒ g  } n X| | f S(   Ns`   There was an error trying to parse a config file. The files we were attempting to parse were: %r(   t   configparsert   RawConfigParsert   readt   ParsingErrort   LOGt	   exception(   t   filest   configt   found_files(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   _read_config4   s    	
c         C   s2   |  j  | ƒ \ } } | r. t j d | ƒ n  | S(   s=   Read and parse the config file specified on the command-line.s!   Found cli configuration files: %s(   R%   R    t   debug(   R   R"   R#   R$   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt
   cli_config@   s    c         c   s¦   |  j  } |  j } t } x‡ | r¡ | r¡ x[ |  j D]P } t j j t j j | | ƒ ƒ } t j j | ƒ r2 | Vt	 } | |  _
 q2 q2 Wt j j | ƒ \ } } q Wd S(   s)   Find and generate all local config files.N(   R   R   t   FalseR   R   R   R   t   joint   existst   TrueR   t   split(   R   R   R   t   found_config_filest   project_filenamet   filename(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   generate_possible_local_filesG   s    		c         C   sO   t  j j } g  |  j ƒ  D] } | ^ q g  |  j D] } | | ƒ r2 | ^ q2 S(   s˜  Find all local config files which actually exist.

        Filter results from
        :meth:`~ConfigFileFinder.generate_possible_local_files` based
        on whether the filename exists or not.

        :returns:
            List of files that exist that are local project config files with
            extra config files appended to that list (which also exist).
        :rtype:
            [str]
        (   R   R   R*   R0   R   (   R   R*   R/   R   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   local_config_filesV   s    c         C   s8   |  j  |  j ƒ  ƒ \ } } | r4 t j d | ƒ n  | S(   s4   Parse all local config files into one config object.s#   Found local configuration files: %s(   R%   R1   R    R&   (   R   R#   R$   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   local_configsi   s    c         C   s9   |  j  r  t j j d |  j ƒ St j j |  j |  j ƒ S(   s    Find the user-level config file.s   ~\(   R   R   R   R   R   R)   R   R   (   R   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   user_config_filep   s    	c         C   s8   |  j  |  j ƒ  ƒ \ } } | r4 t j d | ƒ n  | S(   s0   Parse the user config file into a config object.s"   Found user configuration files: %s(   R%   R3   R    R&   (   R   R#   R$   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   user_configv   s    (   s	   setup.cfgs   tox.ini(   t   __name__t
   __module__t   __doc__t   PROJECT_FILENAMESR   t   staticmethodR%   R'   R0   R1   R2   R3   R4   (    (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyR       s   	#					c           B   s   e  Z d  Z e d d g ƒ Z e d d g ƒ Z d d d „ Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d e d „ Z RS(   sø   Encapsulate merging different types of configuration files.

    This parses out the options registered that were specified in the
    configuration files, handles extra configuration files, and returns
    dictionaries with the parsed values.
    t   intt   countt
   store_truet   store_falsec         C   s[   | |  _  | j |  _ | |  _ | j |  _ | p3 g  |  _ t |  j |  j |  j ƒ |  _ d S(   sQ  Initialize the MergedConfigParser instance.

        :param flake8.option.manager.OptionManager option_manager:
            Initialized OptionManager.
        :param list extra_config_files:
            List of extra config files to parse.
        :params list args:
            The extra parsed arguments from the command-line.
        N(   t   option_managerR   R   t   config_options_dictt   config_optionsR   R    t   config_finder(   R   R>   R   R   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyR      s    		c         C   s5   | j  | |  j j ƒ } t j d | | | j ƒ | S(   Ns,   %r has been normalized to %r for option "%s"(   t	   normalizeRA   R   R    R&   t   config_name(   R   t   optiont   valuet   final_value(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   _normalize_value¦   s    	c         C   sâ   i  } xÕ | j  |  j ƒ D]Á } | |  j k rD t j d | ƒ q n  |  j | } | j } | j |  j k rx | j } n | j	 |  j
 k r– | j } n  | |  j | ƒ } t j d | | ƒ |  j | | ƒ } | | | j <q W| S(   Ns(   Option "%s" is not registered. Ignoring.s   Option "%s" returned value: %r(   t   optionsR   R@   R    R&   R   t   typet   GETINT_TYPESt   getintt   actiont   GETBOOL_ACTIONSt
   getbooleanRG   RC   (   R   t   config_parsert   config_dictt   option_nameRD   t   methodRE   RF   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   _parse_config¯   s"    		c         C   s   | j  |  j ƒ S(   s@   Check if the specified config parser has an appropriate section.(   t   has_sectionR   (   R   R#   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   is_configured_byÇ   s    c         C   sO   |  j  j ƒ  } |  j | ƒ s5 t j d |  j ƒ i  St j d ƒ |  j | ƒ S(   s/   Parse and return the local configuration files.s,   Local configuration files have no %s sections"   Parsing local configuration files.(   RA   R2   RU   R    R&   R   RS   (   R   R#   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   parse_local_configË   s    	
c         C   sO   |  j  j ƒ  } |  j | ƒ s5 t j d |  j ƒ i  St j d ƒ |  j | ƒ S(   s.   Parse and return the user configuration files.s+   User configuration files have no %s sections!   Parsing user configuration files.(   RA   R4   RU   R    R&   R   RS   (   R   R#   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   parse_user_configÖ   s    	
c         C   sR   |  j  j | ƒ } |  j | ƒ s8 t j d |  j ƒ i  St j d ƒ |  j | ƒ S(   s0   Parse and return the file specified by --config.s*   CLI configuration files have no %s sections    Parsing CLI configuration files.(   RA   R'   RU   R    R&   R   RS   (   R   t   config_pathR#   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   parse_cli_configá   s    	
c         C   sI   |  j  ƒ  } |  j ƒ  } x* | j ƒ  D] \ } } | j | | ƒ q% W| S(   s¸   Merge the parsed user and local configuration files.

        :returns:
            Dictionary of the parsed and merged configuration options.
        :rtype:
            dict
        (   RW   RV   t   itemst
   setdefault(   R   R4   R#   RD   RE   (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   merge_user_and_local_configì   s
    c         C   sD   | r t  j d ƒ i  S| r: t  j d | ƒ |  j | ƒ S|  j ƒ  S(   sº  Parse and return the local and user config files.

        First this copies over the parsed local configuration and then
        iterates over the options in the user configuration and sets them if
        they were not set by the local configuration file.

        :param str cli_config:
            Value of --config when specified at the command-line. Overrides
            all other config files.
        :param bool isolated:
            Determines if we should parse configuration files at all or not.
            If running in isolated mode, we ignore all configuration files
        :returns:
            Dictionary of parsed configuration options
        :rtype:
            dict
        sE   Refusing to parse configuration files due to user-requested isolations|   Ignoring user and locally found configuration files. Reading only configuration from "%s" specified via --config by the user(   R    R&   RY   R\   (   R   R'   t   isolated(    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   parseü   s    	N(   R5   R6   R7   t   setRJ   RM   t   NoneR   RG   RS   RU   RV   RW   RY   R\   R(   R^   (    (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyR   ~   s   								(   s   ConfigFileFinders   MergedConfigParser(   R7   R   t   loggingt   os.pathR   R	   t	   getLoggerR5   R    t   __all__t   objectR    R   (    (    (    s5   /tmp/pip-build-EndXZ2/flake8/flake8/options/config.pyt   <module>   s   r