huggingface-hub 1.0.0rc1__py3-none-any.whl → 1.0.0rc3__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.

Files changed (59) hide show
  1. huggingface_hub/__init__.py +4 -7
  2. huggingface_hub/_commit_api.py +126 -66
  3. huggingface_hub/_commit_scheduler.py +4 -7
  4. huggingface_hub/_login.py +10 -16
  5. huggingface_hub/_snapshot_download.py +119 -21
  6. huggingface_hub/_tensorboard_logger.py +2 -5
  7. huggingface_hub/_upload_large_folder.py +1 -2
  8. huggingface_hub/_webhooks_server.py +8 -20
  9. huggingface_hub/cli/_cli_utils.py +12 -6
  10. huggingface_hub/cli/download.py +32 -7
  11. huggingface_hub/cli/repo.py +137 -5
  12. huggingface_hub/dataclasses.py +122 -2
  13. huggingface_hub/errors.py +4 -0
  14. huggingface_hub/fastai_utils.py +22 -32
  15. huggingface_hub/file_download.py +234 -38
  16. huggingface_hub/hf_api.py +385 -424
  17. huggingface_hub/hf_file_system.py +55 -65
  18. huggingface_hub/inference/_client.py +27 -48
  19. huggingface_hub/inference/_generated/_async_client.py +27 -48
  20. huggingface_hub/inference/_generated/types/image_to_image.py +6 -2
  21. huggingface_hub/inference/_mcp/agent.py +2 -5
  22. huggingface_hub/inference/_mcp/mcp_client.py +6 -8
  23. huggingface_hub/inference/_providers/__init__.py +16 -0
  24. huggingface_hub/inference/_providers/_common.py +2 -0
  25. huggingface_hub/inference/_providers/fal_ai.py +2 -0
  26. huggingface_hub/inference/_providers/publicai.py +6 -0
  27. huggingface_hub/inference/_providers/scaleway.py +28 -0
  28. huggingface_hub/inference/_providers/zai_org.py +17 -0
  29. huggingface_hub/lfs.py +14 -8
  30. huggingface_hub/repocard.py +12 -16
  31. huggingface_hub/serialization/_base.py +3 -6
  32. huggingface_hub/serialization/_torch.py +16 -34
  33. huggingface_hub/utils/__init__.py +1 -2
  34. huggingface_hub/utils/_cache_manager.py +42 -72
  35. huggingface_hub/utils/_chunk_utils.py +2 -3
  36. huggingface_hub/utils/_http.py +37 -68
  37. huggingface_hub/utils/_validators.py +2 -2
  38. huggingface_hub/utils/logging.py +8 -11
  39. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/METADATA +2 -2
  40. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/RECORD +44 -56
  41. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/entry_points.txt +0 -1
  42. huggingface_hub/commands/__init__.py +0 -27
  43. huggingface_hub/commands/_cli_utils.py +0 -74
  44. huggingface_hub/commands/delete_cache.py +0 -476
  45. huggingface_hub/commands/download.py +0 -195
  46. huggingface_hub/commands/env.py +0 -39
  47. huggingface_hub/commands/huggingface_cli.py +0 -65
  48. huggingface_hub/commands/lfs.py +0 -200
  49. huggingface_hub/commands/repo.py +0 -151
  50. huggingface_hub/commands/repo_files.py +0 -132
  51. huggingface_hub/commands/scan_cache.py +0 -183
  52. huggingface_hub/commands/tag.py +0 -159
  53. huggingface_hub/commands/upload.py +0 -318
  54. huggingface_hub/commands/upload_large_folder.py +0 -131
  55. huggingface_hub/commands/user.py +0 -207
  56. huggingface_hub/commands/version.py +0 -40
  57. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/LICENSE +0 -0
  58. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/WHEEL +0 -0
  59. {huggingface_hub-1.0.0rc1.dist-info → huggingface_hub-1.0.0rc3.dist-info}/top_level.txt +0 -0
