hfutils 0.3.7__tar.gz → 0.3.8__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 (69) hide show
  1. {hfutils-0.3.7/hfutils.egg-info → hfutils-0.3.8}/PKG-INFO +1 -1
  2. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/config/meta.py +1 -1
  3. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/index/__init__.py +2 -1
  4. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/index/make.py +59 -1
  5. {hfutils-0.3.7 → hfutils-0.3.8/hfutils.egg-info}/PKG-INFO +1 -1
  6. {hfutils-0.3.7 → hfutils-0.3.8}/LICENSE +0 -0
  7. {hfutils-0.3.7 → hfutils-0.3.8}/MANIFEST.in +0 -0
  8. {hfutils-0.3.7 → hfutils-0.3.8}/README.md +0 -0
  9. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/__init__.py +0 -0
  10. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/__main__.py +0 -0
  11. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/archive/__init__.py +0 -0
  12. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/archive/base.py +0 -0
  13. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/archive/rar.py +0 -0
  14. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/archive/sevenz.py +0 -0
  15. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/archive/tar.py +0 -0
  16. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/archive/zip.py +0 -0
  17. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/cache/__init__.py +0 -0
  18. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/cache/delete.py +0 -0
  19. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/config/__init__.py +0 -0
  20. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/__init__.py +0 -0
  21. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/base.py +0 -0
  22. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/cli.py +0 -0
  23. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/clone.py +0 -0
  24. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/dispatch.py +0 -0
  25. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/download.py +0 -0
  26. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/index.py +0 -0
  27. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/ls.py +0 -0
  28. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/ls_repo.py +0 -0
  29. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/rollback.py +0 -0
  30. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/upload.py +0 -0
  31. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/entry/whoami.py +0 -0
  32. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/index/fetch.py +0 -0
  33. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/index/hash.py +0 -0
  34. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/index/local_fetch.py +0 -0
  35. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/index/validate.py +0 -0
  36. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/operate/__init__.py +0 -0
  37. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/operate/base.py +0 -0
  38. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/operate/download.py +0 -0
  39. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/operate/upload.py +0 -0
  40. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/operate/validate.py +0 -0
  41. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/repository/__init__.py +0 -0
  42. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/repository/base.py +0 -0
  43. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/repository/clone.py +0 -0
  44. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/repository/rollback.py +0 -0
  45. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/__init__.py +0 -0
  46. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/binary.py +0 -0
  47. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/download.py +0 -0
  48. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/irregular_repo.json +0 -0
  49. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/logging.py +0 -0
  50. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/number.py +0 -0
  51. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/path.py +0 -0
  52. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/session.py +0 -0
  53. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/temp.py +0 -0
  54. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/tqdm_.py +0 -0
  55. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils/utils/walk.py +0 -0
  56. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils.egg-info/SOURCES.txt +0 -0
  57. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils.egg-info/dependency_links.txt +0 -0
  58. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils.egg-info/entry_points.txt +0 -0
  59. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils.egg-info/requires.txt +0 -0
  60. {hfutils-0.3.7 → hfutils-0.3.8}/hfutils.egg-info/top_level.txt +0 -0
  61. {hfutils-0.3.7 → hfutils-0.3.8}/requirements-7z.txt +0 -0
  62. {hfutils-0.3.7 → hfutils-0.3.8}/requirements-build.txt +0 -0
  63. {hfutils-0.3.7 → hfutils-0.3.8}/requirements-doc.txt +0 -0
  64. {hfutils-0.3.7 → hfutils-0.3.8}/requirements-rar.txt +0 -0
  65. {hfutils-0.3.7 → hfutils-0.3.8}/requirements-test.txt +0 -0
  66. {hfutils-0.3.7 → hfutils-0.3.8}/requirements-transfer.txt +0 -0
  67. {hfutils-0.3.7 → hfutils-0.3.8}/requirements.txt +0 -0
  68. {hfutils-0.3.7 → hfutils-0.3.8}/setup.cfg +0 -0
  69. {hfutils-0.3.7 → hfutils-0.3.8}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.3.7
3
+ Version: 0.3.8
4
4
  Summary: Useful utilities for huggingface
5
5
  Home-page: https://github.com/deepghs/hfutils
6
6
  Author: narugo1992
@@ -7,7 +7,7 @@ Overview:
7
7
  __TITLE__ = 'hfutils'
8
8
 
9
9
  #: Version of this project.
10
- __VERSION__ = '0.3.7'
10
+ __VERSION__ = '0.3.8'
11
11
 
12
12
  #: Short description of the project, will be included in ``setup.py``.
13
13
  __DESCRIPTION__ = 'Useful utilities for huggingface'
@@ -1,5 +1,6 @@
1
1
  from .fetch import hf_tar_list_files, hf_tar_file_download, hf_tar_get_index, hf_tar_file_exists, \
2
2
  ArchiveStandaloneFileIncompleteDownload, ArchiveStandaloneFileHashNotMatch, hf_tar_file_size, hf_tar_file_info
3
3
  from .local_fetch import tar_get_index, tar_file_info, tar_file_download, tar_file_size, tar_file_exists, tar_list_files
