o
    h                     @  s   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m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 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ eeZG dd dZdS )z3Module containing the application logic for Flake8.    )annotationsN)Sequence)checker)defaults)
exceptions)style_guide)BaseFormatter)debug)
parse_args)finder)reporterc                   @  s   e Zd ZdZd"ddZd#ddZd"d	d
Zd"ddZd$ddZd"ddZ	d"ddZ
d"ddZd"ddZd$ddZd"ddZd$ddZd$dd Zd!S )%Applicationz&Abstract our application into a class.returnNonec                 C  sD   t   | _d| _d| _d| _d| _d| _d| _d| _d| _	d| _
dS )zInitialize our application.Nr   F)time
start_timeend_timeplugins	formatterguidefile_checker_manageroptionsresult_counttotal_result_countcatastrophic_failureself r   M/var/www/html/ai/venv/lib/python3.10/site-packages/flake8/main/application.py__init__   s   

zApplication.__init__intc                 C  s2   | j rdS | jdusJ | jjrdS t| jdkS )zReturn the program exit code.   Nr   )r   r   	exit_zeror    r   r   r   r   r   	exit_code:   s   zApplication.exit_codec                 C  s4   | j dusJ | jdusJ t| j j| j| _dS )z3Initialize a formatter based on the parsed options.N)r   r   r   make	reportersr   r   r   r   r   make_formatterD   s   zApplication.make_formatterc                 C  s2   | j dusJ | jdusJ t| j| j | _dS )zInitialize our StyleGuide.N)r   r   r   StyleGuideManagerr   r   r   r   r   
make_guideJ   s
   
zApplication.make_guideargvSequence[str]c                 C  s8   | j dusJ | jdusJ tj| j | jj|d| _dS )z#Initialize our FileChecker Manager.N)r   r   r)   )r   r   r   Managercheckersr   r   r)   r   r   r   make_file_checker_managerR   s   z%Application.make_file_checker_managerc              
   C  s   | j dusJ | j   z| j   W n  tjy3 } ztt| td d| _W Y d}~nd}~ww t	d | j 
  t | _dS )zRun the actual checks with the FileChecker Manager.

        This method encapsulates the logic to make a
        :class:`~flake8.checker.Manger` instance run the checks it is
        managing.
        Nz5Run flake8 with greater verbosity to see more detailsTzFinished running)r   startrunr   PluginExecutionFailedprintstrr   LOGinfostopr   r   )r   plugin_failedr   r   r   
run_checks\   s   


zApplication.run_checksc                 C  s   | j dusJ | j jsdS | jdusJ | jdusJ | j| j }d|fg}|j}tjd D ]#}| jj| }d| d}|||f | d}||t	|| f q.| j
dusYJ | j
| dS )z9Aggregate, calculate, and report benchmarks for this run.Nzseconds elapsed)filesztotal z
 processedz processed per second)r   	benchmarkr   r   r   appendr   STATISTIC_NAMES
statisticsr    r   show_benchmarks)r   time_elapsedr=   add_statistic	statisticvaluetotal_descriptionper_second_descriptionr   r   r   report_benchmarksp   s    

zApplication.report_benchmarksc                 C  sD   t d | jdusJ | j }|\| _| _t d| j| j dS )zReport all the errors found by flake8 3.0.

        This also updates the :attr:`result_count` attribute with the total
        number of errors, warnings, and other messages found.
        zReporting errorsNz.Found a total of %d violations and reported %d)r4   r5   r   reportr   r   )r   resultsr   r   r   report_errors   s   

zApplication.report_errorsc                 C  sJ   | j dusJ | j jsdS | jdusJ | jdusJ | j| jj dS )z.Aggregate and report statistics from this run.N)r   r=   r   r   show_statisticsstatsr   r   r   r   report_statistics   s   zApplication.report_statisticsc                 C  sb   t |\| _| _| jjr"ttj| j}tt	j
|ddd td|   |   | | dS )zInitialize the application to be run.

        This finds the plugins, registers their options, and parses the
        command-line arguments.
           T)indent	sort_keysr   N)r
   r   r   
bug_reportr	   informationflake8__version__r2   jsondumps
SystemExitr&   r(   r.   )r   r)   r5   r   r   r   
initialize   s   zApplication.initializec                 C  s>   | j dusJ | j   |   |   |   | j   dS )z*Report errors, statistics, and benchmarks.N)r   r/   rH   rK   rE   r6   r   r   r   r   rF      s   
zApplication.reportc                 C  s   |  | |   |   d S )N)rV   r8   rF   r-   r   r   r   _run   s   
zApplication._runc              
   C  s   z|  | W nX ty+ } ztd td t| d| _W Y d}~dS d}~w tjyN } ztd t| t| d| _W Y d}~dS d}~w tj	y_   d| _td Y dS w | j
dusgJ | j
jrrt| j dS dS )zRun our application.

        This method will also handle KeyboardInterrupt exceptions for the
        entirety of the flake8 application. If it sees a KeyboardInterrupt it
        will forcibly clean up the :class:`~flake8.checker.Manager`.
        z... stoppedz#Caught keyboard interrupt from userTNz6There was a critical error during execution of Flake8:z"... stopped while processing files)rW   KeyboardInterruptr2   r4   critical	exceptionr   r   ExecutionError	EarlyQuitr   countr   )r   r)   excr   r   r   r0      s,   


zApplication.runN)r   r   )r   r    )r)   r*   r   r   )__name__
__module____qualname____doc__r   r#   r&   r(   r.   r8   rE   rH   rK   rV   rF   rW   r0   r   r   r   r   r      s    














	r   )rb   
__future__r   argparserS   loggingr   typingr   rQ   r   r   r   r   flake8.formatting.baser   flake8.mainr	   flake8.options.parse_argsr
   flake8.pluginsr   r   	getLoggerr_   r4   r   r   r   r   r   <module>   s&    
