
    ^j                    .   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Zddl	m
Z
 ddlmZmZ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mZ ddlmZ ddlmZ ddlmZ ddl m!Z!m"Z" d,dZ#d-dZ$d.dZ% ed          	 d/d0d(            Z&	 d/d1d+Z'dS )2z
Formatting many files at once via multiprocessing. Contains entrypoint and utilities.

NOTE: this module is only imported if we need to format several files at once.
    )annotationsN)Iterable)ExecutorProcessPoolExecutorThreadPoolExecutor)Manager)Path)Any)
mypyc_attr)	WriteBackformat_file_in_place)Cache)Mode)err)ChangedReportreturnasyncio.AbstractEventLoopc                     	 t           j        dk    rddl} |                                 S ddl}|                                S # t
          $ r t          j                    cY S w xY w)a	  If our environment has uvloop or winloop installed we use it otherwise
    a normal asyncio eventloop is called as fallback.

    This is called only from command-line entry points to avoid
    interfering with the parent process if Black is used as a library.
    win32r   N)sysplatformuvloopnew_event_loopwinloopImportErrorasyncio)r   r   s     U/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/black/concurrency.pymaybe_use_uvloopr      sz    
(<7""MMM((***NNN))+++ ( ( (%'''''(s   'A A A"!A"tasksIterable[asyncio.Future[Any]]Nonec                V    t          d           | D ]}|                                 dS )zFasyncio signal handler that cancels all `tasks` and reports to stderr.zAborted!N)r   cancel)r    tasks     r   r$   r$   2   s5    
OOO       loopc                |   	 d t          j        |           D             }|sJ	 t          j        d          }|                    t          j                   |                                  dS |D ]}|                                 |                     t          j	        |ddi           t          j        d          }|                    t          j                   |                                  dS # t          j        d          }|                    t          j                   |                                  w xY w)zFCancel all pending tasks on `loop`, wait for them, and close the loop.c                :    g | ]}|                                 |S  )done).0r%   s     r   
<listcomp>zshutdown.<locals>.<listcomp>=   s%    QQQdTYY[[QTQQQr&   zconcurrent.futuresNreturn_exceptionsT)
r   	all_taskslogging	getLoggersetLevelCRITICALcloser$   run_until_completegather)r'   	to_cancel	cf_loggerr%   s       r   shutdownr9   9   s&   QQg&7&=&=QQQ	 	 %&:;;	7+,,,

  	 	DKKMMMM	 RT R RSSS
 %&:;;	7+,,,

 %&:;;	7+,,,

s    C2 ,=C2 2A	D;T)	patchableFsources	set[Path]fastbool
write_backr   moder   reportr   workers
int | Noneno_cachec                   |Dt          t          j                            dd                    }|pt          j                    pd}t
          j        dk    rt          |d          }t          t
          dd          rd}d}|dk    r/	 t          |	          }n# t          t          t          f$ r Y nw xY w|t          d	          }t                      }t          j        |           	 |                    t%          | |||||||
                     	 t'          |           t          j        d           n# t          j        d           w xY w||                                 dS dS # 	 t'          |           t          j        d           n# t          j        d           w xY w||                                 w w xY w)z4Reformat multiple files using a ProcessPoolExecutor.NBLACK_NUM_WORKERSr      r   <   frozenF)max_workers)r;   r=   r?   r@   rA   r'   executorrD   )intosenvironget	cpu_countr   r   mingetattrr   r   NotImplementedErrorOSErrorr   r   r   set_event_loopr5   schedule_formattingr9   )	r;   r=   r?   r@   rA   rB   rD   rK   r'   s	            r   reformat_manyrW   O   s    bjnn%8!<<==0R\^^0q
|wgr""sHe$$ 
  $H{{	*w???HH0': 	 	 	
 D	 %!444D4    %!!	 	 		
 	
 	
	)TNNN"4((((G"4((((  		)TNNN"4((((G"4((((  sB   B B32B3+*E- D: :E-G/F>GF))GrK   r   c                V  K   |rdnt          j                  }|dt          j        t          j        fvrJ|                    |           \  } }	t          |	          D ]"}
|                    |
t          j	                   #| sdS g }g }dd}t          j        t          j        fv r"t                      }|                                	 fdt          |           D             }|                                }	                     t          j        t           |                               t          j        t           |           n# t$          $ r Y nw xY w|r\t'          j        |t&          j                   d{V \  }}|D ],}|                    |          }
|                                r|                    |           B|                                x}rS|j        r(t7          j        t;          |          ||j                   |                    |
tA          |                     |!                                rt          j"        nt          j#        }t          j"        u st          j$        u r#|t          j#        u r|                    |
           |                    |
|           .|\|rt'          j%        |ddi d{V  |r|s||&                    |           ||'                                 dS dS # ||'                                 w w xY w)zRun formatting of `sources` in parallel using the provided `executor`.

    (Use ProcessPoolExecutors for actual parallelism.)

    `write_back`, `fast`, and `mode` options are passed to
    :func:`format_file_in_place`.
    Nc                v    i | ]5}t          j                            t          |                    |6S r*   )r   ensure_futurerun_in_executorr   )r,   srcrK   r=   lockr'   r@   r?   s     r   
<dictcomp>z'schedule_formatting.<locals>.<dictcomp>   sa     
 
 
  !$$2CtZQU   
 
 
r&   )return_whenr.   T)(r   readr   DIFF
COLOR_DIFFfiltered_cachedsortedr+   r   CACHEDr   Lockkeysadd_signal_handlersignalSIGINTr$   SIGTERMrS   r   waitFIRST_COMPLETEDpop	cancelledappend	exceptionverbose	tracebackprint_exceptiontype__traceback__failedstrresultYESNOCHECKr6   writer9   )r;   r=   r?   r@   rA   r'   rK   rD   cachecachedr\   ro   sources_to_cachemanagerr    pendingr+   _r%   excchangedr]   s    ``` ``              @r   rV   rV      s     " 2DD%*T"2"2EZ0    //88&>> 	- 	-CKKW^,,,, IDGini&:;;; ))||~~)
 
 
 
 
 
 
 
 
 g
 
 
 **,,	##FM67CCC##FNFGDDDD" 	 	 	D	  	.#Lg>UVVVVVVVVVGD! . .iioo>>## .$$T**** NN,,,S .~ U!1$s))S#BSTTTMM#s3xx0000-1[[]]Jgkk
G "Y]22"io55'WZ:O:O(//444KKW----%  	.&  	E.)DtDDDDDDDDD 	*H 	*1BKK())) 7 s2   4L AE L 
EL EFL L()r   r   )r    r!   r   r"   )r'   r   r   r"   )F)r;   r<   r=   r>   r?   r   r@   r   rA   r   rB   rC   rD   r>   r   r"   )r;   r<   r=   r>   r?   r   r@   r   rA   r   r'   r   rK   r   rD   r>   r   r"   )(__doc__
__future__r   r   r0   rM   ri   r   rs   collections.abcr   concurrent.futuresr   r   r   multiprocessingr   pathlibr	   typingr
   mypy_extensionsr   blackr   r   black.cacher   
black.moder   black.outputr   black.reportr   r   r   r$   r9   rW   rV   r*   r&   r   <module>r      s    # " " " " "   				  



     $ $ $ $ $ $ P P P P P P P P P P # # # # # #             & & & & & & 1 1 1 1 1 1 1 1                   ( ( ( ( ( ( ( (( ( ( ((      , d ;  ;  ;  ;  ; L O O O O O O Or&   