hfutils 0.1.0__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.
- {hfutils-0.1.0/hfutils.egg-info → hfutils-0.1.2}/PKG-INFO +1 -1
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/config/meta.py +1 -1
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/entry/download.py +9 -1
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/operate/download.py +44 -23
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/operate/upload.py +1 -1
- {hfutils-0.1.0 → hfutils-0.1.2/hfutils.egg-info}/PKG-INFO +1 -1
- {hfutils-0.1.0 → hfutils-0.1.2}/LICENSE +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/MANIFEST.in +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/README.md +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/__init__.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/archive/__init__.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/archive/base.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/archive/rar.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/archive/sevenz.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/archive/tar.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/archive/zip.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/config/__init__.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/entry/__init__.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/entry/base.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/entry/cli.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/entry/dispatch.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/entry/upload.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/operate/__init__.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/operate/base.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/operate/validate.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/utils/__init__.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/utils/binary.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/utils/download.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/utils/temp.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/utils/tqdm_.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils/utils/walk.py +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils.egg-info/SOURCES.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils.egg-info/dependency_links.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils.egg-info/entry_points.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils.egg-info/requires.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/hfutils.egg-info/top_level.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/requirements-7z.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/requirements-build.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/requirements-doc.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/requirements-rar.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/requirements-test.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/requirements-transfer.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/requirements.txt +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/setup.cfg +0 -0
- {hfutils-0.1.0 → hfutils-0.1.2}/setup.py +0 -0
|
@@ -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,36 +106,55 @@ 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):
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
120
|
+
current_resume_download = resume_download
|
|
121
|
+
try:
|
|
122
|
+
dst_file = os.path.join(local_directory, rel_file)
|
|
123
|
+
if os.path.exists(dst_file) and is_local_file_ready(
|
|
124
|
+
repo_id=repo_id,
|
|
125
|
+
repo_type=repo_type,
|
|
126
|
+
local_file=dst_file,
|
|
127
|
+
file_in_repo=f'{dir_in_repo}/{rel_file}',
|
|
128
|
+
revision=revision,
|
|
129
|
+
hf_token=hf_token,
|
|
130
|
+
):
|
|
131
|
+
logging.info(f'Local file {rel_file} is ready, download skipped.')
|
|
132
|
+
else:
|
|
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
|
+
|
|
155
|
+
progress.update()
|
|
156
|
+
except Exception as err:
|
|
157
|
+
logging.error(f'Unexpected error when downloading {rel_file!r} - {err!r}')
|
|
137
158
|
|
|
138
159
|
tp = ThreadPoolExecutor(max_workers=max_workers)
|
|
139
160
|
for file in files:
|
|
@@ -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()
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|