+
    ~j                        R t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHtHt ^RIHt ^RIHt ^R	IHt ^R
IHt ]P,                  ! ]4      t]
R ,          tR.t]! RR7       ! R R4      4       t]! RR7       ! R R4      4       t]! RR7       ! R R4      4       t]! RR7       ! R R4      4       t]! RR7       ! R R4      4       tR!R R llt R R lt!R R lt"R R lt#R# )"z4Contains utilities to manage the HF cache directory.N)defaultdict)	dataclass)Path)Literal)CacheNotFoundCorruptedCacheException)HF_HUB_CACHE)logging)format_timesince)tabulatez	.DS_StoreT)frozenc                      a  ] tR t^'t o Rt]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       tV 3R lt	R	t
V tR
# )CachedFileInfoa  Frozen data structure holding information about a single cached file.

Args:
    file_name (`str`):
        Name of the file. Example: `config.json`.
    file_path (`Path`):
        Path of the file in the `snapshots` directory. The file path is a symlink
        referring to a blob in the `blobs` folder.
    blob_path (`Path`):
        Path of the blob file. This is equivalent to `file_path.resolve()`.
    size_on_disk (`int`):
        Size of the blob file in bytes.
    blob_last_accessed (`float`):
        Timestamp of the last time the blob file has been accessed (from any
        revision).
    blob_last_modified (`float`):
        Timestamp of the last time the blob file has been modified/created.

> [!WARNING]
> `blob_last_accessed` and `blob_last_modified` reliability can depend on the OS you
> are using. See [python documentation](https://docs.python.org/3/library/os.html#os.stat_result)
> for more details.
c                    < V ^8  d   QhRS[ /#    returnstr)format__classdict__s   "y/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/huggingface_hub/utils/_cache_manager.py__annotate__CachedFileInfo.__annotate__J        9 9 9    c                ,    \        V P                  4      # )z
(property) Timestamp of the last time the blob file has been accessed (from any
revision), returned as a human-readable string.

Example: "2 weeks ago".
)r
   blob_last_accessedselfs   &r   blob_last_accessed_str%CachedFileInfo.blob_last_accessed_strI          7 788r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r   T   r   r   c                ,    \        V P                  4      # )z
(property) Timestamp of the last time the blob file has been modified, returned
as a human-readable string.

Example: "2 weeks ago".
)r
   blob_last_modifiedr   s   &r   blob_last_modified_str%CachedFileInfo.blob_last_modified_strS   r"   r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r   ^        / /# /r   c                ,    \        V P                  4      # )zQ
(property) Size of the blob file as a human-readable string.

