
    ]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	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z&	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ'y)z
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Reportc                     	 t         j                  dk7  rddl} | j                         S ddl}|j                         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     ;/root/env/lib/python3.12/site-packages/black/concurrency.pymaybe_use_uvloopr      sU    
(<<7"((**))++ (%%''(s   &= = AAc                H    t        d       | D ]  }|j                           y)zFasyncio signal handler that cancels all `tasks` and reports to stderr.zAborted!N)r   cancel)taskstasks     r   r   r   2   s!    
O     c                   	 t        j                  |       D cg c]  }|j                         r| }}|sF	 t        j                  d      }|j                  t        j                         | j                          y|D ]  }|j                           | j                  t        j                  |ddi       t        j                  d      }|j                  t        j                         | j                          yc c}w # t        j                  d      }|j                  t        j                         | j                          w xY w)zFCancel all pending tasks on `loop`, wait for them, and close the loop.zconcurrent.futuresNreturn_exceptionsT)r   	all_tasksdonelogging	getLoggersetLevelCRITICALcloser   run_until_completegather)loopr!   	to_cancel	cf_loggers       r   shutdownr1   9   s   &-&7&7&=QdTYY[TQ	Q %%&:;	7++,

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

 R %%&:;	7++,

s'   D C=C=D =;D =D AET)	patchablec                6   |Et        t        j                  j                  dd            }|xs t        j                         xs d}t
        j                  dk(  rt        |d      }t        t
        dd      rd}d}|dkD  r	 t        |	      }|t        d	      }t               }t        j                   |       	 |j#                  t%        | |||||||
             	 t'        |       t        j                   d       ||j'                          yy# t        t        t        f$ r Y w xY w# t        j                   d       w xY w# 	 t'        |       t        j                   d       n# t        j                   d       w xY w||j'                          w w xY w)z4Reformat multiple files using a ProcessPoolExecutor.NBLACK_NUM_WORKERSr      r   <   frozenF)max_workers)sourcesfast
write_backmodereportr.   executorno_cache)intosenvironget	cpu_countr   r   mingetattrr   r   NotImplementedErrorOSErrorr   r   r   set_event_loopr,   schedule_formattingr1   )	r9   r:   r;   r<   r=   workersr?   r>   r.   s	            r   reformat_manyrL   O   sz    bjjnn%8!<=0R\\^0q
||wgr"sHe$
  $H{	*w?H %!4D4  %!!		
	)TN""4(  = 0': 	
 	: ""4(	)TN""4(G""4(  sB   D <"E D- D*)D*-EF	E*F*FFc                  K   |rdnt        j                  |      }|f|t        j                  t        j                  fvrD|j                  |       \  } }	t        |	      D ]"  }
|j                  |
t        j                         $ | syg }g }d}d}|t        j                  t        j                  fv rt               }|j                         }	 t        |       D 
ci c]1  }
t        j                  |j                  |t        |
||||            |
3 }}
|j!                         }	 |j#                  t$        j&                  t(        |       |j#                  t$        j*                  t(        |       |r]t        j.                  |t        j0                         d{   \  }}|D ]#  }|j3                  |      }
|j5                         r|j7                  |       7|j9                         x}rR|j:                  r*t=        j>                  tA        |      ||jB                         |jE                  |
tG        |             |jI                         rt        jJ                  nt        jL                  }|t        jJ                  u s$|t        jN                  u r#|t        jL                  u r|j7                  |
       |j                  |
|       & |r]|rt        jP                  |ddi d{    |r|s||jS                  |       ||jU                          yyc c}
w # t,        $ r Y w xY w7 7 G# ||jU                          w w xY w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`.
    N)return_whenr$   T)+r   readr   DIFF
COLOR_DIFFfiltered_cachedsortedr&   r   CACHEDr   Lockr   ensure_futurerun_in_executorr   keysadd_signal_handlersignalSIGINTr   SIGTERMrG   waitFIRST_COMPLETEDpop	cancelledappend	exceptionverbose	tracebackprint_exceptiontype__traceback__failedstrresultYESNOCHECKr-   writer1   )r9   r:   r;   r<   r=   r.   r>   r?   cachecachedsrcr`   sources_to_cachelockmanagerr    pendingr&   _r!   excchangeds                         r   rJ   rJ      s    " D%**T"2EZ0   //8&> 	-CKKW^^,	-IDGinni&:&:;; )||~) g
  !!$$2CtZQU 	
 
 **,	##FMM67C##FNNFGD #LLg>U>UVVGD! .iio>>#$$T* NN,,S,~~!11$s)S#BSBSTMM#s3x0-1[[]gkk

G "Y]]2"ioo5'WZZ:O(//4KKW-!. & ..)DtDDDH1BKK() O
 # 		 W& E  sz   C	ML0 6LL0 "A
L ,+L0 L+D2L0 L0 &L.'L0 ML0 	L($L0 'L((L0 .L0 0MM)returnasyncio.AbstractEventLoop)r    zIterable[asyncio.Future[Any]]ry   None)r.   rz   ry   r{   )F)r9   	set[Path]r:   boolr;   r   r<   r   r=   r   rK   z
int | Noner?   r}   ry   r{   )r9   r|   r:   r}   r;   r   r<   r   r=   r   r.   rz   r>   r   r?   r}   ry   r{   )(__doc__
__future__r   r   r'   rA   rZ   r   rd   collections.abcr   concurrent.futuresr   r   r   multiprocessingr   pathlibr	   typingr
   mypy_extensionsr   blackr   r   black.cacher   
black.moder   black.outputr   black.reportr   r   r   r   r1   rL   rJ    r"   r   <module>r      s)   #   	  
  $ P P #   & 1    (((, d ; ; 
;  ;  	; 
 ;  ;  ;  
;  ; L OO
O O 	O
 O $O O O 
Or"   