§
    }Štj‹ˆ  ã                   ó¤  — d Z ddlZddlZddl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	lmZ d
dlmZ d
dlmZ d
dlmZ  ej        e¦  «        Ze
d         Zg d¢Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Z ed¬¦  «         G d„ d¦  «        ¦   «         Z d)de!ez  dz  de fd „Z"dede#e         fd!„Z$d"edefd#„Z%d$e&de!fd%„Z'd&ed'e!ddfd(„Z(dS )*z4Contains utilities to manage the HF cache directory.é    N)Údefaultdict)Ú	dataclass)ÚPath)ÚLiteral)ÚCacheNotFoundÚCorruptedCacheExceptioné   )ÚHF_HUB_CACHEé   )Úlogging)Úformat_timesince)Útabulate)ÚmodelÚdatasetÚspace)z	.DS_Storez	Thumbs.dbzdesktop.iniT)Úfrozenc                   ó¤   — e Zd ZU dZeed<   eed<   eed<   eed<   eed<   eed<   e	defd	„¦   «         Z
e	defd
„¦   «         Ze	defd„¦   «         ZdS )Ú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.
    Ú	file_nameÚ	file_pathÚ	blob_pathÚsize_on_diskÚblob_last_accessedÚblob_last_modifiedÚreturnc                 ó*   — t          | j        ¦  «        S )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   r   ©Úselfs    úb/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/huggingface_hub/utils/_cache_manager.pyÚblob_last_accessed_strz%CachedFileInfo.blob_last_accessed_strI   ó   € õ   Ô 7Ñ8Ô8Ð8ó    c                 ó*   — t          | j        ¦  «        S )z¦
        (property) Timestamp of the last time the blob file has been modified, returned
        as a human-readable string.

        Example: "2 weeks ago".
        )r   r   r   s    r   Úblob_last_modified_strz%CachedFileInfo.blob_last_modified_strS   r!   r"   c                 ó*   — t          | j        ¦  «        S )zi
        (property) Size of the blob file as a human-readable string.

        Example: "42.2K".
        ©Ú_format_sizer   r   s    r   Úsize_on_disk_strzCachedFileInfo.size_on_disk_str]   ó   € õ ˜DÔ-Ñ.Ô.Ð.r"   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__r   ÚintÚfloatÚpropertyr    r$   r(   © r"   r   r   r   '   sÔ   € € € € € € ðð ð0 €N€N�NØ€O€O�OØ€O€O�OØÐÐÑàÐÐÑØÐÐÑàð9¨ð 9ð 9ð 9ñ „Xð9ð ð9¨ð 9ð 9ð 9ñ „Xð9ð ð/ #ð /ð /ð /ñ „Xð/ð /ð /r"   r   c                   ó¼   — e Zd ZU dZeed<   eed<   eed<   ee	         ed<   ee         ed<   e
ed<   edefd	„¦   «         Zedefd
„¦   «         Zedefd„¦   «         ZdS )Ú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.
    Úcommit_hashÚsnapshot_pathr   ÚfilesÚrefsÚlast_modifiedr   c                 ó*   — t          | j        ¦  «        S )z¥
        (property) Timestamp of the last time the revision has been modified, returned
        as a human-readable string.

        Example: "2 weeks ago".
        ©r   r:   r   s    r   Úlast_modified_strz$CachedRevisionInfo.last_modified_str“   ó   € õ   Ô 2Ñ3Ô3Ð3r"   c                 ó*   — t          | j        ¦  «        S ©zn
        (property) Sum of the blob file sizes as a human-readable string.

        Example: "42.2K".
        r&   r   s    r   r(   z#CachedRevisionInfo.size_on_disk_str�   r)   r"   c                 ó*   — t          | j        ¦  «        S )zC
        (property) Total number of files in the revision.
        )Úlenr8   r   s    r   Únb_fileszCachedRevisionInfo.nb_files¦   s   € õ
 �4”:‰ŒÐr"   N)r*   r+   r,   r-   r.   r/   r   r0   Ú	frozensetr   r1   r2   r=   r(   rC   r3   r"   r   r5   r5   g   sç   € € € € € € ð ð  ðD ÐÐÑØÐÐÑØÐÐÑØ�^Ô$Ð$Ð$Ñ$Ø
�CŒ.ÐÐÑàÐÐÑàð4 3ð 4ð 4ð 4ñ „Xð4ð ð/ #ð /ð /ð /ñ „Xð/ð ð˜#ð ð ð ñ „Xðð ð r"   r5   c                   ó  — e Zd ZU dZeed<   eed<   eed<   eed<   eed<   e	e
         ed<   eed<   eed	<   ed
