
^Yc           @   sT   d  Z  d d l Z d d l Z d d l m Z e   Z d e j f d     YZ	 d S(   s3   The logic for Flake8's integration with setuptools.iN(   t   applicationt   Flake8c           B   sP   e  Z d  Z d Z g  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(   s;   Run Flake8 via setuptools/distutils for registered modules.s,   Run Flake8 on modules registered in setup.pyc         C   sb   t  j   |  _ |  j j g   |  j j j } x- | D]% } | j r5 t |  | j t	  q5 q5 Wd S(   s3   Override this method to initialize our application.N(
   t   appt   Applicationt   flake8t
   initializet   option_managert   optionst   parse_from_configt   setattrt   config_namet   UNSET(   t   selfR   t   option(    (    s>   /tmp/pip-build-EndXZ2/flake8/flake8/main/setuptools_command.pyt   initialize_options   s    	c         C   s|   |  j  j j } xf | D]^ } | j r | j } t |  | t  } | t k rR q n  t |  j  j | | j |   q q Wd S(   s&   Override this to parse the parameters.N(	   R   R   R   R   R
   t   getattrR   R	   t   normalize_from_setuptools(   R   R   R   t   namet   value(    (    s>   /tmp/pip-build-EndXZ2/flake8/flake8/main/setuptools_command.pyt   finalize_options!   s    		c         c   s   d } |  j  j p i  } d | k } |  j  j p3 g  } xz | D]r } | } | | k rb | | } n" | r t j j | d |  } n  | j |  r q= n  | | d f 7} | Vq= Wd S(   s:   Collect the files/dirs included in the registered modules.t    t   .N(    (   t   distributiont   package_dirt   packagest   ost   patht   joint
   startswith(   R   t   seen_package_directoriest   directoriest   empty_directory_existsR   t   packaget   package_directory(    (    s>   /tmp/pip-build-EndXZ2/flake8/flake8/main/setuptools_command.pyt   package_files.   s    c         c   s;   |  j  j p g  } d j } x | D] } | |  Vq" Wd S(   s'   Collect the files listed as py_modules.s   {0}.pyN(   R   t
   py_modulest   format(   R   t   modulest   filename_fromt   module(    (    s>   /tmp/pip-build-EndXZ2/flake8/flake8/main/setuptools_command.pyt   module_filesH   s    	c         c   sA   x |  j    D] } | Vq Wx |  j   D] } | Vq) Wd Vd S(   s!   Collect package and module files.s   setup.pyN(   R"   R(   (   R   R    R'   (    (    s>   /tmp/pip-build-EndXZ2/flake8/flake8/main/setuptools_command.pyt   distribution_filesO   s
    		c         C   s   |  j  j t |  j     |  j  j j   |  j  j   |  j  j   |  j  j   |  j  j j	   y |  j  j
   Wn" t k
 r } | j r   q n Xd S(   s   Run the Flake8 application.N(   R   t
   run_checkst   listR)   t	   formattert   startt   report_errorst   report_statisticst   report_benchmarkst   stopt   exitt
   SystemExitt   code(   R   t   e(    (    s>   /tmp/pip-build-EndXZ2/flake8/flake8/main/setuptools_command.pyt   runY   s    	(   t   __name__t
   __module__t   __doc__t   descriptiont   user_optionsR   R   R"   R(   R)   R6   (    (    (    s>   /tmp/pip-build-EndXZ2/flake8/flake8/main/setuptools_command.pyR      s   						
(
   R9   R   t
   setuptoolst   flake8.mainR    R   t   objectR   t   CommandR   (    (    (    s>   /tmp/pip-build-EndXZ2/flake8/flake8/main/setuptools_command.pyt   <module>   s
   	