MCPcopy Index your code
hub / github.com/modelscope/modelscope / ModelScopeCacheInfo

Class ModelScopeCacheInfo

modelscope/hub/cache_manager.py:216–305  ·  view source on GitHub ↗

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]`):

Source from the content-addressed store, hash-verified

214
215@dataclass(frozen=True)
216class ModelScopeCacheInfo:
217 """Frozen data structure holding information about the entire cache-system.
218
219 This data structure is returned by [`scan_cache_dir`] and is immutable.
220
221 Args:
222 size_on_disk (`int`):
223 Sum of all valid repo sizes in the cache-system.
224 repos (`FrozenSet[CachedRepoInfo]`):
225 Set of [`~CachedRepoInfo`] describing all valid cached repos found on the
226 cache-system while scanning.
227 warnings (`List[CorruptedCacheException]`):
228 List of [`~CorruptedCacheException`] that occurred while scanning the cache.
229 Those exceptions are captured so that the scan can continue. Corrupted repos
230 are skipped from the scan.
231 """
232
233 size_on_disk: int
234 repos: FrozenSet[CachedRepoInfo]
235 warnings: List[CorruptedCacheException]
236
237 @property
238 def size_on_disk_str(self) -> str:
239 """
240 (property) Sum of all valid repo sizes in the cache-system as a human-readable
241 string.
242 """
243 return convert_readable_size(self.size_on_disk)
244
245 def export_as_table(self) -> str:
246 """Generate a detailed table from the [`ModelScopeCacheInfo`] object.
247
248 Returns a table with a row per repo and revision (thus multiple rows can appear for a single repo), with columns
249 "repo_id", "repo_type", "revision", "size_on_disk", "nb_files", "last_modified", "local_path".
250
251 Example:
252 ```py
253 >>> from modelscope.hub.cache_manager import scan_cache_dir
254
255 >>> ms_cache_info = scan_cache_dir()
256 ModelScopeCacheInfo(...)
257
258 >>> print(ms_cache_info.export_as_table())
259 REPO ID REPO TYPE REVISION SIZE ON DISK NB FILES LAST_MODIFIED LOCAL PATH
260 ---------------------- --------- ---------- ------------ -------- ------------- -------------------------------------------------------------
261 damo/bert-base-chinese model master 2.7M 5 1 week ago ~/.cache/modelscope/hub/models--damo--bert-base-chinese/...
262 damo/structured-bert model master 8.8K 1 1 week ago ~/.cache/modelscope/hub/models--damo--structured-bert/...
263 damo/t5-base model master 893.8M 4 7 months ago ~/.cache/modelscope/hub/models--damo--t5-base/...
264 ```
265
266 Returns:
267 `str`: The table as a string.
268 """ # noqa: E501
269
270 def format_repo_revision(repo: CachedRepoInfo,
271 revision: CachedRevisionInfo) -> List[str]:
272 """Format a single repo and revision into a list of strings for tabulation."""
273 return [

Callers 1

scan_cache_dirFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…