a
    g	g                     @   s
  d 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	m
Z
 ddlmZ ddlmZ ddlmZ eZeZe
eef Zeeef Zedd	d
Ze ZeedddZeedddZeedddZeee e
e	e e	e f dddZeee eddddZdS )z;Caching of formatted files with feature-based invalidation.    N)Path)DictIterableSetTuple)user_cache_dirversion)Mode)returnc                  C   s"   t dtd} ttjd| }|S )a[  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.
    Zblackr   ZBLACK_CACHE_DIR)r   __version__r   osenvironget)Zdefault_cache_dir	cache_dir r   N/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/black/cache.pyget_cache_dir   s    r   )moder   c                 C   s~   t | }| si S |dL}zt|}W n, tjttfyZ   i  Y W  d   S 0 W d   n1 sp0    Y  |S )zRead the cache if it exists and is well formed.

    If it is not well formed, the call to write_cache later should resolve the issue.
    rbN)get_cache_fileexistsopenpickleloadUnpicklingError
ValueError
IndexError)r   
cache_fileZfobjcacher   r   r   
read_cache(   s    6r    c                 C   s   t d|   d S )Nzcache.z.pickle)	CACHE_DIRZget_cache_key)r   r   r   r   r   :   s    r   )pathr   c                 C   s   |   }|j|jfS )zKReturn the information used to check if a file is already formatted or not.)statst_mtimest_size)r"   r#   r   r   r   get_cache_info>   s    r&   )r   sourcesr   c                 C   sT   t  t   }}|D ]8}| }| t|t|kr@|| q|| q||fS )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.
    )setresolver   strr&   add)r   r'   tododonesrcZres_srcr   r   r   filter_cachedD   s    r/   )r   r'   r   r   c                 C   s   t |}zztjddd i | dd |D }tjt|jdd }tj||dd W d	   n1 sh0    Y  t	
|j| W n ty   Y n0 d	S )
zUpdate the cache file.T)parentsexist_okc                 S   s   i | ]}t | t|qS r   )r*   r)   r&   ).0r.   r   r   r   
<dictcomp>[       zwrite_cache.<locals>.<dictcomp>F)dirdelete   )protocolN)r   r!   mkdirtempfileNamedTemporaryFiler*   parentr   dumpr   replacenameOSError)r   r'   r   r   Z	new_cachefr   r   r   write_cacheT   s    .rB   ) __doc__r   r   r:   pathlibr   typingr   r   r   r   Zplatformdirsr   Z_black_versionr	   r   Z
black.moder
   float	TimestampintZFileSize	CacheInfor*   Cacher   r!   r    r   r&   r/   rB   r   r   r   r   <module>   s&   &