
    ^h                     0   S 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
  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  \R0                  S:  a  SSKJr  OSSKJr   " S S\5      rS\4S jr\" 5       rS\S\4S jr\	 " S S5      5       rg)z;Caching of formatted files with feature-based invalidation.    N)Iterable)	dataclassfield)Path)
NamedTuple)user_cache_dir)version)Mode)err)      )Selfc                   4    \ rS rSr% \\S'   \\S'   \\S'   Srg)FileData   st_mtimest_sizehash N)	__name__
__module____qualname____firstlineno__float__annotations__intstr__static_attributes__r       E/home/james-whalen/.local/lib/python3.13/site-packages/black/cache.pyr   r      s    OL
Ir   r   returnc                      [        S5      n [        [        R                  R	                  SU 5      5      nU[
        -  nU$ )aC  Get the cache directory used by black.

Users can customize this directory on all systems using `BLACK_CACHE_DIR`
environment variable. By default, the cache directory is the user cache directory
under the black application.

This result is immediately set to a constant `black.cache.CACHE_DIR` as to avoid
repeated calls.
blackBLACK_CACHE_DIR)r   r   osenvironget__version__)default_cache_dir	cache_dirs     r    get_cache_dirr+      s:     'w/RZZ^^$57HIJIK'Ir   modec                 8    [         SU R                  5        S3-  $ )Nzcache.z.pickle)	CACHE_DIRget_cache_key)r,   s    r    get_cache_filer0   3   s      2 2 45W===r   c                       \ rS rSr% \\S'   \\S'   \" \S9r	\\
\4   \S'   \S\S\4S j5       r\S\S\
4S	 j5       r\S\S\4S
 j5       rS\S\4S jrS\\   S\\\   \\   4   4S jrS\\   SS4S jrSrg)Cache7   r,   
cache_file)default_factory	file_datar!   c           	         [        U5      n UR                  5       nU(       d  U " X5      $ UR	                  S5       n [
        R                  " U5      nUR                  5        VVs0 s H  u  pxU[        U6 _M     n	nn SSS5        U " XW	5      $ ! [         a#  n[        SU SU 35        U " X5      s SnA$ SnAff = fs  snnf ! [
        R                  [        [        4 a    U " X5      s sSSS5        $ f = f! , (       d  f       N= f)z}Read the cache if it exists and is well-formed.

If it is not well-formed, the call to write later should
resolve the issue.
zUnable to read cache file z due to Nrb)r0   existsOSErrorr   openpickleloaditemsr   UnpicklingError
ValueError
IndexError)
clsr,   r4   r9   efobjdatakvr6   s
             r    read
Cache.read=   s     $D)
	)&&(F
 t((__T"d-:@++d:K9=FQ!_	F	 # 4Y//  	),ZLDEt((	) G**J
C -4,, #"-	 #"sW   B C>)C(C=C
B?B:4B?:B?C'C;/C>:C;;C>>
Dpathc                 j    U R                  5       n[        R                  " U5      R                  5       $ )zReturn hash digest for path.)
read_byteshashlibsha256	hexdigest)rJ   rE   s     r    hash_digestCache.hash_digestW   s(      ~~d#--//r   c                     U R                  5       n[        R                  U 5      n[        UR                  UR
                  U5      $ )zReturn file data for path.)statr2   rP   r   r   r   )rJ   rS   r   s      r    get_file_dataCache.get_file_data^   s6     yy{  &t||T::r   sourcec                 H   UR                  5       nU R                  R                  [        U5      5      nUc  gUR	                  5       nUR
                  UR
                  :w  a  gUR                  UR                  :w  a%  [        R                  U5      nXSR                  :w  a  gg)z7Check if source has changed compared to cached version.TF)
resolver6   r'   r   rS   r   r   r2   rP   r   )selfrV   res_srcoldstnew_hashs         r    
is_changedCache.is_changedf   s|    .."nn  W.;\\^::$;;#,,&((1H88#r   sourcesc                     [        5       n[        5       nU H=  nU R                  U5      (       a  UR                  U5        M,  UR                  U5        M?     X#4$ )zSplit an iterable of paths in `sources` into two sets.

The first contains paths of files that modified on disk or are not in the
cache. The other contains paths to non-modified files.
)setr^   add)rY   r`   changeddonesrcs        r    filtered_cachedCache.filtered_cachedv   sL     !U%Cs##C 	 
 }r   Nc                    U R                   R                  " S0 U Vs0 s H0  n[        UR                  5       5      [        R                  U5      _M2     snD6   [        R                  SSS9  [        R                  " [        U R                  R                  5      SS9 nU R                   R                  5        VVs0 s H  u  pEU/ UQ7_M     nnn[        R                  " XcSS9  SSS5        [        R                   " WR"                  U R                  5        gs  snf s  snnf ! , (       d  f       NE= f! [$         a     gf = f)	z6Update the cache file data and write a new cache file.T)parentsexist_okF)dirdelete   )protocolNr   )r6   updater   rX   r2   rT   r.   mkdirtempfileNamedTemporaryFiler4   parentr>   r<   dumpr%   replacenamer:   )rY   r`   rf   frF   rG   rE   s          r    writeCache.write   s    	
GNOws3;;=!5#6#6s#;;wO	
	OOD4O8,,../ *.)=)=)?;)?AuuH)?  ; Da0 JJqvvt/ P;	   		sB   7DAD8  D'>D!D'(3D8 !D''
D51D8 8
EEr   )r   r   r   r   r
   r   r   r   dictr6   r   r   classmethodr   rH   staticmethodrP   rT   boolr^   r   tuplerb   rg   ry   r   r   r   r    r2   r2   7   s    
J%*4%@ItCM"@0 0 0 02 0$ 03 0 0 ;D ;X ; ; $  x~ %D	3t9@T:U Xd^  r   r2   ) __doc__rM   r%   r<   sysrr   collections.abcr   dataclassesr   r   pathlibr   typingr   platformdirsr   _black_versionr	   r(   
black.moder
   black.outputr   version_infor   typing_extensionsr   r+   r.   r0   r2   r   r   r    <module>r      s    A  	  
  $ (   ' 1  w&z t " O	> >$ > ^ ^ ^r   