huggingface-hub 0.35.1__py3-none-any.whl → 1.0.0rc1__py3-none-any.whl
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.
Potentially problematic release.
This version of huggingface-hub might be problematic. Click here for more details.
- huggingface_hub/__init__.py +28 -45
- huggingface_hub/_commit_api.py +28 -28
- huggingface_hub/_commit_scheduler.py +11 -8
- huggingface_hub/_inference_endpoints.py +8 -8
- huggingface_hub/_jobs_api.py +20 -20
- huggingface_hub/_login.py +13 -39
- huggingface_hub/_oauth.py +8 -8
- huggingface_hub/_snapshot_download.py +14 -28
- huggingface_hub/_space_api.py +4 -4
- huggingface_hub/_tensorboard_logger.py +5 -5
- huggingface_hub/_upload_large_folder.py +15 -15
- huggingface_hub/_webhooks_payload.py +3 -3
- huggingface_hub/_webhooks_server.py +2 -2
- huggingface_hub/cli/__init__.py +0 -14
- huggingface_hub/cli/_cli_utils.py +80 -3
- huggingface_hub/cli/auth.py +104 -150
- huggingface_hub/cli/cache.py +102 -126
- huggingface_hub/cli/download.py +93 -110
- huggingface_hub/cli/hf.py +37 -41
- huggingface_hub/cli/jobs.py +689 -1017
- huggingface_hub/cli/lfs.py +120 -143
- huggingface_hub/cli/repo.py +158 -216
- huggingface_hub/cli/repo_files.py +50 -84
- huggingface_hub/cli/system.py +6 -25
- huggingface_hub/cli/upload.py +198 -212
- huggingface_hub/cli/upload_large_folder.py +90 -105
- huggingface_hub/commands/_cli_utils.py +2 -2
- huggingface_hub/commands/delete_cache.py +11 -11
- huggingface_hub/commands/download.py +4 -13
- huggingface_hub/commands/lfs.py +4 -4
- huggingface_hub/commands/repo_files.py +2 -2
- huggingface_hub/commands/tag.py +1 -3
- huggingface_hub/commands/upload.py +4 -4
- huggingface_hub/commands/upload_large_folder.py +3 -3
- huggingface_hub/commands/user.py +4 -5
- huggingface_hub/community.py +5 -5
- huggingface_hub/constants.py +3 -41
- huggingface_hub/dataclasses.py +16 -22
- huggingface_hub/errors.py +43 -30
- huggingface_hub/fastai_utils.py +8 -9
- huggingface_hub/file_download.py +154 -253
- huggingface_hub/hf_api.py +329 -558
- huggingface_hub/hf_file_system.py +104 -62
- huggingface_hub/hub_mixin.py +32 -54
- huggingface_hub/inference/_client.py +178 -163
- huggingface_hub/inference/_common.py +38 -54
- huggingface_hub/inference/_generated/_async_client.py +219 -259
- huggingface_hub/inference/_generated/types/automatic_speech_recognition.py +3 -3
- huggingface_hub/inference/_generated/types/base.py +10 -7
- huggingface_hub/inference/_generated/types/chat_completion.py +16 -16
- huggingface_hub/inference/_generated/types/depth_estimation.py +2 -2
- huggingface_hub/inference/_generated/types/document_question_answering.py +2 -2
- huggingface_hub/inference/_generated/types/feature_extraction.py +2 -2
- huggingface_hub/inference/_generated/types/fill_mask.py +2 -2
- huggingface_hub/inference/_generated/types/sentence_similarity.py +3 -3
- huggingface_hub/inference/_generated/types/summarization.py +2 -2
- huggingface_hub/inference/_generated/types/table_question_answering.py +4 -4
- huggingface_hub/inference/_generated/types/text2text_generation.py +2 -2
- huggingface_hub/inference/_generated/types/text_generation.py +10 -10
- huggingface_hub/inference/_generated/types/text_to_video.py +2 -2
- huggingface_hub/inference/_generated/types/token_classification.py +2 -2
- huggingface_hub/inference/_generated/types/translation.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_image_classification.py +2 -2
- huggingface_hub/inference/_generated/types/zero_shot_object_detection.py +1 -3
- huggingface_hub/inference/_mcp/agent.py +3 -3
- huggingface_hub/inference/_mcp/constants.py +1 -2
- huggingface_hub/inference/_mcp/mcp_client.py +33 -22
- huggingface_hub/inference/_mcp/types.py +10 -10
- huggingface_hub/inference/_mcp/utils.py +4 -4
- huggingface_hub/inference/_providers/__init__.py +2 -13
- huggingface_hub/inference/_providers/_common.py +24 -25
- huggingface_hub/inference/_providers/black_forest_labs.py +6 -6
- huggingface_hub/inference/_providers/cohere.py +3 -3
- huggingface_hub/inference/_providers/fal_ai.py +25 -25
- huggingface_hub/inference/_providers/featherless_ai.py +4 -4
- huggingface_hub/inference/_providers/fireworks_ai.py +3 -3
- huggingface_hub/inference/_providers/hf_inference.py +13 -13
- huggingface_hub/inference/_providers/hyperbolic.py +4 -4
- huggingface_hub/inference/_providers/nebius.py +10 -10
- huggingface_hub/inference/_providers/novita.py +5 -5
- huggingface_hub/inference/_providers/nscale.py +4 -4
- huggingface_hub/inference/_providers/replicate.py +15 -15
- huggingface_hub/inference/_providers/sambanova.py +6 -6
- huggingface_hub/inference/_providers/together.py +7 -7
- huggingface_hub/lfs.py +24 -33
- huggingface_hub/repocard.py +16 -17
- huggingface_hub/repocard_data.py +56 -56
- huggingface_hub/serialization/__init__.py +0 -1
- huggingface_hub/serialization/_base.py +9 -9
- huggingface_hub/serialization/_dduf.py +7 -7
- huggingface_hub/serialization/_torch.py +28 -28
- huggingface_hub/utils/__init__.py +10 -4
- huggingface_hub/utils/_auth.py +5 -5
- huggingface_hub/utils/_cache_manager.py +31 -31
- huggingface_hub/utils/_deprecation.py +1 -1
- huggingface_hub/utils/_dotenv.py +3 -3
- huggingface_hub/utils/_fixes.py +0 -10
- huggingface_hub/utils/_git_credential.py +3 -3
- huggingface_hub/utils/_headers.py +7 -29
- huggingface_hub/utils/_http.py +369 -209
- huggingface_hub/utils/_pagination.py +4 -4
- huggingface_hub/utils/_paths.py +5 -5
- huggingface_hub/utils/_runtime.py +15 -13
- huggingface_hub/utils/_safetensors.py +21 -21
- huggingface_hub/utils/_subprocess.py +9 -9
- huggingface_hub/utils/_telemetry.py +3 -3
- huggingface_hub/utils/_typing.py +3 -3
- huggingface_hub/utils/_validators.py +53 -72
- huggingface_hub/utils/_xet.py +16 -16
- huggingface_hub/utils/_xet_progress_reporting.py +1 -1
- huggingface_hub/utils/insecure_hashlib.py +3 -9
- huggingface_hub/utils/tqdm.py +3 -3
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/METADATA +17 -26
- huggingface_hub-1.0.0rc1.dist-info/RECORD +161 -0
- huggingface_hub/inference/_providers/publicai.py +0 -6
- huggingface_hub/inference/_providers/scaleway.py +0 -28
- huggingface_hub/inference_api.py +0 -217
- huggingface_hub/keras_mixin.py +0 -500
- huggingface_hub/repository.py +0 -1477
- huggingface_hub/serialization/_tensorflow.py +0 -95
- huggingface_hub/utils/_hf_folder.py +0 -68
- huggingface_hub-0.35.1.dist-info/RECORD +0 -168
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/LICENSE +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/WHEEL +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/entry_points.txt +0 -0
- {huggingface_hub-0.35.1.dist-info → huggingface_hub-1.0.0rc1.dist-info}/top_level.txt +0 -0
huggingface_hub/cli/repo.py
CHANGED
|
@@ -21,229 +21,171 @@ Usage:
|
|
|
21
21
|
hf repo create my-cool-model --private
|
|
22
22
|
"""
|
|
23
23
|
|
|
24
|
-
import
|
|
25
|
-
from argparse import _SubParsersAction
|
|
26
|
-
from typing import Optional
|
|
24
|
+
from typing import Annotated, Optional
|
|
27
25
|
|
|
28
|
-
|
|
26
|
+
import typer
|
|
29
27
|
|
|
30
|
-
from huggingface_hub.commands import BaseHuggingfaceCLICommand
|
|
31
|
-
from huggingface_hub.commands._cli_utils import ANSI
|
|
32
|
-
from huggingface_hub.constants import REPO_TYPES, SPACES_SDK_TYPES
|
|
33
28
|
from huggingface_hub.errors import HfHubHTTPError, RepositoryNotFoundError, RevisionNotFoundError
|
|
34
|
-
from huggingface_hub.hf_api import HfApi
|
|
35
29
|
from huggingface_hub.utils import logging
|
|
36
30
|
|
|
31
|
+
from ._cli_utils import (
|
|
32
|
+
ANSI,
|
|
33
|
+
PrivateOpt,
|
|
34
|
+
RepoIdArg,
|
|
35
|
+
RepoType,
|
|
36
|
+
RepoTypeOpt,
|
|
37
|
+
RevisionOpt,
|
|
38
|
+
TokenOpt,
|
|
39
|
+
get_hf_api,
|
|
40
|
+
typer_factory,
|
|
41
|
+
)
|
|
37
42
|
|
|
38
|
-
logger = logging.get_logger(__name__)
|
|
39
43
|
|
|
44
|
+
logger = logging.get_logger(__name__)
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
)
|
|
62
|
-
repo_create_parser.add_argument(
|
|
63
|
-
"--space_sdk",
|
|
64
|
-
type=str,
|
|
65
|
-
help='Optional: Hugging Face Spaces SDK type. Required when --type is set to "space".',
|
|
66
|
-
choices=SPACES_SDK_TYPES,
|
|
67
|
-
)
|
|
68
|
-
repo_create_parser.add_argument(
|
|
69
|
-
"--private",
|
|
70
|
-
action="store_true",
|
|
71
|
-
help="Whether to create a private repository. Defaults to public unless the organization's default is private.",
|
|
72
|
-
)
|
|
73
|
-
repo_create_parser.add_argument(
|
|
74
|
-
"--token",
|
|
75
|
-
type=str,
|
|
76
|
-
help="Hugging Face token. Will default to the locally saved token if not provided.",
|
|
77
|
-
)
|
|
78
|
-
repo_create_parser.add_argument(
|
|
79
|
-
"--exist-ok",
|
|
80
|
-
action="store_true",
|
|
46
|
+
repo_cli = typer_factory(help="Manage repos on the Hub.")
|
|
47
|
+
tag_app = typer_factory(help="Manage tags for a repo on the Hub.")
|
|
48
|
+
repo_cli.add_typer(tag_app, name="tag")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@repo_cli.command("create", help="Create a new repo on the Hub.")
|
|
52
|
+
def repo_create(
|
|
53
|
+
repo_id: RepoIdArg,
|
|
54
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
55
|
+
space_sdk: Annotated[
|
|
56
|
+
Optional[str],
|
|
57
|
+
typer.Option(
|
|
58
|
+
help="Hugging Face Spaces SDK type. Required when --type is set to 'space'.",
|
|
59
|
+
),
|
|
60
|
+
] = None,
|
|
61
|
+
private: PrivateOpt = False,
|
|
62
|
+
token: TokenOpt = None,
|
|
63
|
+
exist_ok: Annotated[
|
|
64
|
+
bool,
|
|
65
|
+
typer.Option(
|
|
81
66
|
help="Do not raise an error if repo already exists.",
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
),
|
|
68
|
+
] = False,
|
|
69
|
+
resource_group_id: Annotated[
|
|
70
|
+
Optional[str],
|
|
71
|
+
typer.Option(
|
|
86
72
|
help="Resource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.",
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
exit(1)
|
|
207
|
-
raise e
|
|
208
|
-
print(f"Tag {ANSI.bold(str(self.args.tag))} created on {ANSI.bold(self.repo_id)}")
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
class RepoTagListCommand(RepoTagCommand):
|
|
212
|
-
def run(self):
|
|
213
|
-
try:
|
|
214
|
-
refs = self.api.list_repo_refs(
|
|
215
|
-
repo_id=self.repo_id,
|
|
216
|
-
repo_type=self.repo_type,
|
|
217
|
-
)
|
|
218
|
-
except RepositoryNotFoundError:
|
|
219
|
-
print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.")
|
|
220
|
-
exit(1)
|
|
221
|
-
except HTTPError as e:
|
|
222
|
-
print(e)
|
|
223
|
-
print(ANSI.red(e.response.text))
|
|
224
|
-
exit(1)
|
|
225
|
-
if len(refs.tags) == 0:
|
|
226
|
-
print("No tags found")
|
|
227
|
-
exit(0)
|
|
228
|
-
print(f"Tags for {self.repo_type} {ANSI.bold(self.repo_id)}:")
|
|
229
|
-
for tag in refs.tags:
|
|
230
|
-
print(tag.name)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
class RepoTagDeleteCommand(RepoTagCommand):
|
|
234
|
-
def run(self):
|
|
235
|
-
print(f"You are about to delete tag {ANSI.bold(self.args.tag)} on {self.repo_type} {ANSI.bold(self.repo_id)}")
|
|
236
|
-
if not getattr(self.args, "yes", False):
|
|
237
|
-
choice = input("Proceed? [Y/n] ").lower()
|
|
238
|
-
if choice not in ("", "y", "yes"):
|
|
239
|
-
print("Abort")
|
|
240
|
-
exit()
|
|
241
|
-
try:
|
|
242
|
-
self.api.delete_tag(repo_id=self.repo_id, tag=self.args.tag, repo_type=self.repo_type)
|
|
243
|
-
except RepositoryNotFoundError:
|
|
244
|
-
print(f"{self.repo_type.capitalize()} {ANSI.bold(self.repo_id)} not found.")
|
|
245
|
-
exit(1)
|
|
246
|
-
except RevisionNotFoundError:
|
|
247
|
-
print(f"Tag {ANSI.bold(self.args.tag)} not found on {ANSI.bold(self.repo_id)}")
|
|
248
|
-
exit(1)
|
|
249
|
-
print(f"Tag {ANSI.bold(self.args.tag)} deleted on {ANSI.bold(self.repo_id)}")
|
|
73
|
+
),
|
|
74
|
+
] = None,
|
|
75
|
+
) -> None:
|
|
76
|
+
api = get_hf_api(token=token)
|
|
77
|
+
repo_url = api.create_repo(
|
|
78
|
+
repo_id=repo_id,
|
|
79
|
+
repo_type=repo_type.value,
|
|
80
|
+
private=private,
|
|
81
|
+
token=token,
|
|
82
|
+
exist_ok=exist_ok,
|
|
83
|
+
resource_group_id=resource_group_id,
|
|
84
|
+
space_sdk=space_sdk,
|
|
85
|
+
)
|
|
86
|
+
print(f"Successfully created {ANSI.bold(repo_url.repo_id)} on the Hub.")
|
|
87
|
+
print(f"Your repo is now available at {ANSI.bold(repo_url)}")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@tag_app.command("create", help="Create a tag for a repo.")
|
|
91
|
+
def tag_create(
|
|
92
|
+
repo_id: RepoIdArg,
|
|
93
|
+
tag: Annotated[
|
|
94
|
+
str,
|
|
95
|
+
typer.Argument(
|
|
96
|
+
help="The name of the tag to create.",
|
|
97
|
+
),
|
|
98
|
+
],
|
|
99
|
+
message: Annotated[
|
|
100
|
+
Optional[str],
|
|
101
|
+
typer.Option(
|
|
102
|
+
"-m",
|
|
103
|
+
"--message",
|
|
104
|
+
help="The description of the tag to create.",
|
|
105
|
+
),
|
|
106
|
+
] = None,
|
|
107
|
+
revision: RevisionOpt = None,
|
|
108
|
+
token: TokenOpt = None,
|
|
109
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
110
|
+
) -> None:
|
|
111
|
+
repo_type_str = repo_type.value
|
|
112
|
+
api = get_hf_api(token=token)
|
|
113
|
+
print(f"You are about to create tag {ANSI.bold(tag)} on {repo_type_str} {ANSI.bold(repo_id)}")
|
|
114
|
+
try:
|
|
115
|
+
api.create_tag(repo_id=repo_id, tag=tag, tag_message=message, revision=revision, repo_type=repo_type_str)
|
|
116
|
+
except RepositoryNotFoundError:
|
|
117
|
+
print(f"{repo_type_str.capitalize()} {ANSI.bold(repo_id)} not found.")
|
|
118
|
+
raise typer.Exit(code=1)
|
|
119
|
+
except RevisionNotFoundError:
|
|
120
|
+
print(f"Revision {ANSI.bold(str(revision))} not found.")
|
|
121
|
+
raise typer.Exit(code=1)
|
|
122
|
+
except HfHubHTTPError as e:
|
|
123
|
+
if e.response.status_code == 409:
|
|
124
|
+
print(f"Tag {ANSI.bold(tag)} already exists on {ANSI.bold(repo_id)}")
|
|
125
|
+
raise typer.Exit(code=1)
|
|
126
|
+
raise e
|
|
127
|
+
print(f"Tag {ANSI.bold(tag)} created on {ANSI.bold(repo_id)}")
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@tag_app.command("list", help="List tags for a repo.")
|
|
131
|
+
def tag_list(
|
|
132
|
+
repo_id: RepoIdArg,
|
|
133
|
+
token: TokenOpt = None,
|
|
134
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
135
|
+
) -> None:
|
|
136
|
+
repo_type_str = repo_type.value
|
|
137
|
+
api = get_hf_api(token=token)
|
|
138
|
+
try:
|
|
139
|
+
refs = api.list_repo_refs(repo_id=repo_id, repo_type=repo_type_str)
|
|
140
|
+
except RepositoryNotFoundError:
|
|
141
|
+
print(f"{repo_type_str.capitalize()} {ANSI.bold(repo_id)} not found.")
|
|
142
|
+
raise typer.Exit(code=1)
|
|
143
|
+
except HfHubHTTPError as e:
|
|
144
|
+
print(e)
|
|
145
|
+
print(ANSI.red(e.response.text))
|
|
146
|
+
raise typer.Exit(code=1)
|
|
147
|
+
if len(refs.tags) == 0:
|
|
148
|
+
print("No tags found")
|
|
149
|
+
raise typer.Exit(code=0)
|
|
150
|
+
print(f"Tags for {repo_type_str} {ANSI.bold(repo_id)}:")
|
|
151
|
+
for t in refs.tags:
|
|
152
|
+
print(t.name)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@tag_app.command("delete", help="Delete a tag for a repo.")
|
|
156
|
+
def tag_delete(
|
|
157
|
+
repo_id: RepoIdArg,
|
|
158
|
+
tag: Annotated[
|
|
159
|
+
str,
|
|
160
|
+
typer.Argument(
|
|
161
|
+
help="The name of the tag to delete.",
|
|
162
|
+
),
|
|
163
|
+
],
|
|
164
|
+
yes: Annotated[
|
|
165
|
+
bool,
|
|
166
|
+
typer.Option(
|
|
167
|
+
"-y",
|
|
168
|
+
"--yes",
|
|
169
|
+
help="Answer Yes to prompt automatically",
|
|
170
|
+
),
|
|
171
|
+
] = False,
|
|
172
|
+
token: TokenOpt = None,
|
|
173
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
174
|
+
) -> None:
|
|
175
|
+
repo_type_str = repo_type.value
|
|
176
|
+
print(f"You are about to delete tag {ANSI.bold(tag)} on {repo_type_str} {ANSI.bold(repo_id)}")
|
|
177
|
+
if not yes:
|
|
178
|
+
choice = input("Proceed? [Y/n] ").lower()
|
|
179
|
+
if choice not in ("", "y", "yes"):
|
|
180
|
+
print("Abort")
|
|
181
|
+
raise typer.Exit()
|
|
182
|
+
api = get_hf_api(token=token)
|
|
183
|
+
try:
|
|
184
|
+
api.delete_tag(repo_id=repo_id, tag=tag, repo_type=repo_type_str)
|
|
185
|
+
except RepositoryNotFoundError:
|
|
186
|
+
print(f"{repo_type_str.capitalize()} {ANSI.bold(repo_id)} not found.")
|
|
187
|
+
raise typer.Exit(code=1)
|
|
188
|
+
except RevisionNotFoundError:
|
|
189
|
+
print(f"Tag {ANSI.bold(tag)} not found on {ANSI.bold(repo_id)}")
|
|
190
|
+
raise typer.Exit(code=1)
|
|
191
|
+
print(f"Tag {ANSI.bold(tag)} deleted on {ANSI.bold(repo_id)}")
|
|
@@ -34,95 +34,61 @@ Usage:
|
|
|
34
34
|
hf repo-files delete <repo_id> file.txt --revision=refs/pr/1 --repo-type=dataset
|
|
35
35
|
"""
|
|
36
36
|
|
|
37
|
-
from
|
|
38
|
-
|
|
37
|
+
from typing import Annotated, Optional
|
|
38
|
+
|
|
39
|
+
import typer
|
|
39
40
|
|
|
40
41
|
from huggingface_hub import logging
|
|
41
|
-
|
|
42
|
-
from
|
|
42
|
+
|
|
43
|
+
from ._cli_utils import RepoIdArg, RepoType, RepoTypeOpt, RevisionOpt, TokenOpt, get_hf_api, typer_factory
|
|
43
44
|
|
|
44
45
|
|
|
45
46
|
logger = logging.get_logger(__name__)
|
|
46
47
|
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
self.commit_description: Optional[str] = args.commit_description
|
|
58
|
-
self.create_pr: bool = args.create_pr
|
|
59
|
-
self.token: Optional[str] = args.token
|
|
60
|
-
|
|
61
|
-
def run(self) -> None:
|
|
62
|
-
logging.set_verbosity_info()
|
|
63
|
-
url = self.api.delete_files(
|
|
64
|
-
delete_patterns=self.patterns,
|
|
65
|
-
repo_id=self.repo_id,
|
|
66
|
-
repo_type=self.repo_type,
|
|
67
|
-
revision=self.revision,
|
|
68
|
-
commit_message=self.commit_message,
|
|
69
|
-
commit_description=self.commit_description,
|
|
70
|
-
create_pr=self.create_pr,
|
|
71
|
-
)
|
|
72
|
-
print(f"Files correctly deleted from repo. Commit: {url}.")
|
|
73
|
-
logging.set_verbosity_warning()
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
class RepoFilesCommand(BaseHuggingfaceCLICommand):
|
|
77
|
-
@staticmethod
|
|
78
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
79
|
-
repo_files_parser = parser.add_parser("repo-files", help="Manage files in a repo on the Hub.")
|
|
80
|
-
repo_files_subparsers = repo_files_parser.add_subparsers(
|
|
81
|
-
help="Action to execute against the files.",
|
|
82
|
-
required=True,
|
|
83
|
-
)
|
|
84
|
-
delete_subparser = repo_files_subparsers.add_parser(
|
|
85
|
-
"delete",
|
|
86
|
-
help="Delete files from a repo on the Hub",
|
|
87
|
-
)
|
|
88
|
-
delete_subparser.set_defaults(func=lambda args: DeleteFilesSubCommand(args))
|
|
89
|
-
delete_subparser.add_argument(
|
|
90
|
-
"repo_id", type=str, help="The ID of the repo to manage (e.g. `username/repo-name`)."
|
|
91
|
-
)
|
|
92
|
-
delete_subparser.add_argument(
|
|
93
|
-
"patterns",
|
|
94
|
-
nargs="+",
|
|
95
|
-
type=str,
|
|
49
|
+
repo_files_cli = typer_factory(help="Manage files in a repo on the Hub.")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@repo_files_cli.command("delete")
|
|
53
|
+
def repo_files_delete(
|
|
54
|
+
repo_id: RepoIdArg,
|
|
55
|
+
patterns: Annotated[
|
|
56
|
+
list[str],
|
|
57
|
+
typer.Argument(
|
|
96
58
|
help="Glob patterns to match files to delete.",
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
59
|
+
),
|
|
60
|
+
],
|
|
61
|
+
repo_type: RepoTypeOpt = RepoType.model,
|
|
62
|
+
revision: RevisionOpt = None,
|
|
63
|
+
commit_message: Annotated[
|
|
64
|
+
Optional[str],
|
|
65
|
+
typer.Option(
|
|
66
|
+
help="The summary / title / first line of the generated commit.",
|
|
67
|
+
),
|
|
68
|
+
] = None,
|
|
69
|
+
commit_description: Annotated[
|
|
70
|
+
Optional[str],
|
|
71
|
+
typer.Option(
|
|
72
|
+
help="The description of the generated commit.",
|
|
73
|
+
),
|
|
74
|
+
] = None,
|
|
75
|
+
create_pr: Annotated[
|
|
76
|
+
bool,
|
|
77
|
+
typer.Option(
|
|
78
|
+
help="Whether to create a new Pull Request for these changes.",
|
|
79
|
+
),
|
|
80
|
+
] = False,
|
|
81
|
+
token: TokenOpt = None,
|
|
82
|
+
) -> None:
|
|
83
|
+
api = get_hf_api(token=token)
|
|
84
|
+
url = api.delete_files(
|
|
85
|
+
delete_patterns=patterns,
|
|
86
|
+
repo_id=repo_id,
|
|
87
|
+
repo_type=repo_type.value,
|
|
88
|
+
revision=revision,
|
|
89
|
+
commit_message=commit_message,
|
|
90
|
+
commit_description=commit_description,
|
|
91
|
+
create_pr=create_pr,
|
|
92
|
+
)
|
|
93
|
+
print(f"Files correctly deleted from repo. Commit: {url}.")
|
|
94
|
+
logging.set_verbosity_warning()
|
huggingface_hub/cli/system.py
CHANGED
|
@@ -18,35 +18,16 @@ Usage:
|
|
|
18
18
|
hf version
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
from argparse import _SubParsersAction
|
|
22
|
-
|
|
23
21
|
from huggingface_hub import __version__
|
|
24
22
|
|
|
25
23
|
from ..utils import dump_environment_info
|
|
26
|
-
from . import BaseHuggingfaceCLICommand
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class EnvironmentCommand(BaseHuggingfaceCLICommand):
|
|
30
|
-
def __init__(self, args):
|
|
31
|
-
self.args = args
|
|
32
|
-
|
|
33
|
-
@staticmethod
|
|
34
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
35
|
-
env_parser = parser.add_parser("env", help="Print information about the environment.")
|
|
36
|
-
env_parser.set_defaults(func=EnvironmentCommand)
|
|
37
|
-
|
|
38
|
-
def run(self) -> None:
|
|
39
|
-
dump_environment_info()
|
|
40
24
|
|
|
41
25
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
26
|
+
def env() -> None:
|
|
27
|
+
"""Print information about the environment."""
|
|
28
|
+
dump_environment_info()
|
|
45
29
|
|
|
46
|
-
@staticmethod
|
|
47
|
-
def register_subcommand(parser: _SubParsersAction):
|
|
48
|
-
version_parser = parser.add_parser("version", help="Print information about the hf version.")
|
|
49
|
-
version_parser.set_defaults(func=VersionCommand)
|
|
50
30
|
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
def version() -> None:
|
|
32
|
+
"""Print CLI version."""
|
|
33
|
+
print(f"huggingface_hub version: {__version__}")
|