@@ -1,39 +0,0 @@
1
- # Copyright 2022 The HuggingFace Team. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """Contains command to print information about the environment.
15
-
16
- Usage:
17
- huggingface-cli env
18
- """
19
-
20
- from argparse import _SubParsersAction
21
-
22
- from ..utils import dump_environment_info
23
- from . import BaseHuggingfaceCLICommand
24
- from ._cli_utils import show_deprecation_warning
25
-
26
-
27
- class EnvironmentCommand(BaseHuggingfaceCLICommand):
28
- def __init__(self, args):
29
- self.args = args
30
-
31
- @staticmethod
32
- def register_subcommand(parser: _SubParsersAction):
33
- env_parser = parser.add_parser("env", help="Print information about the environment.")
34
- env_parser.set_defaults(func=EnvironmentCommand)
35
-
36
- def run(self) -> None:
37
- show_deprecation_warning("huggingface-cli env", "hf env")
38
-
39
- dump_environment_info()
@@ -1,65 +0,0 @@
1
- # Copyright 2020 The HuggingFace Team. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from argparse import ArgumentParser
16
-
17
- from huggingface_hub.commands._cli_utils import show_deprecation_warning
18
- from huggingface_hub.commands.delete_cache import DeleteCacheCommand
19
- from huggingface_hub.commands.download import DownloadCommand
20
- from huggingface_hub.commands.env import EnvironmentCommand
21
- from huggingface_hub.commands.lfs import LfsCommands
22
- from huggingface_hub.commands.repo import RepoCommands
23
- from huggingface_hub.commands.repo_files import RepoFilesCommand
24
- from huggingface_hub.commands.scan_cache import ScanCacheCommand
25
- from huggingface_hub.commands.tag import TagCommands
26
- from huggingface_hub.commands.upload import UploadCommand
27
- from huggingface_hub.commands.upload_large_folder import UploadLargeFolderCommand
28
- from huggingface_hub.commands.user import UserCommands
29
- from huggingface_hub.commands.version import VersionCommand
30
-
31
-
32
- def main():
33
- parser = ArgumentParser("huggingface-cli", usage="huggingface-cli <command> [<args>]")
34
- commands_parser = parser.add_subparsers(help="huggingface-cli command helpers")
35
-
36
- # Register commands
37
- DownloadCommand.register_subcommand(commands_parser)
38
- UploadCommand.register_subcommand(commands_parser)
39
- RepoFilesCommand.register_subcommand(commands_parser)
40
- EnvironmentCommand.register_subcommand(commands_parser)
41
- UserCommands.register_subcommand(commands_parser)
42
- RepoCommands.register_subcommand(commands_parser)
43
- LfsCommands.register_subcommand(commands_parser)
44
- ScanCacheCommand.register_subcommand(commands_parser)
45
- DeleteCacheCommand.register_subcommand(commands_parser)
46
- TagCommands.register_subcommand(commands_parser)
47
- VersionCommand.register_subcommand(commands_parser)
48
-
49
- # Experimental
50
- UploadLargeFolderCommand.register_subcommand(commands_parser)
51
-
52
- # Let's go
53
- args = parser.parse_args()
54
- if not hasattr(args, "func"):
55
- show_deprecation_warning("huggingface-cli", "hf")
56
- parser.print_help()
57
- exit(1)
58
-
59
- # Run
60
- service = args.func(args)
61
- service.run()
62
-
63
-
64
- if __name__ == "__main__":
65
- main()
@@ -1,200 +0,0 @@
1
- """
2
- Implementation of a custom transfer agent for the transfer type "multipart" for
3
- git-lfs.
4
-
5
- Inspired by:
6
- github.com/cbartz/git-lfs-swift-transfer-agent/blob/master/git_lfs_swift_transfer.py
7
-
8
- Spec is: github.com/git-lfs/git-lfs/blob/master/docs/custom-transfers.md
9
-
10
-
11
- To launch debugger while developing:
12
-
13
- ``` [lfs "customtransfer.multipart"]
14
- path = /path/to/huggingface_hub/.env/bin/python args = -m debugpy --listen 5678
15
- --wait-for-client
16
- /path/to/huggingface_hub/src/huggingface_hub/commands/huggingface_cli.py
17
- lfs-multipart-upload ```"""
18
-
19
- import json
20
- import os
21
- import subprocess
22
- import sys
23
- from argparse import _SubParsersAction
24
- from typing import Optional
25
-
26
- from huggingface_hub.commands import BaseHuggingfaceCLICommand
27
- from huggingface_hub.lfs import LFS_MULTIPART_UPLOAD_COMMAND
28
-
29
- from ..utils import get_session, hf_raise_for_status, logging
30
- from ..utils._lfs import SliceFileObj
31
-
32
-
33
- logger = logging.get_logger(__name__)
34
-
35
-
36
- class LfsCommands(BaseHuggingfaceCLICommand):
37
- """
38
- Implementation of a custom transfer agent for the transfer type "multipart"
39
- for git-lfs. This lets users upload large files >5GB 🔥. Spec for LFS custom
40
- transfer agent is:
41
- https://github.com/git-lfs/git-lfs/blob/master/docs/custom-transfers.md
42
-
43
- This introduces two commands to the CLI:
44
-
45
- 1. $ huggingface-cli lfs-enable-largefiles
46
-
47
- This should be executed once for each model repo that contains a model file
48
- >5GB. It's documented in the error message you get if you just try to git
49
- push a 5GB file without having enabled it before.
50
-
51
- 2. $ huggingface-cli lfs-multipart-upload
52
-
53
- This command is called by lfs directly and is not meant to be called by the
54
- user.
55
- """
56
-
57
- @staticmethod
58
- def register_subcommand(parser: _SubParsersAction):
59
- enable_parser = parser.add_parser(
60
- "lfs-enable-largefiles", help="Configure your repository to enable upload of files > 5GB."
61
- )
62
- enable_parser.add_argument("path", type=str, help="Local path to repository you want to configure.")
63
- enable_parser.set_defaults(func=lambda args: LfsEnableCommand(args))
64
-
65
- # Command will get called by git-lfs, do not call it directly.
66
- upload_parser = parser.add_parser(LFS_MULTIPART_UPLOAD_COMMAND, add_help=False)
67
- upload_parser.set_defaults(func=lambda args: LfsUploadCommand(args))
68
-
69
-
70
- class LfsEnableCommand:
71
- def __init__(self, args):
72
- self.args = args
73
-
74
- def run(self):
75
- local_path = os.path.abspath(self.args.path)
76
- if not os.path.isdir(local_path):
77
- print("This does not look like a valid git repo.")
78
- exit(1)
79
- subprocess.run(
80
- "git config lfs.customtransfer.multipart.path huggingface-cli".split(),
81
- check=True,
82
- cwd=local_path,
83
- )
84
- subprocess.run(
85
- f"git config lfs.customtransfer.multipart.args {LFS_MULTIPART_UPLOAD_COMMAND}".split(),
86
- check=True,
87
- cwd=local_path,
88
- )
89
- print("Local repo set up for largefiles")
90
-
91
-
92
- def write_msg(msg: dict):
93
- """Write out the message in Line delimited JSON."""
94
- msg_str = json.dumps(msg) + "\n"
95
- sys.stdout.write(msg_str)
96
- sys.stdout.flush()
97
-
98
-
99
- def read_msg() -> Optional[dict]:
100
- """Read Line delimited JSON from stdin."""
101
- msg = json.loads(sys.stdin.readline().strip())
102
-
103
- if "terminate" in (msg.get("type"), msg.get("event")):
104
- # terminate message received
105
- return None
106
-
107
- if msg.get("event") not in ("download", "upload"):
108
- logger.critical("Received unexpected message")
109
- sys.exit(1)
110
-
111
- return msg
112
-
113
-
114
- class LfsUploadCommand:
115
- def __init__(self, args) -> None:
116
- self.args = args
117
-
118
- def run(self) -> None:
119
- # Immediately after invoking a custom transfer process, git-lfs
120
- # sends initiation data to the process over stdin.
121
- # This tells the process useful information about the configuration.
122
- init_msg = json.loads(sys.stdin.readline().strip())
123
- if not (init_msg.get("event") == "init" and init_msg.get("operation") == "upload"):
124
- write_msg({"error": {"code": 32, "message": "Wrong lfs init operation"}})
125
- sys.exit(1)
126
-
127
- # The transfer process should use the information it needs from the
128
- # initiation structure, and also perform any one-off setup tasks it
129
- # needs to do. It should then respond on stdout with a simple empty
130
- # confirmation structure, as follows:
131
- write_msg({})
132
-
133
- # After the initiation exchange, git-lfs will send any number of
134
- # transfer requests to the stdin of the transfer process, in a serial sequence.
135
- while True:
136
- msg = read_msg()
137
- if msg is None:
138
- # When all transfers have been processed, git-lfs will send
139
- # a terminate event to the stdin of the transfer process.
140
- # On receiving this message the transfer process should
141
- # clean up and terminate. No response is expected.
142
- sys.exit(0)
143
-
144
- oid = msg["oid"]
145
- filepath = msg["path"]
146
- completion_url = msg["action"]["href"]
147
- header = msg["action"]["header"]
148
- chunk_size = int(header.pop("chunk_size"))
149
- presigned_urls: list[str] = list(header.values())
150
-
151
- # Send a "started" progress event to allow other workers to start.
152
- # Otherwise they're delayed until first "progress" event is reported,
153
- # i.e. after the first 5GB by default (!)
154
- write_msg(
155
- {
156
- "event": "progress",
157
- "oid": oid,
158
- "bytesSoFar": 1,
159
- "bytesSinceLast": 0,
160
- }
161
- )
162
-
163
- parts = []
164
- with open(filepath, "rb") as file:
165
- for i, presigned_url in enumerate(presigned_urls):
166
- with SliceFileObj(
167
- file,
168
- seek_from=i * chunk_size,
169
- read_limit=chunk_size,
170
- ) as data:
171
- r = get_session().put(presigned_url, data=data)
172
- hf_raise_for_status(r)
173
- parts.append(
174
- {
175
- "etag": r.headers.get("etag"),
176
- "partNumber": i + 1,
177
- }
178
- )
179
- # In order to support progress reporting while data is uploading / downloading,
180
- # the transfer process should post messages to stdout
181
- write_msg(
182
- {
183
- "event": "progress",
184
- "oid": oid,
185
- "bytesSoFar": (i + 1) * chunk_size,
186
- "bytesSinceLast": chunk_size,
187
- }
188
- )
189
- # Not precise but that's ok.
190
-
191
- r = get_session().post(
192
- completion_url,
193
- json={
194
- "oid": oid,
195
- "parts": parts,
196
- },
197
- )
198
- hf_raise_for_status(r)
199
-
200
- write_msg({"event": "complete", "oid": oid})
@@ -1,151 +0,0 @@
1
- # Copyright 2025 The HuggingFace Team. All rights reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """Contains commands to interact with repositories on the Hugging Face Hub.
15
-
16
- Usage:
17
- # create a new dataset repo on the Hub
18
- huggingface-cli repo create my-cool-dataset --repo-type=dataset
19
-
20
- # create a private model repo on the Hub
21
- huggingface-cli repo create my-cool-model --private
22
- """
23
-
24
- import argparse
25
- from argparse import _SubParsersAction
26
- from typing import Optional
27
-
28
- from huggingface_hub.commands import BaseHuggingfaceCLICommand
29
- from huggingface_hub.commands._cli_utils import ANSI
30
- from huggingface_hub.constants import SPACES_SDK_TYPES
31
- from huggingface_hub.hf_api import HfApi
32
- from huggingface_hub.utils import logging
33
-
34
- from ._cli_utils import show_deprecation_warning
35
-
36
-
37
- logger = logging.get_logger(__name__)
38
-
39
-
40
- class RepoCommands(BaseHuggingfaceCLICommand):
41
- @staticmethod
42
- def register_subcommand(parser: _SubParsersAction):
43
- repo_parser = parser.add_parser("repo", help="{create} Commands to interact with your huggingface.co repos.")
44
- repo_subparsers = repo_parser.add_subparsers(help="huggingface.co repos related commands")
45
- repo_create_parser = repo_subparsers.add_parser("create", help="Create a new repo on huggingface.co")
46
- repo_create_parser.add_argument(
47
- "repo_id",
48
- type=str,
49
- help="The ID of the repo to create to (e.g. `username/repo-name`). The username is optional and will be set to your username if not provided.",
50
- )
51
- repo_create_parser.add_argument(
52
- "--repo-type",
53
- type=str,
54
- help='Optional: set to "dataset" or "space" if creating a dataset or space, default is model.',
55
- )
56
- repo_create_parser.add_argument(
57
- "--space_sdk",
58
- type=str,
59
- help='Optional: Hugging Face Spaces SDK type. Required when --type is set to "space".',
60
- choices=SPACES_SDK_TYPES,
61
- )
62
- repo_create_parser.add_argument(
63
- "--private",
64
- action="store_true",
65
- help="Whether to create a private repository. Defaults to public unless the organization's default is private.",
66
- )
67
- repo_create_parser.add_argument(
68
- "--token",
69
- type=str,
70
- help="Hugging Face token. Will default to the locally saved token if not provided.",
71
- )
72
- repo_create_parser.add_argument(
73
- "--exist-ok",
74
- action="store_true",
75
- help="Do not raise an error if repo already exists.",
76
- )
77
- repo_create_parser.add_argument(
78
- "--resource-group-id",
79
- type=str,
80
- help="Resource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.",
81
- )
82
- repo_create_parser.add_argument(
83
- "--type",
84
- type=str,
85
- help="[Deprecated]: use --repo-type instead.",
86
- )
87
- repo_create_parser.add_argument(
88
- "-y",
89
- "--yes",
90
- action="store_true",
91
- help="[Deprecated] no effect.",
92
- )
93
- repo_create_parser.add_argument(
94
- "--organization", type=str, help="[Deprecated] Pass the organization namespace directly in the repo_id."
95
- )
96
- repo_create_parser.set_defaults(func=lambda args: RepoCreateCommand(args))
97
-
98
-
99
- class RepoCreateCommand:
100
- def __init__(self, args: argparse.Namespace):
101
- self.repo_id: str = args.repo_id
102
- self.repo_type: Optional[str] = args.repo_type or args.type
103
- self.space_sdk: Optional[str] = args.space_sdk
104
- self.organization: Optional[str] = args.organization
105
- self.yes: bool = args.yes
106
- self.private: bool = args.private
107
- self.token: Optional[str] = args.token
108
- self.exist_ok: bool = args.exist_ok
109
- self.resource_group_id: Optional[str] = args.resource_group_id
110
-
111
- if args.type is not None:
112
- print(
113
- ANSI.yellow(
114
- "The --type argument is deprecated and will be removed in a future version. Use --repo-type instead."
115
- )
116
- )
117
- if self.organization is not None:
118
- print(
119
- ANSI.yellow(
120
- "The --organization argument is deprecated and will be removed in a future version. Pass the organization namespace directly in the repo_id."
121
- )
122
- )
123
- if self.yes:
124
- print(
125
- ANSI.yellow(
126
- "The --yes argument is deprecated and will be removed in a future version. It does not have any effect."
127
- )
128
- )
129
-
130
- self._api = HfApi()
131
-
132
- def run(self):
133
- show_deprecation_warning("huggingface-cli repo", "hf repo")
134
-
135
- if self.organization is not None:
136
- if "/" in self.repo_id:
137
- print(ANSI.red("You cannot pass both --organization and a repo_id with a namespace."))
138
- exit(1)
139
- self.repo_id = f"{self.organization}/{self.repo_id}"
140
-
141
- repo_url = self._api.create_repo(
142
- repo_id=self.repo_id,
143
- repo_type=self.repo_type,
144
- private=self.private,
145
- token=self.token,
146
- exist_ok=self.exist_ok,
147
- resource_group_id=self.resource_group_id,
148
- space_sdk=self.space_sdk,
149
- )
150
- print(f"Successfully created {ANSI.bold(repo_url.repo_id)} on the Hub.")
151
- print(f"Your repo is now available at {ANSI.bold(repo_url)}")
@@ -1,132 +0,0 @@
1
- # coding=utf-8
2
- # Copyright 2023-present, the HuggingFace Inc. team.
3
- #
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- """Contains command to update or delete files in a repository using the CLI.
16
-
17
- Usage:
18
- # delete all
19
- huggingface-cli repo-files <repo_id> delete "*"
20
-
21
- # delete single file
22
- huggingface-cli repo-files <repo_id> delete file.txt
23
-
24
- # delete single folder
25
- huggingface-cli repo-files <repo_id> delete folder/
26
-
27
- # delete multiple
28
- huggingface-cli repo-files <repo_id> delete file.txt folder/ file2.txt
29
-
30
- # delete multiple patterns
31
- huggingface-cli repo-files <repo_id> delete file.txt "*.json" "folder/*.parquet"
32
-
33
- # delete from different revision / repo-type
34
- huggingface-cli repo-files <repo_id> delete file.txt --revision=refs/pr/1 --repo-type=dataset
35
- """
36
-
37
- from argparse import _SubParsersAction
38
- from typing import Optional
39
-
40
- from huggingface_hub import logging
41
- from huggingface_hub.commands import BaseHuggingfaceCLICommand
42
- from huggingface_hub.hf_api import HfApi
43
-
44
- from ._cli_utils import show_deprecation_warning
45
-
46
-
47
- logger = logging.get_logger(__name__)
48
-
49
-
50
- class DeleteFilesSubCommand:
51
- def __init__(self, args) -> None:
52
- self.args = args
53
- self.repo_id: str = args.repo_id
54
- self.repo_type: Optional[str] = args.repo_type
55
- self.revision: Optional[str] = args.revision
56
- self.api: HfApi = HfApi(token=args.token, library_name="huggingface-cli")
57
- self.patterns: list[str] = args.patterns
58
- self.commit_message: Optional[str] = args.commit_message
59
- self.commit_description: Optional[str] = args.commit_description
60
- self.create_pr: bool = args.create_pr
61
- self.token: Optional[str] = args.token
62
-
63
- def run(self) -> None:
64
- show_deprecation_warning("huggingface-cli repo-files", "hf repo-files")
65
-
66
- logging.set_verbosity_info()
67
- url = self.api.delete_files(
68
- delete_patterns=self.patterns,
69
- repo_id=self.repo_id,
70
- repo_type=self.repo_type,
71
- revision=self.revision,
72
- commit_message=self.commit_message,
73
- commit_description=self.commit_description,
74
- create_pr=self.create_pr,
75
- )
76
- print(f"Files correctly deleted from repo. Commit: {url}.")
77
- logging.set_verbosity_warning()
78
-
79
-
80
- class RepoFilesCommand(BaseHuggingfaceCLICommand):
81
- @staticmethod
82
- def register_subcommand(parser: _SubParsersAction):
83
- repo_files_parser = parser.add_parser("repo-files", help="Manage files in a repo on the Hub")
84
- repo_files_parser.add_argument(
85
- "repo_id", type=str, help="The ID of the repo to manage (e.g. `username/repo-name`)."
86
- )
87
- repo_files_subparsers = repo_files_parser.add_subparsers(
88
- help="Action to execute against the files.",
89
- required=True,
90
- )
91
- delete_subparser = repo_files_subparsers.add_parser(
92
- "delete",
93
- help="Delete files from a repo on the Hub",
94
- )
95
- delete_subparser.set_defaults(func=lambda args: DeleteFilesSubCommand(args))
96
- delete_subparser.add_argument(
97
- "patterns",
98
- nargs="+",
99
- type=str,
100
- help="Glob patterns to match files to delete.",
101
- )
102
- delete_subparser.add_argument(
103
- "--repo-type",
104
- choices=["model", "dataset", "space"],
105
- default="model",
106
- help="Type of the repo to upload to (e.g. `dataset`).",
107
- )
108
- delete_subparser.add_argument(
109
- "--revision",
110
- type=str,
111
- help=(
112
- "An optional Git revision to push to. It can be a branch name "
113
- "or a PR reference. If revision does not"
114
- " exist and `--create-pr` is not set, a branch will be automatically created."
115
- ),
116
- )
117
- delete_subparser.add_argument(
118
- "--commit-message", type=str, help="The summary / title / first line of the generated commit."
119
- )
120
- delete_subparser.add_argument(
121
- "--commit-description", type=str, help="The description of the generated commit."
122
- )
123
- delete_subparser.add_argument(
124
- "--create-pr", action="store_true", help="Whether to create a new Pull Request for these changes."
125
- )
126
- repo_files_parser.add_argument(
127
- "--token",
128
- type=str,
129
- help="A User Access Token generated from https://huggingface.co/settings/tokens",
130
- )
131
-
132
- repo_files_parser.set_defaults(func=RepoFilesCommand)