hfutils 0.1.1__tar.gz → 0.1.2__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 (45) hide show
  1. {hfutils-0.1.1/hfutils.egg-info → hfutils-0.1.2}/PKG-INFO +1 -1
  2. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/config/meta.py +1 -1
  3. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/entry/download.py +9 -1
  4. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/operate/download.py +29 -11
  5. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/operate/upload.py +1 -1
  6. {hfutils-0.1.1 → hfutils-0.1.2/hfutils.egg-info}/PKG-INFO +1 -1
  7. {hfutils-0.1.1 → hfutils-0.1.2}/LICENSE +0 -0
  8. {hfutils-0.1.1 → hfutils-0.1.2}/MANIFEST.in +0 -0
  9. {hfutils-0.1.1 → hfutils-0.1.2}/README.md +0 -0
  10. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/__init__.py +0 -0
  11. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/archive/__init__.py +0 -0
  12. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/archive/base.py +0 -0
  13. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/archive/rar.py +0 -0
  14. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/archive/sevenz.py +0 -0
  15. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/archive/tar.py +0 -0
  16. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/archive/zip.py +0 -0
  17. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/config/__init__.py +0 -0
  18. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/entry/__init__.py +0 -0
  19. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/entry/base.py +0 -0
  20. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/entry/cli.py +0 -0
  21. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/entry/dispatch.py +0 -0
  22. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/entry/upload.py +0 -0
  23. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/operate/__init__.py +0 -0
  24. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/operate/base.py +0 -0
  25. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/operate/validate.py +0 -0
  26. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/utils/__init__.py +0 -0
  27. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/utils/binary.py +0 -0
  28. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/utils/download.py +0 -0
  29. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/utils/temp.py +0 -0
  30. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/utils/tqdm_.py +0 -0
  31. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils/utils/walk.py +0 -0
  32. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils.egg-info/SOURCES.txt +0 -0
  33. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils.egg-info/dependency_links.txt +0 -0
  34. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils.egg-info/entry_points.txt +0 -0
  35. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils.egg-info/requires.txt +0 -0
  36. {hfutils-0.1.1 → hfutils-0.1.2}/hfutils.egg-info/top_level.txt +0 -0
  37. {hfutils-0.1.1 → hfutils-0.1.2}/requirements-7z.txt +0 -0
  38. {hfutils-0.1.1 → hfutils-0.1.2}/requirements-build.txt +0 -0
  39. {hfutils-0.1.1 → hfutils-0.1.2}/requirements-doc.txt +0 -0
  40. {hfutils-0.1.1 → hfutils-0.1.2}/requirements-rar.txt +0 -0
  41. {hfutils-0.1.1 → hfutils-0.1.2}/requirements-test.txt +0 -0
  42. {hfutils-0.1.1 → hfutils-0.1.2}/requirements-transfer.txt +0 -0
  43. {hfutils-0.1.1 → hfutils-0.1.2}/requirements.txt +0 -0
  44. {hfutils-0.1.1 → hfutils-0.1.2}/setup.cfg +0 -0
  45. {hfutils-0.1.1 → hfutils-0.1.2}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.1.1
3
+ Version: 0.1.2
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.1.1'
10
+ __VERSION__ = '0.1.2'
11
11
 
12
12
  #: Short description of the project, will be included in ``setup.py``.
13
13
  __DESCRIPTION__ = 'Useful utilities for huggingface'
@@ -1,3 +1,4 @@
1
+ import os
1
2
  import warnings
2
3
  from typing import Optional
3
4
 
@@ -46,10 +47,12 @@ def _add_download_subcommand(cli: click.Group) -> click.Group:
46
47
  help='Max threads to download.', show_default=True)
47
48
  @click.option('-p', '--password', 'password', type=str, default=None,
48
49
  help='Password for the archive file. Only applied when -a is used.', show_default=True)
50
+ @click.option('--tmpdir', 'tmpdir', type=str, default=None,
51
+ help='Use custom temporary Directory.', show_default=True)
49
52
  @command_wrap()
50
53
  def download(repo_id: str, repo_type: RepoTypeTyping,
51
54
  file_in_repo: Optional[str], archive_in_repo: Optional[str], dir_in_repo: Optional[str],
52
- output_path: str, revision: str, max_workers: int, password: Optional[str]):
55
+ output_path: str, revision: str, max_workers: int, password: Optional[str], tmpdir: Optional[str]):
53
56
  """
54
57
  Download data from HuggingFace repositories.
55
58
 
@@ -71,7 +74,12 @@ def _add_download_subcommand(cli: click.Group) -> click.Group:
71
74
  :type max_workers: int
72
75
  :param password: Password for the archive file. Only applied when -a is used.
73
76
  :type password: str, optional
77
+ :param tmpdir: Use custom temporary Directory.
78
+ :type tmpdir: str, optional
74
79
  """
