hfutils 0.2.8__tar.gz → 0.2.9__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {hfutils-0.2.8/hfutils.egg-info → hfutils-0.2.9}/PKG-INFO +7 -7
  2. hfutils-0.2.9/hfutils/cache/__init__.py +7 -0
  3. hfutils-0.2.9/hfutils/cache/delete.py +151 -0
  4. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/config/meta.py +1 -1
  5. {hfutils-0.2.8 → hfutils-0.2.9/hfutils.egg-info}/PKG-INFO +7 -7
  6. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils.egg-info/SOURCES.txt +2 -0
  7. {hfutils-0.2.8 → hfutils-0.2.9}/LICENSE +0 -0
  8. {hfutils-0.2.8 → hfutils-0.2.9}/MANIFEST.in +0 -0
  9. {hfutils-0.2.8 → hfutils-0.2.9}/README.md +0 -0
  10. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/__init__.py +0 -0
  11. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/__main__.py +0 -0
  12. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/archive/__init__.py +0 -0
  13. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/archive/base.py +0 -0
  14. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/archive/rar.py +0 -0
  15. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/archive/sevenz.py +0 -0
  16. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/archive/tar.py +0 -0
  17. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/archive/zip.py +0 -0
  18. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/config/__init__.py +0 -0
  19. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/__init__.py +0 -0
  20. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/base.py +0 -0
  21. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/cli.py +0 -0
  22. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/dispatch.py +0 -0
  23. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/download.py +0 -0
  24. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/ls.py +0 -0
  25. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/ls_repo.py +0 -0
  26. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/upload.py +0 -0
  27. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/entry/whoami.py +0 -0
  28. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/index/__init__.py +0 -0
  29. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/index/fetch.py +0 -0
  30. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/index/hash.py +0 -0
  31. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/index/make.py +0 -0
  32. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/index/validate.py +0 -0
  33. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/operate/__init__.py +0 -0
  34. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/operate/base.py +0 -0
  35. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/operate/download.py +0 -0
  36. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/operate/upload.py +0 -0
  37. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/operate/validate.py +0 -0
  38. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/utils/__init__.py +0 -0
  39. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/utils/binary.py +0 -0
  40. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/utils/download.py +0 -0
  41. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/utils/irregular_repo.json +0 -0
  42. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/utils/path.py +0 -0
  43. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/utils/temp.py +0 -0
  44. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/utils/tqdm_.py +0 -0
  45. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils/utils/walk.py +0 -0
  46. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils.egg-info/dependency_links.txt +0 -0
  47. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils.egg-info/entry_points.txt +0 -0
  48. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils.egg-info/requires.txt +0 -0
  49. {hfutils-0.2.8 → hfutils-0.2.9}/hfutils.egg-info/top_level.txt +0 -0
  50. {hfutils-0.2.8 → hfutils-0.2.9}/requirements-7z.txt +0 -0
  51. {hfutils-0.2.8 → hfutils-0.2.9}/requirements-build.txt +0 -0
  52. {hfutils-0.2.8 → hfutils-0.2.9}/requirements-doc.txt +0 -0
  53. {hfutils-0.2.8 → hfutils-0.2.9}/requirements-rar.txt +0 -0
  54. {hfutils-0.2.8 → hfutils-0.2.9}/requirements-test.txt +0 -0
  55. {hfutils-0.2.8 → hfutils-0.2.9}/requirements-transfer.txt +0 -0
  56. {hfutils-0.2.8 → hfutils-0.2.9}/requirements.txt +0 -0
  57. {hfutils-0.2.8 → hfutils-0.2.9}/setup.cfg +0 -0
  58. {hfutils-0.2.8 → hfutils-0.2.9}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.2.8
3
+ Version: 0.2.9
4
4
  Summary: Useful utilities for huggingface
5
5
  Home-page: https://github.com/deepghs/hfutils
6
6
  Author: narugo1992
@@ -30,6 +30,8 @@ Requires-Dist: natsort
30
30
  Provides-Extra: build
