
    h                    X   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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       Z'	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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Optional)
mypyc_attr)	WriteBackformat_file_in_place)Cache)Mode)err)ChangedReportc                 L    	 ddl } | j                          y# t        $ r Y y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    D/var/www/html/immo/lib/python3.12/site-packages/black/concurrency.pymaybe_install_uvloopr      s&     s    	##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   ,   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)asyncio	all_tasksdonelogging	getLoggersetLevelCRITICALcloser   run_until_completegather)loopr   	to_cancel	cf_loggers       r   shutdownr.   3   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   t                |Et        t        j                  j	                  dd            }|xs t        j
                         xs d}t        j                  dk(  rt        |d      }d}|dkD  r	 t        |      }|t        d      }t        j                         }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      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   9D =!E D- D*)D*-EF	E*F*FFc                &  K   t        j                  |      }|t        j                  t        j                  fvrD|j                  |       \  } }t        |      D ]"  }	|j                  |	t        j                         $ | syg }
g }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|jS                  |       yyc c}	w # t,        $ r Y w xY w7 ~7 1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   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&:&:;; )||~ '?  	  .T4T	
 		E  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L6K7LA
K< #+LLD2LLLL<	L	LL		LL)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   