a
    ›`é  ã                   @   sX   d Z ddlmZ ddlZddlmZmZ ddlZddlm	Z
 eƒ ZG dd„ dejƒZdS )z3The logic for Flake8's integration with setuptools.é    )ÚlogN)ÚListÚTuple)Úapplicationc                   @   sH   e Zd ZdZdZg Zdd„ Zdd„ Zdd„ Zd	d
„ Z	dd„ Z
dd„ ZdS )ÚFlake8z;Run Flake8 via setuptools/distutils for registered modules.z,Run Flake8 on modules registered in setup.pyc                 C   sB   t  ¡ | _| j g ¡ | jjj}|D ]}|jr$t| |jt	ƒ q$dS )z3Override this method to initialize our application.N)
ÚappZApplicationÚflake8Z
initializeÚoption_managerÚoptionsÚparse_from_configÚsetattrÚconfig_nameÚUNSET)Úselfr
   Úoption© r   ú=lib/python3.9/site-packages/flake8/main/setuptools_command.pyÚinitialize_options   s    

zFlake8.initialize_optionsc                 C   sP   | j jj}|D ]<}|jr|j}t| |tƒ}|tu r4qt| j j|| |¡ƒ qdS )z&Override this to parse the parameters.N)	r   r	   r
   r   r   Úgetattrr   r   Znormalize_from_setuptools)r   r
   r   ÚnameÚvaluer   r   r   Úfinalize_options#   s    
ýzFlake8.finalize_optionsc                 c   s~   d}| j jpi }d|v }| j jp"g }|D ]P}|}||v rB|| }n|rXtj |d |¡}| |¡rdq(||d f7 }|V  q(dS )z:Collect the files/dirs included in the registered modules.r   Ú Ú.N)ÚdistributionZpackage_dirÚpackagesÚosÚpathÚjoinÚ
startswith)r   Zseen_package_directoriesZdirectoriesZempty_directory_existsr   ÚpackageZpackage_directoryr   r   r   Úpackage_files2   s     
ÿ

zFlake8.package_filesc                 c   s*   | j jp
g }dj}|D ]}||ƒV  qdS )z'Collect the files listed as py_modules.z{0}.pyN)r   Z
py_modulesÚformat)r   ÚmodulesZfilename_fromÚmoduler   r   r   Úmodule_filesM   s    zFlake8.module_filesc                 c   s2   |   ¡ D ]
}|V  q|  ¡ D ]
}|V  qdV  dS )z!Collect package and module files.zsetup.pyN)r!   r%   )r   r    r$   r   r   r   Údistribution_filesT   s
    zFlake8.distribution_filesc              
   C   s®   | j  t|  ¡ ƒ¡ | j j ¡  | j  ¡  | j  ¡  | j  ¡  | j j 	¡  zNz| j  
¡  W n, ty† } z|jrr‚ W Y d}~n
d}~0 0 W |  dtj¡ n|  dtj¡ 0 dS )zRun the Flake8 application.NzœWARNING: flake8 setuptools integration is deprecated and scheduled for removal in 4.x.  For more information, see https://gitlab.com/pycqa/flake8/issues/544)r   Z
run_checksÚlistr&   Ú	formatterÚstartZreport_errorsZreport_statisticsZreport_benchmarksÚstopÚexitÚ
SystemExitÚcodeZannouncer   ZWARN)r   Úer   r   r   Úrun^   s$    


ü
üz
Flake8.runN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚdescriptionZuser_optionsr   r   r!   r%   r&   r/   r   r   r   r   r      s   	
r   )r3   Ú	distutilsr   r   Útypingr   r   Z
setuptoolsZflake8.mainr   r   Úobjectr   ZCommandr   r   r   r   r   Ú<module>   s   