31
31
  Requires-Dist: pyinstaller<5,>=4.7; extra == "build"
32
32
  Requires-Dist: setuptools<70; extra == "build"
33
+ Provides-Extra: transfer
34
+ Requires-Dist: hf-transfer; extra == "transfer"
33
35
  Provides-Extra: doc
34
36
  Requires-Dist: Jinja2>=3.0.0; extra == "doc"
35
37
  Requires-Dist: sphinx>=3.2.0; extra == "doc"
@@ -50,10 +52,8 @@ Requires-Dist: ipykernel>=6.15; extra == "doc"
50
52
  Requires-Dist: py-cpuinfo>=8.0.0; extra == "doc"
51
53
  Requires-Dist: click>=7.0.0; extra == "doc"
52
54
  Requires-Dist: pandas; extra == "doc"
53
- Provides-Extra: 7z
54
- Requires-Dist: py7zr; extra == "7z"
55
- Provides-Extra: transfer
56
- Requires-Dist: hf-transfer; extra == "transfer"
55
+ Provides-Extra: rar
56
+ Requires-Dist: rarfile; extra == "rar"
57
57
  Provides-Extra: test
58
58
  Requires-Dist: coverage>=5; extra == "test"
59
59
  Requires-Dist: mock>=4.0.3; extra == "test"
@@ -71,8 +71,8 @@ Requires-Dist: testtools>=2; extra == "test"
71
71
  Requires-Dist: where>=1.0.2; extra == "test"
72
72
  Requires-Dist: responses>=0.20.0; extra == "test"
73
73
  Requires-Dist: natsort; extra == "test"
74
- Provides-Extra: rar
75
- Requires-Dist: rarfile; extra == "rar"
74
+ Provides-Extra: 7z
75
+ Requires-Dist: py7zr; extra == "7z"
76
76
 
77
77
  # hfutils
78
78
 