efd„¦   «         Zed
efd„¦   «         Zed
efd„¦   «         Zed
efd„¦   «         Zed
eee
f         fd„¦   «         ZdS )ÚCachedRepoInfoaF  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.
    Úrepo_idÚ	repo_typeÚ	repo_pathr   rC   Ú	revisionsÚlast_accessedr:   r   c                 ó*   — t          | j        ¦  «        S )zŸ
        (property) Last time a blob file of the repo has been accessed, returned as a
        human-readable string.

        Example: "2 weeks ago".
        )r   rK   r   s    r   Úlast_accessed_strz CachedRepoInfo.last_accessed_strÙ   r>   r"   c                 ó*   — t          | j        ¦  «        S )zŸ
        (property) Last time a blob file of the repo has been modified, returned as a
        human-readable string.

        Example: "2 weeks ago".
        r<   r   s    r   r=   z CachedRepoInfo.last_modified_strã   r>   r"   c                 ó*   — t          | j        ¦  «        S r@   r&   r   s    r   r(   zCachedRepoInfo.size_on_disk_strí   r)   r"   c                 ó$   — | j         › d| j        › �S )z9Canonical `type/id` identifier used across cache tooling.ú/)rH   rG   r   s    r   Úcache_idzCachedRepoInfo.cache_idö   s   € ð ”.Ð1Ð1 4¤<Ð1Ð1Ð1r"   c                 ó$   — d„ | j         D ¦   «         S )zQ
        (property) Mapping between `refs` and revision data structures.
        c                 ó(   — i | ]}|j         D ]}||“ŒŒS r3   )r9   )Ú.0ÚrevisionÚrefs      r   ú
<dictcomp>z'CachedRepoInfo.refs.<locals>.<dictcomp>   s)   € ÐVÐVÐV (ÈÌÐVÐVÀ��XÐVÐVÐVÐVr"   )rJ   r   s    r   r9   zCachedRepoInfo.refsû   s   € ð
 WÐV¨d¬nÐVÑVÔVÐVr"   N)r*   r+   r,   r-   r.   r/   ÚREPO_TYPE_Tr   r0   rD   r5   r1   r2   rM   r=   r(   rR   Údictr9   r3   r"   r   rF   rF   ®   sR  € € € € € € ðð ð> €L€L�LØÐÐÑØ€O€O�OØÐÐÑØ€M€M�MØÐ+Ô,Ð,Ð,Ñ,àÐÐÑØÐÐÑàð4 3ð 4ð 4ð 4ñ „Xð4ð ð4 3ð 4ð 4ð 4ñ „Xð4ð ð/ #ð /ð /ð /ñ „Xð/ð ð2˜#ð 2ð 2ð 2ñ „Xð2ð ðW�d˜3Ð 2Ð2Ô3ð Wð Wð Wñ „XðWð Wð Wr"   rF   c                   óš   — e Zd ZU dZeed<   ee         ed<   ee         ed<   ee         ed<   ee         ed<   ede	fd„¦   «         Z