4
- from .make import tar_create_index, hf_tar_create_index, tar_get_index_info, hf_tar_create_from_directory
4
+ from .make import tar_create_index, hf_tar_create_index, tar_get_index_info, hf_tar_create_from_directory, \
5
+ tar_create_index_for_directory
5
6
  from .validate import hf_tar_item_validate, hf_tar_validate
@@ -1,3 +1,22 @@
1
+ """
2
+ This module provides functionalities for handling and indexing TAR archive files, especially for use with
3
+ the Hugging Face ecosystem. It includes functions to create and retrieve index information of TAR archives,
4
+ which is crucial for efficient data retrieval and management in large datasets. The module also integrates
5
+ with Hugging Face's repository system, allowing for operations like uploading and downloading TAR files
6
+ and their indices.
7
+
8
+ Key functionalities include:
9
+
10
+ - Extracting index information from TAR files.
11
+ - Creating index files for TAR archives locally or in a directory.
12
+ - Integrating with Hugging Face repositories to manage TAR archives and their indices.
13
+
14
+ The module utilizes cryptographic hash functions for data integrity checks and supports operations on both local
15
+ and remote repositories. It is designed to work seamlessly with the Hugging Face platform, enabling users to
16
+ handle large datasets efficiently.
17
+ """
18
+
19
+ import glob
1
20
  import json
2
21
  import logging
3
22
  import os
@@ -47,7 +66,7 @@ def tar_get_index_info(src_tar_file, chunk_for_hash: int = 1 << 20, with_hash: b
47
66
  logging.info(f'Indexing tar file {src_tar_file!r} ...')
48
67
  files = {}
49
68
  with tarfile.open(src_tar_file, mode='r|') as tar:
50
- for tarinfo in tqdm(tar, desc='Indexing tar file ...', silent=silent):
69
+ for tarinfo in tqdm(tar, desc=f'Indexing tar file {src_tar_file!r} ...', silent=silent):
51
70
  tarinfo: tarfile.TarInfo
52
71
  if tarinfo.isreg():
53
72
  info = {
@@ -90,11 +109,50 @@ def tar_create_index(src_tar_file, dst_index_file: Optional[str] = None,
90
109
  """
91
110
  body, _ = os.path.splitext(src_tar_file)
92
111
  dst_index_file = dst_index_file or f'{body}.json'
112
+ if os.path.dirname(dst_index_file):
113
+ os.makedirs(os.path.dirname(dst_index_file), exist_ok=True)
93
114
  with open(dst_index_file, 'w') as f:
94
115
  json.dump(tar_get_index_info(src_tar_file, chunk_for_hash, with_hash, silent), f)
95
116
  return dst_index_file
96
117
 
97
118
 
119
+ def tar_create_index_for_directory(src_tar_directory: str, dst_index_directory: Optional[str] = None,
120
+ chunk_for_hash: int = 1 << 20, with_hash: bool = True, silent: bool = False):
121
+ """
122
+ Create index files for all tar archives in a specified directory.
123
+
124
+ This function scans through the given directory to find all tar files, generates an index for each,
125
+ and saves these indices to the specified destination directory. If no destination directory is provided,
126
+ indices are saved in the same directory as the tar files.
127
+
128
+ :param src_tar_directory: The path to the directory containing tar files.
129
+ :type src_tar_directory: str
130
+ :param dst_index_directory: The path to the directory where index files will be saved, defaults to the same as src_tar_directory.
131
+ :type dst_index_directory: str, optional
132
+ :param chunk_for_hash: The chunk size for hashing, defaults to 1 << 20 (1 MB).
133
+ :type chunk_for_hash: int, optional
134
+ :param with_hash: Whether to include file hashes in the index, defaults to True.
135
+ :type with_hash: bool, optional
136
+ :param silent: Whether to suppress progress bars and logging messages, defaults to False.
137
+ :type silent: bool, optional
138
+ :return: The path to the directory where index files are saved.
139
+ :rtype: str
140
+ """
141
+ dst_index_directory = dst_index_directory or src_tar_directory
142
+ for tar_file in tqdm(glob.glob(os.path.join(src_tar_directory, '**', '*.tar'), recursive=True), silent=silent):
143
+ p_idx_file = os.path.join(dst_index_directory, os.path.relpath(tar_file, src_tar_directory))
144
+ idx_body, _ = os.path.splitext(p_idx_file)
145
+ idx_file = f'{idx_body}.json'
146
+ tar_create_index(
147
+ src_tar_file=tar_file,
148
+ dst_index_file=idx_file,
149
+ chunk_for_hash=chunk_for_hash,
150
+ with_hash=with_hash,
151
+ silent=silent,
152
+ )
153
+ return dst_index_directory
154
+
155
+
98
156
  def hf_tar_create_index(repo_id: str, archive_in_repo: str,
99
157
  repo_type: RepoTypeTyping = 'dataset', revision: str = 'main',
100
158
  idx_repo_id: Optional[str] = None, idx_file_in_repo: Optional[str] = None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.3.7
3
+ Version: 0.3.8
4
4
  Summary: Useful utilities for huggingface
5
5
  Home-page: https://github.com/deepghs/hfutils
6
6
  Author: narugo1992
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
File without changes
File without changes
File without changes