@@ -0,0 +1,7 @@
1
+ """
2
+ Overview:
3
+ Huggingface local cache management.
4
+
5
+ Can quickly manage the local cache and make the disk space under control.
6
+ """
7
+ from .delete import delete_detached_cache, delete_cache
@@ -0,0 +1,151 @@
1
+ import logging
2
+ from functools import partial
3
+ from typing import Optional, Callable
4
+
5
+ from huggingface_hub import scan_cache_dir, CachedRepoInfo, CachedRevisionInfo, DeleteCacheStrategy
6
+
7
+
8
+ def _collect_revisions(fn: Callable[[CachedRepoInfo, CachedRevisionInfo], bool], cache_dir: Optional[str] = None) \
9
+ -> DeleteCacheStrategy:
10
+ """
11
+ Collects revisions from the cache that match a specific condition defined by the function `fn`.
12
+
13
+ :param fn: A callable that takes a CachedRepoInfo and CachedRevisionInfo and returns a boolean.
14
+ If True, the revision matches the condition.
15
+ :type fn: Callable[[CachedRepoInfo, CachedRevisionInfo], bool]
16
+ :param cache_dir: The directory where the cache is stored. If None, uses the default directory.
17
+ :type cache_dir: Optional[str]
18
+ :return: A strategy for deleting the collected revisions.
19
+ :rtype: DeleteCacheStrategy
20
+ """
21
+ revision_hashes = set()
22
+ scan = scan_cache_dir(cache_dir=cache_dir)
23
+ for repo in scan.repos:
24
+ for revision in repo.revisions:
25
+ if fn(repo, revision):
26
+ revision_hashes.add(revision.commit_hash)
27
+ logging.info(f'Revisions to delete from huggingface cache: {sorted(revision_hashes)}')
28
+ return scan.delete_revisions(*revision_hashes)
29
+
30
+
31
+ def _is_repo_match(repo: CachedRepoInfo, repo_id: Optional[str] = None, repo_type: Optional[str] = None) -> bool:
32
+ """
33
+ Checks if a repository matches the specified ID and type.
34
+
35
+ :param repo: The repository information.
36
+ :type repo: CachedRepoInfo
37
+ :param repo_id: The ID of the repository to match. If None, matches any ID.
38
+ :type repo_id: Optional[str]
39
+ :param repo_type: The type of the repository to match. If None, matches any type.
40
+ :type repo_type: Optional[str]
41
+ :return: True if the repository matches the conditions, False otherwise.
42
+ :rtype: bool
43
+ """
44
+ if repo_id and repo_type:
45
+ return repo.repo_id == repo_id and repo.repo_type == repo_type
46
+ elif repo_id:
47
+ return repo.repo_id == repo_id
48
+ elif repo_type:
49
+ return repo.repo_type == repo_type
50
+ else:
51
+ return True
52
+
53
+
54
+ def _is_detached_revision(
55
+ repo: CachedRepoInfo, revision: CachedRevisionInfo,
56
+ repo_id: Optional[str] = None, repo_type: Optional[str] = None,
57
+ ) -> bool:
58
+ """
59
+ Determines if a revision is detached (no references) and matches the specified repository ID and type.
60
+
61
+ :param repo: The repository information.
62
+ :type repo: CachedRepoInfo
63
+ :param revision: The revision information.
64
+ :type revision: CachedRevisionInfo
65
+ :param repo_id: The repository ID to match. If None, matches any ID.
66
+ :type repo_id: Optional[str]
67
+ :param repo_type: The repository type to match. If None, matches any type.
68
+ :type repo_type: Optional[str]
69
+ :return: True if the revision is detached and matches the repository conditions, False otherwise.
70
+ :rtype: bool
71
+ """
72
+ if len(revision.refs) == 0:
73
+ return _is_repo_match(repo, repo_id, repo_type)
74
+ else:
75
+ return False
76
+
77
+
78
+ def delete_detached_cache(
79
+ repo_id: Optional[str] = None, repo_type: Optional[str] = None,
80
+ cache_dir: Optional[str] = None
81
+ ):
82
+ """
83
+ Deletes all detached revisions from the cache that match the specified repository ID and type.
84
+
85
+ :param repo_id: The repository ID to match. If None, matches any ID.
86
+ :type repo_id: Optional[str]
87
+ :param repo_type: The repository type to match. If None, matches any type.
88
+ :type repo_type: Optional[str]
89
+ :param cache_dir: The directory where the cache is stored. If None, uses the default directory.
90
+ :type cache_dir: Optional[str]
91
+ """
92
+ # noinspection PyTypeChecker
93
+ strategy = _collect_revisions(
94
+ fn=partial(
95
+ _is_detached_revision,
96
+ repo_id=repo_id,
97
+ repo_type=repo_type,
98
+ ),
99
+ cache_dir=cache_dir,
100
+ )
101
+ logging.info(f'{strategy.expected_freed_size_str} space will be freed.')
102
+ strategy.execute()
103
+
104
+
105
+ def _is_selected_revision(
106
+ repo: CachedRepoInfo, revision: CachedRevisionInfo,
107
+ repo_id: Optional[str] = None, repo_type: Optional[str] = None,
108
+ ) -> bool:
109
+ """
110
+ Determines if a revision matches the specified repository ID and type.
111
+
112
+ :param repo: The repository information.
113
+ :type repo: CachedRepoInfo
114
+ :param revision: The revision information.
115
+ :type revision: CachedRevisionInfo
116
+ :param repo_id: The repository ID to match. If None, matches any ID.
117
+ :type repo_id: Optional[str]
118
+ :param repo_type: The repository type to match. If None, matches any type.
119
+ :type repo_type: Optional[str]
120
+ :return: True if the revision matches the repository conditions, False otherwise.
121
+ :rtype: bool
122
+ """
123
+ _ = repo, revision
124
+ return _is_repo_match(repo, repo_id, repo_type)
125
+
126
+
127
+ def delete_cache(
128
+ repo_id: Optional[str] = None, repo_type: Optional[str] = None,
129
+ cache_dir: Optional[str] = None
130
+ ):
131
+ """
132
+ Deletes all revisions from the cache that match the specified repository ID and type.
133
+
134
+ :param repo_id: The repository ID to match. If None, matches any ID.
135
+ :type repo_id: Optional[str]
136
+ :param repo_type: The repository type to match. If None, matches any type.
137
+ :type repo_type: Optional[str]
138
+ :param cache_dir: The directory where the cache is stored. If None, uses the default directory.
139
+ :type cache_dir: Optional[str]
140
+ """
141
+ # noinspection PyTypeChecker
142
+ strategy = _collect_revisions(
143
+ fn=partial(
144
+ _is_selected_revision,
145
+ repo_id=repo_id,
146
+ repo_type=repo_type,
147
+ ),
148
+ cache_dir=cache_dir,
149
+ )
150
+ logging.info(f'{strategy.expected_freed_size_str} space will be freed.')
151
+ strategy.execute()
@@ -7,7 +7,7 @@ Overview:
7
7
  __TITLE__ = 'hfutils'