dd
„Zd	S )ÚDeleteCacheStrategyaÒ  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).
    Úexpected_freed_sizeÚblobsr9   ÚreposÚ	snapshotsr   c                 ó*   — t          | j        ¦  «        S )zt
        (property) Expected size that will be freed as a human-readable string.

        Example: "42.2K".
        )r'   r]   r   s    r   Úexpected_freed_size_strz+DeleteCacheStrategy.expected_freed_size_str  s   € õ ˜DÔ4Ñ5Ô5Ð5r"   Nc                 ó$  — | j         D ]}t          |d¬¦  «         Œ| j        D ]}t          |d¬¦  «         Œ| j        D ]}t          |d¬¦  «         Œ| j        D ]}t          |d¬¦  «         Œt
                               d| j        › d�¦  «         dS )	aŠ  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ÚsnapshotrW   ÚblobzCache deletion done. Saved ú.N)r_   Ú_try_delete_pathr`   r9   r^   ÚloggerÚinforb   )r   Úpaths     r   ÚexecutezDeleteCacheStrategy.execute&  sÍ   € ð" ”Jð 	5ð 	5ˆDÝ˜T¨VÐ4Ñ4Ô4Ð4Ð4ð ”Nð 	9ð 	9ˆDÝ˜T¨ZÐ8Ñ8Ô8Ð8Ð8ð ”Ið 	4ð 	4ˆDÝ˜T¨UÐ3Ñ3Ô3Ð3Ð3ð ”Jð 	5ð 	5ˆDÝ˜T¨VÐ4Ñ4Ô4Ð4Ð4å�ŠÐQ°$Ô2NÐQÐQÐQÑRÔRÐRÐRÐRr"   )r   N)r*   r+   r,   r-   r0   r/   rD   r   r2   r.   rb   rm   r3   r"   r   r\   r\     s­   € € € € € € ðð ð$ ÐÐÑØ�TŒ?ÐÐÑØ
�DŒ/ÐÐÑØ�TŒ?ÐÐÑØ˜ŒÐÐÑàð6¨ð 6ð 6ð 6ñ „Xð6ð Sð  Sð  Sð  Sð  Sð  Sr"   r\   c                   ó(   — e Zd ZU dZeed<   eed<   dS )ÚCachedIncompleteFileInfoaÚ  Frozen data structure holding information about a single incomplete download.

    Interrupted downloads leave `<cache>/<repo>/blobs/<etag>.incomplete` files behind.
    These are not part of any committed revision, so they are surfaced separately by
    [`scan_cache_dir`].

    Args:
        file_path (`Path`):
            Path of the `.incomplete` file in the `blobs` folder.
        size_on_disk (`int`):
            Size of the partially-downloaded file in bytes.
    r   r   N)r*   r+   r,   r-   r   r/   r0   r3   r"   r   ro   ro   I  s3   € € € € € € ðð ð €O€O�OØÐÐÑÐÐr"   ro   c                   ó¾   — e Zd ZU dZeed<   ee         ed<   ee         ed<   e	e
         ed<   edefd„¦   «         Zedefd„¦   «         Zd	edefd
„Zddœdedefd„ZdS )ÚHFCacheInfoaA  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.
        incomplete_files (`frozenset[CachedIncompleteFileInfo]`):
            Set of [`~CachedIncompleteFileInfo`] describing orphaned `*.incomplete`
            files left behind by interrupted downloads.
        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.
    r   r_   Úincomplete_filesÚwarningsr   c                 ó*   — t          | j        ¦  «        S )z‹
        (property) Sum of all valid repo sizes in the cache-system as a human-readable
        string.

        Example: "42.2K".
        r&   r   s    r   r(   zHFCacheInfo.size_on_disk_strz  s   € õ ˜DÔ-Ñ.Ô.Ð.r"   c                 ó>   — t          d„ | j        D ¦   «         ¦  «        S )z9(property) Sum of all incomplete download sizes in bytes.c              3   ó$   K  — | ]}|j         V — Œd S ©N©r   ©rU   Úfiles     r   ú	<genexpr>z6HFCacheInfo.incomplete_size_on_disk.<locals>.<genexpr>‡  s%   è è € ÐGÐG¨�4Ô$ÐGÐGÐGÐGÐGÐGr"   )Úsumrr   r   s    r   Úincomplete_size_on_diskz#HFCacheInfo.incomplete_size_on_disk„  s$   € õ ÐGÐG°Ô1FÐGÑGÔGÑGÔGÐGr"   rJ   c                 ó„  — t          |¦  «        }t          t           ¦  «        }| j        D ]J}|j        D ]@}|j        |v r5||                              |¦  «         |                     |j        ¦  «         ŒAŒKt          |¦  «        dk    r0t           	                    dd 
                    |¦  «        › �¦  «         t          ¦   «         }t          ¦   «         }t          ¦   «         }t          ¦   «         }	d}
|                     ¦   «         D ]ò\  }}|j        |z
  }t          |¦  «        dk    r%|                     |j        ¦  «         |
|j        z  }
ŒG|D ]¨}|	                     |j        ¦  «         |j        D ]"}|                     |j        dz  |z  ¦  «         Œ#|j        D ]Z}|j        |vrOd}|D ]$}|j        D ]}|j        |j        k    rd} nŒ|s nŒ%|r$|                     |j        ¦  «         |
|j        z  }
Œ[Œ©Œót%          t'          |¦  «        t'          |¦  «        t'          |¦  «        t'          |	¦  «        |
¬¦  «        S )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.
        r   z,Revision(s) not found - cannot delete them: ú, r9   TF)r^   r9   r_   r`   r]   )Úsetr   r_   rJ   r6   ÚaddÚremoverB   rj   ÚwarningÚjoinÚitemsrI   r   r7   r9   r8   r   r\   rD   )r   rJ   Úhashes_to_deleteÚrepos_with_revisionsrd   rV   Ú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_deleterW   rz   Úis_file_aloneÚrev_files                      r   Údelete_revisionszHFCacheInfo.delete_revisions‰  sÒ  € õF &)¨¡^¤^ÐåNYÕZ]ÑN^ÔN^Ðà”Jð 	Bð 	BˆDØ œNð Bð B�ØÔ'Ð+;Ð;Ð;Ø(¨Ô.×2Ò2°8Ñ<Ô<Ð<Ø$×+Ò+¨HÔ,@ÑAÔAÐAøðBõ
 ÐÑ Ô  1Ò$Ð$Ý�NŠNÐgÈ$Ï)Ê)ÐTdÑJeÔJeÐgÐgÑhÔhÐhå+.©5¬5ÐÝ*-©%¬%ÐÝ+.©5¬5ÐÝ/2©u¬uÐ!Ø./Ð+à2F×2LÒ2LÑ2NÔ2Nð #	Uð #	UÑ.ˆMÐ.Ø+Ô5Ð8KÑKˆOõ �?Ñ#Ô# qÒ(Ð(Ø%×)Ò)¨-Ô*AÑBÔBÐBØ3°}Ô7QÑQÐ3Øð ':ð Uð UÐ"à)×-Ò-Ð.@Ô.NÑOÔOÐOð .Ô2ð Uð U�CØ(×,Ò,¨]Ô-DÀvÑ-MÐPSÑ-SÑTÔTÐTÐTð /Ô4ð Uð U�DØ”~Ð-BÐBÐBØ(,˜Ø(7ð &ð &˜HØ,4¬Nð *ð * Ø#'¤>°XÔ5GÒ#GÐ#GØ49 MØ$) Eð $Hð $1ð &Ø % ð&ð )ð UØ1×5Ò5°d´nÑEÔEÐEØ?À4ÔCTÑTÐ?øðUðUõ4 #ÝÐ1Ñ2Ô2ÝÐ/Ñ0Ô0ÝÐ1Ñ2Ô2ÝÐ 9Ñ:Ô:Ø Cð
ñ 
ô 
ð 	
r"   r   )Ú	verbosityr”   c                óÖ   — |dk    r2t          d„ t          | j        d„ ¬¦  «        D ¦   «         g d¢¬¦  «        S t          d„ t          | j        d„ ¬¦  «        D ¦   «         g d	¢¬¦  «        S )
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.
        r   c                 óÐ   — g | ]c}|j         |j        |j        d ›|j        |j        |j        d                     t          |j        ¦  «        ¦  «        t          |j
        ¦  «        g‘ŒdS )ú>12r   )rG   rH   r(   rC   rM   r=   r„   Úsortedr9   r.   rI   ©rU   rd   s     r   ú
<listcomp>z/HFCacheInfo.export_as_table.<locals>.<listcomp>  sy   € ð ð ð ð ð œØœØÔ0Ð6Ð6ØœØÔ.ØÔ.ØŸ	š	¥&¨¬Ñ"3Ô"3Ñ4Ô4Ý˜DœNÑ+Ô+ð	ðð ð r"   c                 ó   — | j         S rw   ©rI   ©rd   s    r   ú<lambda>z-HFCacheInfo.export_as_table.<locals>.<lambda>"  ó   € ÀDÄN€ r"   ©Úkey)úREPO IDú	REPO TYPEúSIZE ON DISKúNB FILESÚLAST_ACCESSEDÚLAST_MODIFIEDÚREFSú
LOCAL PATH)ÚrowsÚheadersc                 ó  — g | ]}}t          |j        d „ ¬¦  «        D ]c}|j        |j        |j        |j        d›|j        |j        d                     t          |j	        ¦  «        ¦  «        t          |j        ¦  «        g‘ŒdŒ~S )c                 ó   — | j         S rw   )r6   )rV   s    r   rž   z8HFCacheInfo.export_as_table.<locals>.<listcomp>.<lambda>=  s
   € ÐPXÔPd€ r"   r    r—   r   )r˜   rJ   rG   rH   r6   r(   rC   r=   r„   r9   r.   r7   )rU   rd   rV   s      r   rš   z/HFCacheInfo.export_as_table.<locals>.<listcomp>1  s¥   € ð ð ð ð Ý$*¨4¬>Ð?dÐ?dÐ$eÑ$eÔ$eðð ð !ð œØœØ Ô,Ø#Ô4Ð:Ð:Ø Ô)Ø Ô2ØŸ	š	¥&¨¬Ñ"7Ô"7Ñ8Ô8Ý˜HÔ2Ñ3Ô3ð	ðð ð ð r"   c                 ó   — | j         S rw   rœ   r�   s    r   rž   z-HFCacheInfo.export_as_table.<locals>.<lambda><  rŸ   r"   )r¢   r£   ÚREVISIONr¤   r¥   r§   r¨   r©   )r   r˜   r_   )r   r”   s     r   Úexport_as_tablezHFCacheInfo.export_as_tableí  s¾   € ðP ˜Š>ˆ>Ýðð õ !' t¤zÐ7RÐ7RÐ SÑ SÔ Sðñ ô ð	ð 	ð 	ðñ ô ð õ4 ðð õ !' t¤zÐ7RÐ7RÐ SÑ SÔ Sðñ ô ð	ð 	ð 	ðñ ô ð r"   N)r*   r+   r,   r-   r0   r/   rD   rF   ro   Úlistr   r2   r.   r(   r}   r\   r“   r°   r3   r"   r   rq   rq   \  s  € € € € € € ðð ð. ÐÐÑØ�^Ô$Ð$Ð$Ñ$ØÐ 8Ô9Ð9Ð9Ñ9ØÐ*Ô+Ð+Ð+Ñ+àð/ #ð /ð /ð /ñ „Xð/ð ðH¨ð Hð Hð Hñ „XðHðb
