
    nia                    .   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Nonec                 Z    	 ddl } |                                  dS # t          $ r Y dS w xY w)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    N/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/black/concurrency.pymaybe_install_uvloopr      sH       s    
**tasksIterable[asyncio.Future[Any]]c                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   ,   s5    
OOO       loopasyncio.AbstractEventLoopc                |   	 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>7   s%    QQQdTYY[[QTQQQr    zconcurrent.futuresNreturn_exceptionsT)
asyncio	all_taskslogging	getLoggersetLevelCRITICALcloser   run_until_completegather)r!   	to_cancel	cf_loggerr   s       r   shutdownr5   3   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                   t                       |Dt          t          j                            dd                    }|pt          j                    pd}t          j        dk    rt          |d          }d}|dk    r/	 t          |          }n# t          t          t          f$ r Y nw xY w|t          d          }t          j                    }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      win32<   )max_workers)r7   r9   r;   r<   r=   r!   executorr@   )r   intosenvironget	cpu_countsysplatformminr   r   NotImplementedErrorOSErrorr   r*   new_event_loopset_event_loopr1   schedule_formattingr5   )	r7   r9   r;   r<   r=   r>   r@   rG   r!   s	            r   reformat_manyrU   I   s    bjnn%8!<<==0R\^^0q
|wgr"" $H{{	*w???HH0': 	 	 	
 D	 %!444!##D4    %!!	 	 		
 	
 	
	)TNNN"4((((G"4((((  		)TNNN"4((((G"4((((  sB   >B B)(B)&*E( D5 5E(F?*F9F?F$$F?rG   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'   srcrG   r9   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   SIGTERMrP   r*   waitFIRST_COMPLETEDpop	cancelledappend	exceptionverbose	tracebackprint_exceptiontype__traceback__failedstrresultYESNOCHECKr2   writer5   )r7   r9   r;   r<   r=   r!   rG   r@   cachecachedrZ   rm   sources_to_cachemanagerr   pendingr&   _r   excchangedr[   s    ``` ``              @r   rT   rT      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)r7   r8   r9   r:   r;   r   r<   r   r=   r   r>   r?   r@   r:   r   r   )r7   r8   r9   r:   r;   r   r<   r   r=   r   r!   r"   rG   r   r@   r:   r   r   )(__doc__
__future__r   r*   r,   rI   rg   rM   rq   collections.abcr   concurrent.futuresr   r   r   multiprocessingr   pathlibr	   typingr
   mypy_extensionsr   blackr   r   black.cacher   
black.moder   black.outputr   black.reportr   r   r   r   r5   rU   rT   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 6  6  6  6  6 B O O O O O O Or    