
    j                        d 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m	Z	m
Z
 ddlm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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ed         ddfdZ"dej#        ddfdZ$ ed          de%e         de&dedede dee'         ddfd            Z(de%e         de&dededddej#        ddddfd Z)dS )"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.
    N)ExecutorProcessPoolExecutorThreadPoolExecutor)Manager)Path)AnyIterableOptional)
mypyc_attr)	WriteBackformat_file_in_place)Cache)Mode)err)ChangedReportreturnc                  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    [/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/black/concurrency.pymaybe_install_uvloopr      sH       s    
**tasksz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       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>4   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   shutdownr2   0   s&   QQg&7&=&=QQQ	 	 %&:;;	7+,,,

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

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

s    C2 ,=C2 2A	D;T)	patchablesourcesfast
write_backmodereportworkersc                 n   t                       |Dt          t          j                            dd                    }|pt          j                    pd}t          j        dk    rt          |d          }	 t          |          }n-# t          t          t          f$ r t          d          }Y nw xY w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)r4   r5   r6   r7   r8   r   executor)r   intosenvironget	cpu_countsysplatformminr   r   NotImplementedErrorOSErrorr   r'   new_event_loopset_event_loopr.   schedule_formattingr2   )r4   r5   r6   r7   r8   r9   r@   r   s           r   reformat_manyrN   F   s     bjnn%8!<<==0R\^^0q
|wgr""5&7;;;,g6 5 5 5
 &!4445 !##D4    %!  
	
 
	
 
	
	)TNNN"4((((G"4((((  		)TNNN"4((((G"4((((  sB   6B 'B10B1)E D* *E F4F.F4FF4r   r@   r   c                   K   t          j                  }t          j        t          j        fvrJ|                    |           \  } }t          |          D ]"}	|                    |	t          j	                   #| sdS g }
g }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|&                    |           dS dS )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$   srcr@   r5   lockr   r7   r6   s     r   
<dictcomp>z'schedule_formatting.<locals>.<dictcomp>   s`         	  .T4T 	
 	
   r   )return_whenr&   T)'r   readr   DIFF
COLOR_DIFFfiltered_cachedsortedr#   r   CACHEDr   Lockkeysadd_signal_handlersignalSIGINTr   SIGTERMrI   r'   waitFIRST_COMPLETEDpop	cancelledappend	exceptionverbose	tracebackprint_exceptiontype__traceback__failedstrresultYESNOCHECKr/   write)r4   r5   r6   r7   r8   r   r@   cachecachedrS   rf   sources_to_cachemanagerr   pendingr#   _r   excchangedrT   s    ``` ``             @r   rM   rM   y   s$       JtE).)*>???//88&>> 	- 	-CKKW^,,,, IDini&:;;; ))||~~         '??  E jjllGvw???@@@@     *W':QRRRRRRRRRa 	* 	*D))D//C~~ *  &&&&((( *> Q-d3iic>OPPPc3s88,,,,)-F'++GJ ..)/11g6K6K$++C000C))))%  *&  Ani@4@@@@@@@@@ &$%%%%%& &s   <AE	 	
EE)r   N)*__doc__r'   r)   rB   r`   rF   rj   concurrent.futuresr   r   r   multiprocessingr   pathlibr   typingr   r	   r
   mypy_extensionsr   blackr   r   black.cacher   
black.moder   black.outputr   black.reportr   r   r   r   AbstractEventLoopr2   setboolrA   rN   rM   r"   r   r   <module>r      s{      				  



     P P P P P P P P P P # # # # # #       * * * * * * * * * * & & & & & & 1 1 1 1 1 1 1 1                   ( ( ( ( ( ( ( (   (01 d    7,     , d/ Y/ 
/  /  	/ 
 /  c]/  
/  /  /  / dE&YE&
E& E& 	E&
 E& 
#E& E& 
E& E& E& E& E& E&r   