¨3ð b
Ð3Fð b
ð b
ð b
ð b
ðH 34ð \ð \ð \¨Cð \¸ð \ð \ð \ð \ð \ð \r"   rq   Ú	cache_dirr   c                 óÜ  — | €t           } t          | ¦  «                             ¦   «                              ¦   «         } |                      ¦   «         st          d| › d�| ¬¦  «        ‚|                      ¦   «         rt          d| › d�¦  «        ‚t          ¦   «         }g }|  	                    ¦   «         D ]x}|j
        t          v rŒ|j
        dk    rŒ|j
        dk    rŒ)	 |                     t          |¦  «        ¦  «         ŒM# t          $ r}|                     |¦  «         Y d}~Œqd}~ww xY wt!          t#          |¦  «        t%          d„ |D ¦   «         ¦  «        t'          | ¦  «        |¬	¦  «        S )
a‹  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   ó$   K  — | ]}|j         V — Œd S rw   rx   r™   s     r   r{   z!scan_cache_dir.<locals>.<genexpr>»  s%   è è € Ð=Ð=¨t˜Ô*Ð=Ð=Ð=Ð=Ð=Ð=r"   )r_   r   rr   rs   )r
   r   Ú
expanduserÚresolveÚexistsr   Úis_fileÚ
ValueErrorr€   ÚiterdirÚnameÚFILES_TO_IGNOREr�   Ú_scan_cached_repor   Úappendrq   rD   r|   Ú_scan_incomplete_files)r²   r_   rs   rI   Úes        r   Úscan_cache_dirrÁ   L  sÇ  € ð` ÐÝ ˆ	å�Y‘”×*Ò*Ñ,Ô,×4Ò4Ñ6Ô6€IØ×ÒÑÔð 
Ýð C¨)ð  Cð  Cð  CØð
ñ 
ô 
ð 	
ð
 ×ÒÑÔð 
Ýð YÀ	ð  Yð  Yð  Yñ
ô 
ð 	
õ "%¡¤€EØ.0€HØ×&Ò&Ñ(Ô(ð 
ð 
ˆ	ØŒ>�_Ð,Ð,ØØŒ>˜XÒ%Ð%ØØŒ>˜^Ò+Ð+Øð	Ø�IŠIÕ'¨	Ñ2Ô2Ñ3Ô3Ð3Ð3øÝ&ð 	ð 	ð 	Ø�OŠO˜AÑÔÐÐÐÐÐÐøøøøð	øøøõ Ý˜ÑÔÝÐ=Ð=°uÐ=Ñ=Ô=Ñ=Ô=Ý/°	Ñ:Ô:Øð	ñ ô ð s   Ã"C>Ã>
D'ÄD"Ä"D'c                 ó
  — t          ¦   «         }|                      d¦  «        D ]Q}	 |                     ¦   «         j        }n# t          $ r Y Œ)w xY w|                     t          ||¬¦  «        ¦  «         ŒRt          |¦  «        S )a,  Find orphaned `*.incomplete` partial-download files in the cache.

    Interrupted downloads leave `<cache>/<repo>/blobs/<etag>.incomplete` files behind.
    These are not part of any committed revision, so they are reported separately in the
    [`~HFCacheInfo`] returned by [`scan_cache_dir`].
    z*/blobs/*.incomplete)r   r   )r€   ÚglobÚstatÚst_sizeÚOSErrorr�   ro   rD   )r²   r8   rl   r   s       r   r¿   r¿   Á  s“   € õ ,/©5¬5€EØ—’Ð5Ñ6Ô6ð Wð Wˆð	ØŸ9š9™;œ;Ô.ˆLˆLøÝð 	ð 	ð 	ØˆHð	øøøà�	Š	Õ*°TÈÐUÑUÔUÑVÔVÐVÐVÝ�UÑÔÐs   §AÁ
AÁArI   c                 óD
  ‡— |                       ¦   «         st          d| › �¦  «        ‚d| j        vrt          d| › �¦  «        ‚| j                             dd¬¦  «        \  }}|dd…         }|                     dd¦  «        }|d	vrt          d
|› d| › d�¦  «        ‚i Š| dz  }| dz  }|                     ¦   «         r|                      ¦   «         st          d|› �¦  «        ‚t          t          ¦  «        }|                     ¦   «         rÞ|                     ¦   «         rt          d|› �¦  «        ‚| 	                    d¦  «        D ]¢}|                      ¦   «         s|j        t          v rŒ%t          |                     |¦  «        ¦  «        }|                     ¦   «         5 }|                     ¦   «         }	ddd¦  «         n# 1 swxY w Y   ||	                              |¦  «         Œ£t          ¦   «         }
|                     ¦   «         D �]ú}|j        t          v rŒ|                     ¦   «         rt          d|› �¦  «        ‚t          ¦   «         }| 	                    d¦  «        D ]Ç}|                      ¦   «         rŒt#          |¦  «                             ¦   «         }|                     ¦   «         st          d|› �¦  «        ‚|‰vr|                     ¦   «         ‰|<   |                     t)          |j        |‰|         j        |‰|         j        ‰|         j        ¬¦  «        ¦  «         ŒÈt1          |¦  «        dk    rt3          ˆfd„|D ¦   «         ¦  «        }n|                     ¦   «         j        }|
                     t5          |j        t7          |¦  «        t7          |                     |j        t          ¦   «         ¦  «        ¦  «        t;          ˆfd„d„ |D ¦   «         D ¦   «         ¦  «        ||¬¦  «        ¦  «         �Œüt1          |¦  «        dk    r#t          dt=          |¦  «        › d| › d�¦  «        ‚t1          ‰¦  «        dk    rWt3          d„ ‰                     ¦   «         D ¦   «         ¦  «        }t3          d„ ‰                     ¦   «         D ¦   «         ¦  «        }n"|                      ¦   «         }|j        }|j        }tA          t1          ‰¦  «        || |t7          |
¦  «        t;          d„ ‰                     ¦   «         D ¦   «         ¦  «        ||¬¦  «        S ) 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: r   )ÚmaxsplitNéÿÿÿÿrQ   >   r   r   r   z8Repo type must be `dataset`, `model` or `space`, found `z` (z).r`   r9   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): )r   r   r   r   r   r   r   c              3   ó<   •K  — | ]}‰|j                  j        V — Œd S rw   )r   Úst_mtime)rU   rz   Ú
blob_statss     €r   r{   z$_scan_cached_repo.<locals>.<genexpr>+  s.   øè è € Ð(fÐ(fÐQU¨°D´NÔ)CÔ)LÐ(fÐ(fÐ(fÐ(fÐ(fÐ(fr"   c              3   ó2   •K  — | ]}‰|         j         V — Œd S rw   ©rÅ   )rU   r   rÌ   s     €r   r{   z$_scan_cached_repo.<locals>.<genexpr>4  s<   øè è € ð !ð !Ø6?�J˜yÔ)Ô1ð!ð !ð !ð !ð !ð !r"   c                 ó   — h | ]	}|j         ’Œ
S r3   )r   ry   s     r   ú	<setcomp>z$_scan_cached_repo.<locals>.<setcomp>5  s   € ÐClÐClÐClÐW[ÀDÄNÐClÐClÐClr"   )r6   r8   r9   r   r7   r:   z-Reference(s) refer to missing commit hashes: z (c              3   ó$   K  — | ]}|j         V — Œd S rw   )Úst_atime©rU   rÄ   s     r   r{   z$_scan_cached_repo.<locals>.<genexpr>E  ó$   è è € Ð OÐ O°4 ¤Ð OÐ OÐ OÐ OÐ OÐ Or"   c              3   ó$   K  — | ]}|j         V — Œd S rw   )rË   rÓ   s     r   r{   z$_scan_cached_repo.<locals>.<genexpr>F  rÔ   r"   c              3   ó$   K  — | ]}|j         V — Œd S rw   rÎ   rÓ   s     r   r{   z$_scan_cached_repo.<locals>.<genexpr>S  s$   è è € ÐFÐF¨$˜œÐFÐFÐFÐFÐFÐFr"   )rC   rG   rI   rH   rJ   r   rK   r:   )!Úis_dirr   r»   ÚsplitÚreplacer·   r   r€   r¸   rÃ   r¼   r.   Úrelative_toÚopenÚreadr�   rº   r   r¶   rÄ   r   rÅ   rÒ   rË   rB   Úmaxr5   rD   Úpopr|   rZ   ÚvaluesrF   )rI   rH   rG   Úsnapshots_pathÚ	refs_pathÚrefs_by_hashÚref_pathÚref_nameÚfr6   Úcached_revisionsÚrevision_pathÚcached_filesr   r   Úrevision_last_modifiedÚrepo_last_accessedÚrepo_last_modifiedÚ
repo_statsrÌ   s                      @r   r½   r½   Ò  sè  ø€ ð
 ×ÒÑÔð TÝ%Ð&RÀyÐ&RÐ&RÑSÔSÐSà�9”>Ð!Ð!Ý%Ð&jÐ_hÐ&jÐ&jÑkÔkÐkà"œ×-Ò-¨d¸QÐ-Ñ?Ô?Ñ€IˆwØ˜#˜2˜#”€IØ�oŠo˜d CÑ(Ô(€GàÐ5Ð5Ð5Ý%ØbÀyÐbÐbÐU^ÐbÐbÐbñ