80
+ if tmpdir:
81
+ os.environ['TMPDIR'] = tmpdir
82
+
75
83
  if not file_in_repo and not archive_in_repo and not dir_in_repo:
76
84
  raise NoRemotePathAssignedWithDownload('No remote path in repository assigned.\n'
77
85
  'One of the -f, -a, or -d option is required.')
@@ -4,6 +4,8 @@ import shutil
4
4
  from concurrent.futures import ThreadPoolExecutor
5
5
  from typing import List, Optional
6
6
 
7
+ import requests.exceptions
8
+
7
9
  from .base import RepoTypeTyping, list_files_in_repository, _IGNORE_PATTERN_UNSET, get_hf_client
8
10
  from .validate import is_local_file_ready
9
11
  from ..archive import archive_unpack
@@ -83,7 +85,7 @@ def download_archive_as_directory(local_directory: str, repo_id: str, file_in_re
83
85
  def download_directory_as_directory(local_directory: str, repo_id: str, dir_in_repo: str = '.',
84
86
  repo_type: RepoTypeTyping = 'dataset', revision: str = 'main',
85
87
  silent: bool = False, ignore_patterns: List[str] = _IGNORE_PATTERN_UNSET,
86
- resume_download: bool = True, max_workers: int = 8,
88
+ resume_download: bool = True, max_workers: int = 8, max_retries: int = 5,
87
89
  hf_token: Optional[str] = None):
88
90
  """
89
91
  Download all files in a directory from a Hugging Face repository to a local directory.
@@ -104,15 +106,18 @@ def download_directory_as_directory(local_directory: str, repo_id: str, dir_in_r
104
106
  :type ignore_patterns: List[str]
105
107
  :param max_workers: Max workers when downloading. Default is ``8``.
106
108
  :type max_workers: int
109
+ :param max_retries: Max retry times when downloading. Default is ``5``.
110
+ :type max_retries: int
107
111
  :param resume_download: Resume the existing download.
108
112
  :type resume_download: bool
109
113
  :param hf_token: Huggingface token for API client, use ``HF_TOKEN`` variable if not assigned.
110
114
  :type hf_token: str, optional
111
115
  """
112
- files = list_files_in_repository(repo_id, repo_type, dir_in_repo, revision, ignore_patterns)
116
+ files = list_files_in_repository(repo_id, repo_type, dir_in_repo, revision, ignore_patterns, hf_token=hf_token)
113
117
  progress = tqdm(files, silent=silent, desc=f'Downloading {dir_in_repo!r} ...')
114
118
 
115
119
  def _download_one_file(rel_file):
120
+ current_resume_download = resume_download
116
121
  try:
117
122
  dst_file = os.path.join(local_directory, rel_file)
118
123
  if os.path.exists(dst_file) and is_local_file_ready(
@@ -125,15 +130,28 @@ def download_directory_as_directory(local_directory: str, repo_id: str, dir_in_r
125
130
  ):
126
131
  logging.info(f'Local file {rel_file} is ready, download skipped.')
127
132
  else:
128
- download_file_to_file(
129
- local_file=dst_file,
130
- repo_id=repo_id,
131
- file_in_repo=f'{dir_in_repo}/{rel_file}',
132
- repo_type=repo_type,
133
- revision=revision,
134
- resume_download=resume_download,
135
- hf_token=hf_token,
136
- )
133
+ tries = 0
134
+ while True:
135
+ try:
136
+ download_file_to_file(
137
+ local_file=dst_file,
138
+ repo_id=repo_id,
139
+ file_in_repo=f'{dir_in_repo}/{rel_file}',
140
+ repo_type=repo_type,
141
+ revision=revision,
142
+ resume_download=current_resume_download,
143
+ hf_token=hf_token,
144
+ )
145
+ except requests.exceptions.RequestException as err:
146
+ if tries < max_retries:
147
+ tries += 1
148
+ logging.warning(f'Download {rel_file!r} failed, retry ({tries}/{max_retries}) - {err!r}.')
149
+ current_resume_download = True
150
+ else:
151
+ raise
152
+ else:
153
+ break
154
+
137
155
  progress.update()
138
156
  except Exception as err:
139
157
  logging.error(f'Unexpected error when downloading {rel_file!r} - {err!r}')
@@ -110,7 +110,7 @@ def upload_directory_as_directory(local_directory, repo_id: str, path_in_repo: s
110
110
  if clear:
111
111
  pre_exist_files = {
112
112
  tuple(file.split('/')) for file in
113
- list_files_in_repository(repo_id, repo_type, path_in_repo, revision, ignore_patterns)
113
+ list_files_in_repository(repo_id, repo_type, path_in_repo, revision, ignore_patterns, hf_token=hf_token)
114
114
  }
115
115
  else:
116
116
  pre_exist_files = set()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hfutils
3
- Version: 0.1.1
3
+ Version: 0.1.2
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