ZL isddZddlmZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z mZddlmZddlmZddlmZmZdd lmZdd lmZmZdd lmZdd lmZdd lm Z ddl!m"Z"m#Z#ddZ$ddZ%ddZ&ed d ddZ' d ddZ(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)ExecutorProcessPoolExecutorThreadPoolExecutor)Manager)Path)AnyOptional) mypyc_attr) WriteBackformat_file_in_place)Cache)Mode)err)ChangedReportcL ddl}|jy#t$rYywxYw)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. rN)uvloopinstall ImportError)rs W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/black/concurrency.pymaybe_install_uvlooprs&      s  ##cHtd|D]}|jy)zFasyncio signal handler that cancels all `tasks` and reports to stderr.zAborted!N)rcancel)taskstasks rrr,s! O c tj|Dcgc]}|jr|}}|sF tjd}|j tj |jy|D]}|j|jtj|dditjd}|j tj |jycc}w#tjd}|j tj |jwxYw)zFCancel all pending tasks on `loop`, wait for them, and close the loop.zconcurrent.futuresNreturn_exceptionsT) asyncio all_tasksdonelogging getLoggersetLevelCRITICALcloserrun_until_completegather)loopr to_cancel cf_loggers rshutdownr.3s&-&7&7&=QdTYY[TQ Q %%&:; 7++,  D KKM   RT RS %%&:; 7++, R%%&:; 7++, s'DC=C=D=;D=DAET) patchablec 8t|Ettjj dd}|xstj xsd}t jdk(r t|d}d}|dkDr t|}| td}tj}tj | |j#t%|||||||| t'|tj d||j'yy#tttf$rYwxYw#tj dwxYw# t'|tj dn#tj dwxYw||j'wwxYw) z4Reformat multiple files using a ProcessPoolExecutor.NBLACK_NUM_WORKERSrwin32<) max_workers)sourcesfast write_backmodereportr+executorno_cache)rintosenvironget cpu_countsysplatformminrrNotImplementedErrorOSErrorrr!new_event_loopset_event_loopr)schedule_formattingr.) r6r7r8r9r:workersr<r;r+s r reformat_manyrKIssbjjnn%8!<=0R\\^0q ||wgr" $H{ *w?H%!4  ! ! #D 4    %!!   ) TN  " "4 (       =0':    :  " "4 ( ) TN  " "4 (G " "4 (       sB9 D="E D.D+*D+.EF E+F+FFc>K|rdntj|}|f|tjtjfvrD|j |\}} t | D]"} |j| tj$|syg} g} d} |tjtjfvrt}|j} t |D cic]1} tj|j|t| |||| | 3}} |j!} |j#t$j&t(||j#t$j*t(||r]tj.|tj0d{\}}|D]#}|j3|} |j5r| j7|7|j9x}rR|j:r*t=j>tA|||jB|jE| tG||jIrtjJntjL}|tjJus$|tjNur#|tjLur| j7| |j| |&|r]| rtjP| ddid{| r|s||jS| yyyycc} w#t,$rYwxYw777w)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)*rreadr DIFF COLOR_DIFFfiltered_cachedsortedr#rCACHEDrLockr! ensure_futurerun_in_executorrkeysadd_signal_handlersignalSIGINTrSIGTERMrEwaitFIRST_COMPLETEDpop cancelledappend exceptionverbose tracebackprint_exceptiontype __traceback__failedstrresultYESNOCHECKr*write)r6r7r8r9r:r+r;r<cachecachedsrcr_sources_to_cachelockmanagerrpendingr#_rexcchangeds rrIrIs"D%**T"2E Z0 //8&> -C KKW^^ , - I Dinni&:&:;;)||~'?      .T4T      E jjlG   vw? @  W':Q:QRRa *D))D/C~~  &(((>>--d3ic>O>OP c3s8,)-'++GJJ.)//1g6K$++C0 C)! * &nni@4@@@U-> $%.?I     S& As\CL6L LA L)+LLD2L L#L$$L LLLLL)returnNone)rzIterable['asyncio.Future[Any]']rxry)r+asyncio.AbstractEventLooprxry)F)r6 set[Path]r7boolr8r r9rr:rrJz Optional[int]r<r|rxry)r6r{r7r|r8r r9rr:z'Report'r+rzr;z 'Executor'r<r|rxry))__doc__ __future__rr!r$r>rYrBrccollections.abcrconcurrent.futuresrrrmultiprocessingrpathlibr typingr r mypy_extensionsr blackr r black.cacher black.moder black.outputr black.reportrrrrr.rKrIrrrs) # $PP# &1(  , d6 6 6 6   6  6  6 6  6 6 BI& I& I&I&  I&  I& $ I&I&I& I&r