ô 
ð 	
ð .0€Jà Ñ,€NØ˜FÑ"€Ià× Ò Ñ"Ô"ð g¨.×*?Ò*?Ñ*AÔ*Að gÝ%Ð&eÐUcÐ&eÐ&eÑfÔfÐfõ
 )4µCÑ(8Ô(8€LØ×ÒÑÔð 4ð ×ÒÑÔð 	[Ý)Ð*YÈiÐ*YÐ*YÑZÔZÐZà!Ÿš vÑ.Ô.ð 		4ð 		4ˆHà�ŠÑ Ô ð  H¤Mµ_Ð$DÐ$DØå˜8×/Ò/°	Ñ:Ô:Ñ;Ô;ˆHØ—’‘”ð ' AØŸfšf™hœh�ð'ð 'ð 'ñ 'ô 'ð 'ð 'ð 'ð 'ð 'ð 'øøøð 'ð 'ð 'ð 'ð ˜Ô%×)Ò)¨(Ñ3Ô3Ð3Ð3õ 14±´ÐØ'×/Ò/Ñ1Ô1ð 1
ñ 1
ˆàÔ¥Ð0Ð0ØØ× Ò Ñ"Ô"ð 	hÝ)Ð*fÐWdÐ*fÐ*fÑgÔgÐgå‘u”uˆØ&×+Ò+¨FÑ3Ô3ð 	ð 	ˆIà×ÒÑ!Ô!ð Øå˜Y™œ×/Ò/Ñ1Ô1ˆIØ×#Ò#Ñ%Ô%ð ]Ý-Ð.[ÐPYÐ.[Ð.[Ñ\Ô\Ð\à 
Ð*Ð*Ø(1¯ªÑ(8Ô(8�
˜9Ñ%à×ÒÝØ'œnØ'Ø!+¨IÔ!6Ô!>Ø'Ø'1°)Ô'<Ô'EØ'1°)Ô'<Ô'Eðñ ô ñ	ô 	ð 	ð 	õ ˆ|ÑÔ˜qÒ Ð Ý%(Ð(fÐ(fÐ(fÐ(fÐYeÐ(fÑ(fÔ(fÑ%fÔ%fÐ"Ð"à%2×%7Ò%7Ñ%9Ô%9Ô%BÐ"à×ÒÝØ)Ô.Ý Ñ-Ô-Ý˜|×/Ò/°Ô0BÅCÁEÄEÑJÔJÑKÔKÝ ð !ð !ð !ð !ØClÐClÐ_kÐClÑClÔClð!ñ !ô !ñ ô ð ,Ø4ð	ñ 	ô 	ñ	
ô 	
ð 	
ñ 	
õ ˆ<ÑÔ˜1ÒÐÝ%Ø_½DÀÑ<NÔ<NÐ_Ð_ÐR[Ð_Ð_Ð_ñ
ô 
ð 	
õ ˆ:�„˜ÒÐÝ Ð OÐ O¸:×;LÒ;LÑ;NÔ;NÐ OÑ OÔ OÑOÔOÐÝ Ð OÐ O¸:×;LÒ;LÑ;NÔ;NÐ OÑ OÔ OÑOÔOÐÐà—^’^Ñ%Ô%ˆ
Ø'Ô0ÐØ'Ô0Ðõ Ý�Z‘”ØØØÝÐ,Ñ-Ô-ÝÐFÐF°*×2CÒ2CÑ2EÔ2EÐFÑFÔFÑFÔFØ(Ø(ð	ñ 	ô 	ð 	s   Æ GÇG	ÇG	Únumc                 óx   — t          | ¦  «        }dD ]#}t          |¦  «        dk     r	|d›|› �c S |dz  }Œ$|d›d�S )zkFormat size in bytes into a human-readable string.

    Taken from https://stackoverflow.com/a/1094933
    )Ú ÚKÚMÚGÚTÚPÚEÚZg     @�@z3.1fz.1fÚY)r1   Úabs)rí   Únum_fÚunits      r   r'   r'   Y  sb   € õ
 �#‰JŒJ€EØ7ð ð ˆÝˆu‰:Œ:˜ÒÐØÐ(Ð( $Ð(Ð(Ð(Ð(Ð(Ø�‰ˆˆØˆ?ˆ?ˆ?ˆ?Ðr"   rl   re   c                 óŠ  — t                                d|› d| › �¦  «         	 |                      ¦   «         rt          j        | ¦  «         d	S t          j        | ¦  «         d	S # t          $ r' t                                d|› d| › d�d¬¦  «         Y d	S t          $ r' t                                d|› d| › d�d¬¦  «         Y d	S w xY w)