8
8
 
9
9
  #: Version of this project.
10
- __VERSION__ = '0.2.8'
10
+ __VERSION__ = '0.2.9'
11
11
 
12
12
  #: Short description of the project, will be included in ``setup.py``.
13
13
  __DESCRIPTION__ = 'Useful utilities for huggingface'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.2.8
3
+ Version: 0.2.9
4
4
  Summary: Useful utilities for huggingface
5
5
  Home-page: https://github.com/deepghs/hfutils
6
6
  Author: narugo1992
@@ -30,6 +30,8 @@ Requires-Dist: natsort
30
30
  Provides-Extra: build
31
31
  Requires-Dist: pyinstaller<5,>=4.7; extra == "build"
32
32
  Requires-Dist: setuptools<70; extra == "build"
33
+ Provides-Extra: transfer
34
+ Requires-Dist: hf-transfer; extra == "transfer"
33
35
  Provides-Extra: doc
34
36
  Requires-Dist: Jinja2>=3.0.0; extra == "doc"
35
37
  Requires-Dist: sphinx>=3.2.0; extra == "doc"
@@ -50,10 +52,8 @@ Requires-Dist: ipykernel>=6.15; extra == "doc"
50
52
  Requires-Dist: py-cpuinfo>=8.0.0; extra == "doc"
51
53
  Requires-Dist: click>=7.0.0; extra == "doc"
52
54
  Requires-Dist: pandas; extra == "doc"
53
- Provides-Extra: 7z
54
- Requires-Dist: py7zr; extra == "7z"
55
- Provides-Extra: transfer
56
- Requires-Dist: hf-transfer; extra == "transfer"
55
+ Provides-Extra: rar
56
+ Requires-Dist: rarfile; extra == "rar"
57
57
  Provides-Extra: test
58
58
  Requires-Dist: coverage>=5; extra == "test"
59
59
  Requires-Dist: mock>=4.0.3; extra == "test"
@@ -71,8 +71,8 @@ Requires-Dist: testtools>=2; extra == "test"
71
71
  Requires-Dist: where>=1.0.2; extra == "test"
72
72
  Requires-Dist: responses>=0.20.0; extra == "test"
73
73
  Requires-Dist: natsort; extra == "test"
74
- Provides-Extra: rar
75
- Requires-Dist: rarfile; extra == "rar"
74
+ Provides-Extra: 7z
75
+ Requires-Dist: py7zr; extra == "7z"
76
76
 
77
77
  # hfutils
78
78
 
@@ -23,6 +23,8 @@ hfutils/archive/rar.py
23
23
  hfutils/archive/sevenz.py
24
24
  hfutils/archive/tar.py
25
25
  hfutils/archive/zip.py
26
+ hfutils/cache/__init__.py
27
+ hfutils/cache/delete.py
26
28
  hfutils/config/__init__.py
27
29
  hfutils/config/meta.py
28
30
  hfutils/entry/__init__.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes