
    ^h                    \   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJrJrJr  SSKJr  SSKJr  SSKJrJr  SS	KJr  SS
KJrJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"J#r#  SS jr$SS jr%SS jr&\" SS9              SS j5       r'                SS jr(g)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Optional)
mypyc_attr)	WriteBackformat_file_in_place)Cache)Mode)err)ChangedReportc                 N     SSK n U R                  5         g! [         a     gf = f)zIf our environment has uvloop installed we use it.

This is called only from command-line entry points to avoid
interfering with the parent process if Black is used as a library.
r   N)uvloopinstallImportError)r   s    K/home/james-whalen/.local/lib/python3.13/site-packages/black/concurrency.pymaybe_install_uvloopr      s&     s    
$$c                L    [        S5        U  H  nUR                  5         M     g)zFasyncio signal handler that cancels all `tasks` and reports to stderr.zAborted!N)r   cancel)taskstasks     r   r   r   ,   s    
O     c                    [         R                  " U 5       Vs/ s H  oR                  5       (       a  M  UPM     nnU(       dG   [        R                  " S5      nUR                  [        R                  5        U R                  5         gU H  nUR                  5         M     U R                  [         R                  " USS065        [        R                  " S5      nUR                  [        R                  5        U R                  5         gs  snf ! [        R                  " S5      nUR                  [        R                  5        U R                  5         f = f)zFCancel all pending tasks on `loop`, wait for them, and close the loop.zconcurrent.futuresNreturn_exceptionsT)asyncio	all_tasksdonelogging	getLoggersetLevelCRITICALcloser   run_until_completegather)loopr   	to_cancel	cf_loggers       r   shutdownr.   3   s    &-&7&7&=Q&=dYY[T&=	Q %%&:;	7++,

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

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

s'   D DD	D >D D AET)	patchablec                T   [        5         UcP  [        [        R                  R	                  SS5      5      nU=(       d    [        R
                  " 5       =(       d    Sn[        R                  S:X  a  [        US5      nSnUS:  a
   [        US9nUc	  [        SS9n[        R                  " 5       n[        R                   " U5         UR#                  [%        U UUUUUUS95         ['        U5        [        R                   " S5        Ub  UR'                  5         gg! [        [        [        4 a     Nf = f! [        R                   " S5        f = f!  ['        U5        [        R                   " S5        O! [        R                   " S5        f = fUb  UR'                  5         f f = f)	z4Reformat multiple files using a ProcessPoolExecutor.NBLACK_NUM_WORKERSr      win32<   )max_workers)sourcesfast
write_backmodereportr+   executor)r   intosenvironget	cpu_countsysplatformminr   r   NotImplementedErrorOSErrorr   r!   new_event_loopset_event_loopr)   schedule_formattingr.   )r6   r7   r8   r9   r:   workersr;   r+   s           r   reformat_manyrJ   I   sp    bjjnn%8!<=0R\\^0q
||wgr" $H{	*w?H %!4!!#D4  %!
	
	)TN""4(  ; 0': 	
 	8 ""4(	)TN""4(G""4(  sB   	D E 'D8 D54D58EF'E7 F'7FF'c                  #    [         R                  " U5      nU[        R                  [        R                  4;  aE  UR                  U 5      u  p[        U5       H#  n	UR                  U	[        R                  5        M%     U (       d  g/ n
/ nSnU[        R                  [        R                  4;   a  [        5       nUR                  5       n[        U 5       V	s0 s H1  n	[        R                  " UR                  U[        XX2U5      5      U	_M3     nn	UR!                  5       n UR#                  [$        R&                  [(        U5        UR#                  [$        R*                  [(        U5        U(       Ga}  [        R.                  " U[        R0                  S9I Sh  vN u  nnU GH>  nUR3                  U5      n	UR5                  5       (       a  U
R7                  U5        M=  UR9                  5       =n(       aY  UR:                  (       a+  [<        R>                  " [A        U5      UURB                  5        URE                  U	[G        U5      5        M  URI                  5       (       a  [        RJ                  O[        RL                  nU[        RJ                  L d&  U[        RN                  L a$  U[        RL                  L a  UR7                  U	5        UR                  U	U5        GMA     U(       a  GM}  U
(       a  [        RP                  " U
SS06I Sh  vN   U(       a  URS                  U5        ggs  sn	f ! [,         a     GNf = f GN N77f)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   SIGTERMrD   waitFIRST_COMPLETEDpop	cancelledappend	exceptionverbose	tracebackprint_exceptiontype__traceback__failedstrresultYESNOCHECKr*   write)r6   r7   r8   r9   r:   r+   r;   cachecachedsrcr^   sources_to_cachelockmanagerr   pendingr#   _r   excchangeds                        r   rH   rH      s      JJtE)..)*>*>??//8&>CKKW^^, "IDinni&:&:;; )||~ '? #C 	  .4T	
 		
 # 
  jjlGvw?@ W':Q:QRRaD))D/C~~  &(((>>--d3ic>O>OPc3s8,)-'++GJJ .)//1g6K$++C0C)!  '& nni@4@@@$% I   S& 	As\   CM8L4M&A
L9 0.MM
EM5 MM#M9
MMMMM)returnNone)r   zIterable['asyncio.Future[Any]']rw   rx   )r+   asyncio.AbstractEventLooprw   rx   )r6   	set[Path]r7   boolr8   r   r9   r   r:   r   rI   zOptional[int]rw   rx   )r6   rz   r7   r{   r8   r   r9   r   r:   z'Report'r+   ry   r;   z
'Executor'rw   rx   ))__doc__
__future__r   r!   r$   r=   rX   rA   rb   collections.abcr   concurrent.futuresr   r   r   multiprocessingr   pathlibr	   typingr
   r   mypy_extensionsr   blackr   r   black.cacher   
black.moder   black.outputr   black.reportr   r   r   r   r.   rJ   rH    r   r   <module>r      s
   #   	  
  $ P P #    & 1    (, d4 4 
4  4  	4 
 4  4  
4  4 nE&E&
E& E& 	E&
 E& $E& E& 
E&r   