aD  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)
rj   rk   r¸   Úosr‚   ÚshutilÚrmtreeÚFileNotFoundErrorrƒ   ÚPermissionError)rl   re   s     r   ri   ri   f  s   € õ ‡K‚KÐ-˜)Ð-Ð- tÐ-Ð-Ñ.Ô.Ð.ðbØ�<Š<‰>Œ>ð 	 ÝŒI�d‰OŒOˆOˆOˆOåŒM˜$ÑÔÐÐÐøÝð _ð _ð _Ý�ŠÐN¨)ÐNÐNÀtÐNÐNÐNÐY]ˆÑ^Ô^Ð^Ð^Ð^Ð^Ýð bð bð bÝ�ŠÐQ¨)ÐQÐQÈ$ÐQÐQÐQÐ\`ˆÑaÔaÐaÐaÐaÐaðbøøøs   ¢(A" ÁA" Á"-CÂ,CÃCrw   ))r-   rþ   rÿ   Úcollectionsr   Údataclassesr   Úpathlibr   Útypingr   Úhuggingface_hub.errorsr   r   Ú	constantsr
   rï   r   Ú_parsingr   Ú	_terminalr   Ú
get_loggerr*   rj   rY   r¼   r   r5   rF   r\   ro   rq   r.   rÁ   rD   r¿   r½   r0   r'   ri   r3   r"   r   ú<module>r     s›  ðð ;Ð :à 	€	€	€	Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø !Ð !Ð !Ð !Ð !Ð !Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à IÐ IÐ IÐ IÐ IÐ IÐ IÐ Ià $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ø Ð Ð Ð Ð Ð ð 
ˆÔ	˜HÑ	%Ô	%€àÐ1Ô2€ð <Ð;Ð;€ð €�$ÐÑÔð</ð </ð </ð </ð </ñ </ô </ñ Ôð</ð~ €�$ÐÑÔðCð Cð Cð Cð Cñ Cô Cñ ÔðCðL €�$ÐÑÔðQWð QWð QWð QWð QWñ QWô QWñ ÔðQWðh €�$ÐÑÔðBSð BSð BSð BSð BSñ BSô BSñ ÔðBSðJ €�$ÐÑÔðð ð ð ð ñ ô ñ Ôðð$ €�$ÐÑÔðlð lð lð lð lñ lô lñ Ôðlð^rð r˜c D™j¨4Ñ/ð r¸;ð rð rð rð rðj dð ¨yÐ9QÔ/Rð ð ð ð ð"D ð D¨.ð Dð Dð Dð DðN
�cð 
˜cð 
ð 
ð 
ð 
ðb˜4ð b¨Cð b°Dð bð bð bð bð bð br"   