Example: "42.2K".
_format_sizesize_on_diskr   s   &r   size_on_disk_strCachedFileInfo.size_on_disk_str]        D--..r   c                b   < V ^8  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[;R&   S[;R&   S[;R&   # )r   	file_name	file_path	blob_pathr-   r   r%   )r   r   intfloat)r   r   s   "r   r   r   '   sR     4 N5 6 O7 8 O9 : ; > ? @ A r    N)__name__
__module____qualname____firstlineno____doc__propertyr    r&   r.   __annotate_func____static_attributes____classdictcell__r   s   @r   r   r   '   sO     @ 9 9 9 9 / /o  r   r   c                      a  ] tR t^gt o Rt]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       tV 3R lt	R	t
V tR
# )CachedRevisionInfoa  Frozen data structure holding information about a revision.

A revision correspond to a folder in the `snapshots` folder and is populated with
the exact tree structure as the repo on the Hub but contains only symlinks. A
revision can be either referenced by 1 or more `refs` or be "detached" (no refs).

Args:
    commit_hash (`str`):
        Hash of the revision (unique).
        Example: `"9338f7b671827df886678df2bdd7cc7b4f36dffd"`.
    snapshot_path (`Path`):
        Path to the revision directory in the `snapshots` folder. It contains the
        exact tree structure as the repo on the Hub.
    files: (`frozenset[CachedFileInfo]`):
        Set of [`~CachedFileInfo`] describing all files contained in the snapshot.
    refs (`frozenset[str]`):
        Set of `refs` pointing to this revision. If the revision has no `refs`, it
        is considered detached.
        Example: `{"main", "2.4.0"}` or `{"refs/pr/1"}`.
    size_on_disk (`int`):
        Sum of the blob file sizes that are symlink-ed by the revision.
    last_modified (`float`):
        Timestamp of the last time the revision has been created/modified.

> [!WARNING]
> `last_accessed` cannot be determined correctly on a single revision as blob files
> are shared across revisions.

> [!WARNING]
> `size_on_disk` is not necessarily the sum of all file sizes because of possible
> duplicated files. Besides, only blobs are taken into account, not the (negligible)
> size of folders and symlinks.
c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   CachedRevisionInfo.__annotate__        4 43 4r   c                ,    \        V P                  4      # )z
(property) Timestamp of the last time the revision has been modified, returned
as a human-readable string.

Example: "2 weeks ago".
r
   last_modifiedr   s   &r   last_modified_str$CachedRevisionInfo.last_modified_str          2 233r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   rE      r)   r   c                ,    \        V P                  4      # zV
(property) Sum of the blob file sizes as a human-readable string.

Example: "42.2K".
r+   r   s   &r   r.   #CachedRevisionInfo.size_on_disk_str   r0   r   c                    < V ^8  d   QhRS[ /# r   )r5   )r   r   s   "r   r   rE      s      # r   c                ,    \        V P                  4      # )z3
(property) Total number of files in the revision.
)lenfilesr   s   &r   nb_filesCachedRevisionInfo.nb_files   s    
 4::r   c                   < V ^8  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[S[,          ;R&   S[S[ ,          ;R&   S[;R&   # )r   commit_hashsnapshot_pathr-   rT   refsrI   )r   r   r5   	frozensetr   r6   )r   r   s   "r   r   rE   g   sh     H I J K L M N ^$$O P C.Q T U r   r7   N)r8   r9   r:   r;   r<   r=   rJ   r.   rU   r>   r?   r@   rA   s   @r   rC   rC   g   sO      T 4 4 / /  A  r   rC   c                      a  ] tR t^t o Rt]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR	 l4       t	]V 3R
 lR l4       t
V 3R ltRtV tR# )CachedRepoInfoa  Frozen data structure holding information about a cached repository.

Args:
    repo_id (`str`):
        Repo id of the repo on the Hub. Example: `"google/fleurs"`.
    repo_type (`Literal["dataset", "model", "space"]`):
        Type of the cached repo.
    repo_path (`Path`):
        Local path to the cached repo.
    size_on_disk (`int`):
        Sum of the blob file sizes in the cached repo.
    nb_files (`int`):
        Total number of blob files in the cached repo.
    revisions (`frozenset[CachedRevisionInfo]`):
        Set of [`~CachedRevisionInfo`] describing all revisions cached in the repo.
    last_accessed (`float`):
        Timestamp of the last time a blob file of the repo has been accessed.
    last_modified (`float`):
        Timestamp of the last time a blob file of the repo has been modified/created.

> [!WARNING]
> `size_on_disk` is not necessarily the sum of all revisions sizes because of
> duplicated files. Besides, only blobs are taken into account, not the (negligible)
> size of folders and symlinks.

> [!WARNING]
> `last_accessed` and `last_modified` reliability can depend on the OS you are using.
> See [python documentation](https://docs.python.org/3/library/os.html#os.stat_result)
> for more details.
c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   CachedRepoInfo.__annotate__   rF   r   c                ,    \        V P                  4      # )z
(property) Last time a blob file of the repo has been accessed, returned as a
human-readable string.

Example: "2 weeks ago".
)r
   last_accessedr   s   &r   last_accessed_str CachedRepoInfo.last_accessed_str   rL   r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r_      rF   r   c                ,    \        V P                  4      # )z
(property) Last time a blob file of the repo has been modified, returned as a
human-readable string.

Example: "2 weeks ago".
rH   r   s   &r   rJ    CachedRepoInfo.last_modified_str   rL   r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r_      r)   r   c                ,    \        V P                  4      # rO   r+   r   s   &r   r.   CachedRepoInfo.size_on_disk_str   r0   r   c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   r_      s     2 2# 2r   c                8    V P                    RV P                   2# )z9Canonical `type/id` identifier used across cache tooling./)	repo_typerepo_idr   s   &r   cache_idCachedRepoInfo.cache_id   s     ..!4<<.11r   c                6   < V ^8  d   QhRS[ S[S[3,          /# r   )dictr   rC   )r   r   s   "r   r   r_      s"     W Wd3 223 Wr   c                n    V P                    UUu/ uF  qP                   F  q"VbK  	  K  	  upp# u uppi )zA
(property) Mapping between `refs` and revision data structures.
)	revisionsrZ   )r   revisionrefs   &  r   rZ   CachedRepoInfo.refs   s,    
 /3nnVn(XnVVVs   1c                   < V ^8  d   Qh/ S[ ;R&   S[;R&   S[;R&   S[;R&   S[;R&   S[S[,          ;R&   S[;R&   S[;R&   # )	r   rn   rm   	repo_pathr-   rU   rt   ra   rI   )r   REPO_TYPE_Tr   r5   r[   rC   r6   )r   r   s   "r   r   r_      s     B LC D E F OG H I J MK L +,,M P Q R S r   r7   N)r8   r9   r:   r;   r<   r=   rb   rJ   r.   ro   rZ   r>   r?   r@   rA   s   @r   r]   r]      sy     R 4 4 4 4 / / 2 2 W W]  r   r]   c                   ^   a  ] tR tRt o Rt]V 3R lR l4       tV 3R lR ltV 3R ltRt	V t
R	# )
DeleteCacheStrategyi  a  Frozen data structure holding the strategy to delete cached revisions.

This object is not meant to be instantiated programmatically but to be returned by
[`~utils.HFCacheInfo.delete_revisions`]. See documentation for usage example.

Args:
    expected_freed_size (`float`):
        Expected freed size once strategy is executed.
    blobs (`frozenset[Path]`):
        Set of blob file paths to be deleted.
    refs (`frozenset[Path]`):
        Set of reference file paths to be deleted.
    repos (`frozenset[Path]`):
        Set of entire repo paths to be deleted.
    snapshots (`frozenset[Path]`):
        Set of snapshots to be deleted (directory of symlinks).
c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r    DeleteCacheStrategy.__annotate__  s     6 6 6r   c                ,    \        V P                  4      # )z\
(property) Expected size that will be freed as a human-readable string.

Example: "42.2K".
)r,   expected_freed_sizer   s   &r   expected_freed_size_str+DeleteCacheStrategy.expected_freed_size_str  s     D4455r   c                   < V ^8  d   QhRR/# )r   r   Nr7   )r   r   s   "r   r   r~   &  s      S  S  Sr   c                L   V P                    F  p\        VRR7       K  	  V P                   F  p\        VRR7       K  	  V P                   F  p\        VRR7       K  	  V P                   F  p\        VRR7       K  	  \
        P                  RV P                   R24       R# )	aJ  Execute the defined strategy.

> [!WARNING]
> If this method is interrupted, the cache might get corrupted. Deletion order is
> implemented so that references and symlinks are deleted before the actual blob
> files.

> [!WARNING]
> This method is irreversible. If executed, cached files are erased and must be
> downloaded again.
repo)	path_typesnapshotrv   blobzCache deletion done. Saved .N)repos_try_delete_path	snapshotsrZ   blobsloggerinfor   )r   paths   & r   executeDeleteCacheStrategy.execute&  s    " JJDTV4  NNDTZ8 # IIDTU3  JJDTV4  	1$2N2N1OqQRr   c                   < V ^8  d   Qh/ S[ ;R&   S[S[,          ;R&   S[S[,          ;R&   S[S[,          ;R&   S[S[,          ;R&   # )r   r   r   rZ   r   r   )r5   r[   r   )r   r   s   "r   r   r~     sV     ( ) * T?+ , D/- . T?/ 0 1 r   r7   N)r8   r9   r:   r;   r<   r=   r   r   r>   r?   r@   rA   s   @r   r|   r|     s2     0 6 6 S  SG  r   r|   c                   x   a  ] tR tRt o Rt]V 3R lR l4       tV 3R lR ltR^ /V 3R lR	 lltV 3R
 lt	Rt
V tR# )HFCacheInfoiI  a7  Frozen data structure holding information about the entire cache-system.

This data structure is returned by [`scan_cache_dir`] and is immutable.

Args:
    size_on_disk (`int`):
        Sum of all valid repo sizes in the cache-system.
    repos (`frozenset[CachedRepoInfo]`):
        Set of [`~CachedRepoInfo`] describing all valid cached repos found on the
        cache-system while scanning.
    warnings (`list[CorruptedCacheException]`):
        List of [`~CorruptedCacheException`] that occurred while scanning the cache.
        Those exceptions are captured so that the scan can continue. Corrupted repos
        are skipped from the scan.

> [!WARNING]
> Here `size_on_disk` is equal to the sum of all repo sizes (only blobs). However if
> some cached repos are corrupted, their sizes are not taken into account.
c                    < V ^8  d   QhRS[ /# r   r   )r   r   s   "r   r   HFCacheInfo.__annotate__d  s     / /# /r   c                ,    \        V P                  4      # )zk
(property) Sum of all valid repo sizes in the cache-system as a human-readable
string.

Example: "42.2K".
r+   r   s   &r   r.   HFCacheInfo.size_on_disk_strc  s     D--..r   c                &   < V ^8  d   QhRS[ RS[/# )r   rt   r   )r   r|   )r   r   s   "r   r   r   m  s      b
 b
3 b
3F b
r   c                   \        V4      p\        \         4      pV P                   F[  pVP                   FH  pVP                  V9   g   K  W4,          P                  V4       VP                  VP                  4       KJ  	  K]  	  \        V4      ^ 8  d(   \        P                  RRP                  V4       24       \        4       p\        4       p\        4       p\        4       p	^ p
VP                  4        EF_  w  rVP                  V,
          p\        V4      ^ 8X  d0   VP                  VP                  4       WP                  ,          p
KX  V EF   pV	P                  VP                  4       VP                   F,  pVP                  VP                  R,          V,          4       K.  	  VP                    F  pVP"                  V9  g   K  RpV F?  pVP                    F"  pVP"                  VP"                  8X  g   K   Rp M	  V'       d   K?   M	  V'       g   Kg  VP                  VP"                  4       V
VP                  ,          p
K  	  EK  	  EKb  	  \%        \'        V4      \'        V4      \'        V4      \'        V	4      V
R7      # )a  Prepare the strategy to delete one or more revisions cached locally.

Input revisions can be any revision hash. If a revision hash is not found in the
local cache, a warning is thrown but no error is raised. Revisions can be from
different cached repos since hashes are unique across repos,

Examples:
```py
>>> from huggingface_hub import scan_cache_dir
>>> cache_info = scan_cache_dir()
>>> delete_strategy = cache_info.delete_revisions(
...     "81fd1d6e7847c99f5862c9fb81387956d99ec7aa"
... )
>>> print(f"Will free {delete_strategy.expected_freed_size_str}.")
Will free 7.9K.
>>> delete_strategy.execute()
Cache deletion done. Saved 7.9K.
```

```py
>>> from huggingface_hub import scan_cache_dir
>>> scan_cache_dir().delete_revisions(
...     "81fd1d6e7847c99f5862c9fb81387956d99ec7aa",
...     "e2983b237dccf3ab4937c97fa717319a9ca1a96d",
...     "6c0e6080953db56375760c0471a8c5f2929baf11",
... ).execute()
Cache deletion done. Saved 8.6G.
```

> [!WARNING]
> `delete_revisions` returns a [`~utils.DeleteCacheStrategy`] object that needs to
> be executed. The [`~utils.DeleteCacheStrategy`] is not meant to be modified but
> allows having a dry run before actually executing the deletion.
z,Revision(s) not found - cannot delete them: , rZ   TF)r   rZ   r   r   r   )setr   r   rt   rX   addremoverS   r   warningjoinitemsry   r-   rY   rZ   rT   r4   r|   r[   )r   rt   hashes_to_deleterepos_with_revisionsr   ru   delete_strategy_blobsdelete_strategy_refsdelete_strategy_reposdelete_strategy_snapshots#delete_strategy_expected_freed_sizeaffected_reporevisions_to_deleteother_revisionsrevision_to_deleterv   fileis_file_alonerev_files   &*                 r   delete_revisionsHFCacheInfo.delete_revisionsm  s1   F &)^NYZ]N^JJD NN''+;;(.228<$++H,@,@A +   1$NNI$))TdJeIfgh+.5*-%+.5/2u!./+2F2L2L2N.M+558KKO ?#q(%))-*A*AB37Q7QQ3 ':")--.@.N.NO .22C(,,]-D-Dv-MPS-ST 3 /44D~~-BB(,(7H,4NN#'>>X5G5G#G49M$) -; $1= % )8 )=155dnnE?4CTCTT? 5 ': 3OL #12/012 9: C
 	
r   	verbosityc                &   < V ^8  d   QhRS[ RS[/# )r   r   r   r5   r   )r   r   s   "r   r   r     s     \ \C \ \r   c               (   V^ 8X  d   \        \        V P                  R R7       Uu. uF  pVP                  VP                  VP
                  R VP                  VP                  VP                  RP                  \        VP                  4      4      \        VP                  4      .NK  	  up. ROR7      # \        \        V P                  R R7       UUu. uF  p\        VP                  R R7       F  pVP                  VP                  VP                  VP
                  R VP                  VP                  RP                  \        VP                  4      4      \        VP                  4      .NK  	  K  	  upp. R	OR7      # u upi u uppi )
a  Generate a table from the [`HFCacheInfo`] object.

Pass `verbosity=0` to get a table with a single row per repo, with columns
"repo_id", "repo_type", "size_on_disk", "nb_files", "last_accessed", "last_modified", "refs", "local_path".

Pass `verbosity=1` to get a table with a row per repo and revision (thus multiple rows can appear for a single repo), with columns
"repo_id", "repo_type", "revision", "size_on_disk", "nb_files", "last_modified", "refs", "local_path".

Example:
```py
>>> from huggingface_hub.utils import scan_cache_dir

>>> hf_cache_info = scan_cache_dir()
HFCacheInfo(...)

>>> print(hf_cache_info.export_as_table())
REPO ID                                             REPO TYPE SIZE ON DISK NB FILES LAST_ACCESSED LAST_MODIFIED REFS LOCAL PATH
--------------------------------------------------- --------- ------------ -------- ------------- ------------- ---- --------------------------------------------------------------------------------------------------
roberta-base                                        model             2.7M        5 1 day ago     1 week ago    main ~/.cache/huggingface/hub/models--roberta-base
suno/bark                                           model             8.8K        1 1 week ago    1 week ago    main ~/.cache/huggingface/hub/models--suno--bark
t5-base                                             model           893.8M        4 4 days ago    7 months ago  main ~/.cache/huggingface/hub/models--t5-base
t5-large                                            model             3.0G        4 5 weeks ago   5 months ago  main ~/.cache/huggingface/hub/models--t5-large

>>> print(hf_cache_info.export_as_table(verbosity=1))
REPO ID                                             REPO TYPE REVISION                                 SIZE ON DISK NB FILES LAST_MODIFIED REFS LOCAL PATH
--------------------------------------------------- --------- ---------------------------------------- ------------ -------- ------------- ---- -----------------------------------------------------------------------------------------------------------------------------------------------------
roberta-base                                        model     e2da8e2f811d1448a5b465c236feacd80ffbac7b         2.7M        5 1 week ago    main ~/.cache/huggingface/hub/models--roberta-base/snapshots/e2da8e2f811d1448a5b465c236feacd80ffbac7b
suno/bark                                           model     70a8a7d34168586dc5d028fa9666aceade177992         8.8K        1 1 week ago    main ~/.cache/huggingface/hub/models--suno--bark/snapshots/70a8a7d34168586dc5d028fa9666aceade177992
t5-base                                             model     a9723ea7f1b39c1eae772870f3b547bf6ef7e6c1       893.8M        4 7 months ago  main ~/.cache/huggingface/hub/models--t5-base/snapshots/a9723ea7f1b39c1eae772870f3b547bf6ef7e6c1
t5-large                                            model     150ebc2c4b72291e770f58e6057481c8d2ed331a         3.0G        4 5 months ago  main ~/.cache/huggingface/hub/models--t5-large/snapshots/150ebc2c4b72291e770f58e6057481c8d2ed331a
```

Args:
    verbosity (`int`, *optional*):
        The verbosity level. Defaults to 0.

Returns:
    `str`: The table as a string.
c                     V P                   # Nry   r   s   &r   <lambda>-HFCacheInfo.export_as_table.<locals>.<lambda>      DNNr   )keyz>12r   )rowsheadersc                     V P                   # r   r   r   s   &r   r   r      r   r   c                     V P                   # r   )rX   )ru   s   &r   r   r   !  s    PXPdPdr   )REPO ID	REPO TYPESIZE ON DISKNB FILESLAST_ACCESSEDLAST_MODIFIEDREFS
LOCAL PATH)r   r   REVISIONr   r   r   r   r   )r   sortedr   rn   rm   r.   rU   rb   rJ   r   rZ   r   ry   rt   rX   rY   )r   r   r   ru   s   &$  r   export_as_tableHFCacheInfo.export_as_table  sj   P > !'tzz7R S !T 005....		&"34DNN+	 !T	 4  !'tzz7R S !T$*4>>?d$e  ,,#44S9 )) 22		&"78H223	 %f	 !T	 34s   BF	B%F
c                ^   < V ^8  d   Qh/ S[ ;R&   S[S[,          ;R&   S[S[,          ;R&   # )r   r-   r   warnings)r5   r[   r]   listr   )r   r   s   "r   r   r   I  s7     , - . ^$$/ 0 *++1 r   r7   N)r8   r9   r:   r;   r<   r=   r.   r   r   r>   r?   r@   rA   s   @r   r   r   I  sG     0 / /b
 b
H\! \ \Q  r   r   c                T    V ^8  d   QhR\         \        ,          R,          R\        /# )r   	cache_dirNr   )r   r   r   )r   s   "r   r   r   0  s'     o ocDj4/ o; or   c                f   V f   \         p \        V 4      P                  4       P                  4       p V P	                  4       '       g   \        RV  R2V R7      hV P                  4       '       d   \        RV  R24      h\        4       p. pV P                  4        FD  pVP                  R8X  d   K  VP                  R8X  d   K)   VP                  \        V4      4       KF  	  \        \!        V4      \#        R V 4       4      VR	7      #   \         d   pTP                  T4        Rp?K  Rp?ii ; i)
as
  Scan the entire HF cache-system and return a [`~HFCacheInfo`] structure.

Use `scan_cache_dir` in order to programmatically scan your cache-system. The cache
will be scanned repo by repo. If a repo is corrupted, a [`~CorruptedCacheException`]
will be thrown internally but captured and returned in the [`~HFCacheInfo`]
structure. Only valid repos get a proper report.

```py
>>> from huggingface_hub import scan_cache_dir

>>> hf_cache_info = scan_cache_dir()
HFCacheInfo(
    size_on_disk=3398085269,
    repos=frozenset({
        CachedRepoInfo(
            repo_id='t5-small',
            repo_type='model',
            repo_path=PosixPath(...),
            size_on_disk=970726914,
            nb_files=11,
            revisions=frozenset({
                CachedRevisionInfo(
                    commit_hash='d78aea13fa7ecd06c29e3e46195d6341255065d5',
                    size_on_disk=970726339,
                    snapshot_path=PosixPath(...),
                    files=frozenset({
                        CachedFileInfo(
                            file_name='config.json',
                            size_on_disk=1197
                            file_path=PosixPath(...),
                            blob_path=PosixPath(...),
                        ),
                        CachedFileInfo(...),
                        ...
                    }),
                ),
                CachedRevisionInfo(...),
                ...
            }),
        ),
        CachedRepoInfo(...),
        ...
    }),
    warnings=[
        CorruptedCacheException("Snapshots dir doesn't exist in cached repo: ..."),
        CorruptedCacheException(...),
        ...
    ],
)
```

You can also print a detailed report directly from the `hf` command line using:
```text
> hf cache ls
ID                          SIZE     LAST_ACCESSED LAST_MODIFIED REFS
--------------------------- -------- ------------- ------------- -----------
dataset/nyu-mll/glue          157.4M 2 days ago    2 days ago    main script
model/LiquidAI/LFM2-VL-1.6B     3.2G 4 days ago    4 days ago    main
model/microsoft/UserLM-8b      32.1G 4 days ago    4 days ago    main

Done in 0.0s. Scanned 6 repo(s) for a total of 3.4G.
Got 1 warning(s) while scanning. Use -vvv to print details.
```

Args:
    cache_dir (`str` or `Path`, `optional`):
        Cache directory to cache. Defaults to the default HF cache directory.

> [!WARNING]
> Raises:
>
>     `CacheNotFound`
>       If the cache directory does not exist.
>
>     [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
>       If the cache directory is a file, instead of a directory.

Returns: a [`~HFCacheInfo`] object.
NzCache directory not found: zM. Please use `cache_dir` argument or set `HF_HUB_CACHE` environment variable.)r   z1Scan cache expects a directory but found a file: z.lockszCACHEDIR.TAGc              3   8   "   T F  qP                   x  K  	  R # 5ir   )r-   ).0r   s   & r   	<genexpr>!scan_cache_dir.<locals>.<genexpr>  s     =ut**u   )r   r-   r   )r   r   
expanduserresolveexistsr   is_file
ValueErrorr   iterdirnamer   _scan_cached_repor   appendr   r[   sum)r   r   r   ry   es   &    r   scan_cache_dirr   0  s.   `  	Y**,446I))  5B  C
 	

 ?	{  KX  Y
 	
 "%E.0H&&(	>>X%>>^+	II'	23 ) =u==  ' 	OOA	s   D		D0D++D0c                0    V ^8  d   QhR\         R\        /# )r   ry   r   )r   r]   )r   s   "r   r   r     s     D D D. Dr   c                	  a V P                  4       '       g   \        RV  24      hRV P                  9  d   \        RV  24      hV P                  P                  R^R7      w  rVRR pVP	                  RR4      pVR9  d   \        RV RV  R	24      h/ oV R
,          pV R,          pVP                  4       '       d   VP                  4       '       g   \        RV 24      h\        \        4      pVP                  4       '       d   VP                  4       '       d   \        RV 24      hVP                  R4       F  pVP                  4       '       g   VP                  \        9   d   K0  \        VP                  V4      4      pVP                  4       ;_uu_ 4       pVP                  4       p	RRR4       VX	,          P                  V4       K  	  \        4       p
VP!                  4        EF  pVP                  \        9   d   K  VP                  4       '       d   \        RV 24      h\        4       pVP                  R4       F  pVP                  4       '       d   K  \#        V4      P%                  4       pVP                  4       '       g   \        RV 24      hVS9  d   VP'                  4       SV&   VP                  \)        VP                  VSV,          P*                  VSV,          P,                  SV,          P.                  R7      4       K  	  \1        V4      ^ 8  d   \3        V3R lV 4       4      pMVP'                  4       P.                  pT
P                  \5        VP                  \7        V4      \7        VP9                  VP                  \        4       4      4      \;        V3R lV Uu0 uF  pVP<                  kK  	  up 4       4      VVR7      4       EK  	  \1        V4      ^ 8  d   \        R\?        V4       RV  R	24      h\1        S4      ^ 8  dB   \3        R SPA                  4        4       4      p\3        R SPA                  4        4       4      pM(V P'                  4       pVP,                  pVP.                  p\C        \1        S4      VV V\7        V
4      \;        R SPA                  4        4       4      VVR7      #   + '       g   i     EL+; iu upi )z~Scan a single cache repo and return information about it.

Any unexpected behavior will raise a [`~CorruptedCacheException`].
zRepo path is not a directory: z--z6Repo path is not a valid HuggingFace cache directory: )maxsplitNrl   z8Repo type must be `dataset`, `model` or `space`, found `z` (z).r   rZ   z,Snapshots dir doesn't exist in cached repo: z!Refs directory cannot be a file: z**/*z*Snapshots folder corrupted. Found a file: zBlob missing (broken symlink): )r2   r3   r-   r4   r   r%   c              3   ^   <"   T F"  pSVP                   ,          P                  x  K$  	  R # 5ir   )r4   st_mtime)r   r   
blob_statss   & r   r   $_scan_cached_repo.<locals>.<genexpr>  s#     (fYeQUDNN)C)L)LYes   *-c              3   J   <"   T F  pSV,          P                   x  K  	  R # 5ir   st_size)r   r4   r   s   & r   r   r     s       !CliJy)11Cls    #)rX   rT   rZ   r-   rY   rI   z-Reference(s) refer to missing commit hashes: z (c              3   8   "   T F  qP                   x  K  	  R # 5ir   )st_atimer   stats   & r   r   r           O;N4;Nr   c              3   8   "   T F  qP                   x  K  	  R # 5ir   )r   r   s   & r   r   r     r   r   c              3   8   "   T F  qP                   x  K  	  R # 5ir   r   r   s   & r   r   r   #  s     F2E$2Er   )rU   rn   ry   rm   rt   r-   ra   rI   >   modelspacedataset)"is_dirr   r   splitreplacer   r   r   r   globFILES_TO_IGNOREr   relative_toopenreadr   r   r   r   r   r   r   r   r   rS   maxrC   r[   popr   r4   rr   valuesr]   )ry   rm   rn   snapshots_path	refs_pathrefs_by_hashref_pathref_namefrX   cached_revisionsrevision_pathcached_filesr3   r4   revision_last_modifiedr   repo_last_accessedrepo_last_modified
repo_statsr   s   &                   @r   r   r     sj   
 %(Fyk&RSS9>>!%(^_h^i&jkk"--dQ-?I#2IoodC(G55%FykQTU^T__ab
 	
 .0J,NF"I  "".*?*?*A*A%(TUcTd&eff
 )4C(8L ),Mi[*YZZ!v.H  HMM_$D8//	:;HAffh ! %))(3 / 14'//10  ""),VWdVe*fggu&++F3I!!Y//1I##%%-0OPY{.[\\
*(1(8
9%'nn'!+I!6!>!>''1)'<'E'E'1)'<'E'E	 42 |q %((fYe(f%f"%2%7%7%9%B%B")..-|//0B0BCEJK  !_kCl_kW[DNN_kCl!  ,4		
M 2h <1%;D<N;OrR[Q\\^_
 	
 :  O:;L;L;N OO  O:;L;L;N OO^^%
'00'00 Z,-F*2C2C2EFF((	 	W !f Dms   S9S%S"c                0    V ^8  d   QhR\         R\        /# )r   numr   r   )r   s   "r   r   r   )  s     
 
c 
c 
r   c                z    \        V 4      pR F%  p\        V4      R8  d
   VR V 2u # VR,          pK'  	  VR R2# )zcFormat size in bytes into a human-readable string.

Taken from https://stackoverflow.com/a/1094933
g     @@z3.1fz.1fY) KMGTPEZ)r6   abs)r  num_funits   &  r   r,   r,   )  sM    
 #JE7u:D\$(( 8 C[?r   c                4    V ^8  d   QhR\         R\        RR/# )r   r   r   r   N)r   r   )r   s   "r   r   r   6  s&     b b4 bC bD br   c                |   \         P                  RV RV  24        V P                  4       '       d   \        P                  ! V 4       R	# \
        P                  ! V 4       R	#   \         d#    \         P                  RT RT  R2RR7        R	# \         d#    \         P                  RT RT  R2RR7        R	# i ; i)
a(  Try to delete a local file or folder.

If the path does not exist, error is logged as a warning and then ignored.

Args:
    path (`Path`)
        Path to delete. Can be a file or a folder.
    path_type (`str`)
        What path are we deleting ? Only for logging purposes. Example: "snapshot".
zDelete z: zCouldn't delete z: file not found ()T)exc_infoz: permission denied (N)
r   r   r   osr   shutilrmtreeFileNotFoundErrorr   PermissionError)r   r   s   &&r   r   r   6  s     KK')Btf-.b<<>>IIdOMM$ _))4FtfANY]^ b))4I$qQ\`abs(   A# A# A# #)B;B;B;:B;)r   r   r   r   )$r<   r&  r'  collectionsr   dataclassesr   pathlibr   typingr   huggingface_hub.errorsr   r   	constantsr   r  r	   _parsingr
   	_terminalr   
get_loggerr8   r   rz   r   r   rC   r]   r|   r   r   r   r,   r   r7   r   r   <module>r4     s   ; 	  # !   I $  &  
		H	%12 - $</ </ </~ $C C CL $QW QW QWh $BS BS BSJ $c c cLodDN
br   