From 358b82316fddee2326eeaa2a78f7cdc5d9e025b9 Mon Sep 17 00:00:00 2001 From: martinbrose <13284268+martinbrose@users.noreply.github.com> Date: Sat, 16 Sep 2023 09:38:59 +0100 Subject: [PATCH 1/6] Add repo list, delete, and toggle --- .../commands/huggingface_cli.py | 2 + src/huggingface_hub/commands/repo.py | 300 ++++++++++++++++++ src/huggingface_hub/commands/user.py | 99 ------ 3 files changed, 302 insertions(+), 99 deletions(-) create mode 100644 src/huggingface_hub/commands/repo.py diff --git a/src/huggingface_hub/commands/huggingface_cli.py b/src/huggingface_hub/commands/huggingface_cli.py index 39b6dfe49a..a8914ab6ff 100644 --- a/src/huggingface_hub/commands/huggingface_cli.py +++ b/src/huggingface_hub/commands/huggingface_cli.py @@ -22,6 +22,7 @@ from huggingface_hub.commands.scan_cache import ScanCacheCommand from huggingface_hub.commands.upload import UploadCommand from huggingface_hub.commands.user import UserCommands +from huggingface_hub.commands.repo import RepoCommands def main(): @@ -36,6 +37,7 @@ def main(): LfsCommands.register_subcommand(commands_parser) ScanCacheCommand.register_subcommand(commands_parser) DeleteCacheCommand.register_subcommand(commands_parser) + RepoCommands.register_subcommand(commands_parser) # Let's go args = parser.parse_args() diff --git a/src/huggingface_hub/commands/repo.py b/src/huggingface_hub/commands/repo.py new file mode 100644 index 0000000000..de9965cc01 --- /dev/null +++ b/src/huggingface_hub/commands/repo.py @@ -0,0 +1,300 @@ +# coding=utf-8 +# Copyright 2023-present, the HuggingFace Inc. team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Contains commands to perform repo management with the CLI. + +Usage Examples: + # Create a new repository on huggingface.co + huggingface-cli repo create my-cool-model + + # List repositories on huggingface.co + huggingface-cli repo list + + # Delete a repository on huggingface.co + huggingface-cli repo delete my-cool-model + + # Toggle the visibility of a repository to private + huggingface-cli repo toggle my-cool-model private +""" +import subprocess +from argparse import Namespace, _SubParsersAction + +from requests.exceptions import HTTPError + +from huggingface_hub.commands import BaseHuggingfaceCLICommand +from huggingface_hub.constants import ( + REPO_TYPES, + REPO_TYPES_URL_PREFIXES, + SPACES_SDK_TYPES, +) +from huggingface_hub.hf_api import HfApi + +from ..utils import HfFolder +from ._cli_utils import ANSI + +class RepoCommands(BaseHuggingfaceCLICommand): + @staticmethod + def register_subcommand(parser: _SubParsersAction): + repo_parser = parser.add_parser( + "repo", + help="{create, ls-files, list, delete, toggle visibility} commands to interact with your huggingface.co repos.", + ) + repo_subparsers = repo_parser.add_subparsers(help="huggingface.co repos related commands") + repo_create_parser = repo_subparsers.add_parser("create", help="Create a new repo on huggingface.co") + repo_create_parser.add_argument( + "name", + type=str, + help="Name for your repo. Will be namespaced under your username to build the repo id.", + ) + repo_create_parser.add_argument( + "--type", + choices=["model", "dataset", "space"], + default="model", + help='Optional: type: set to "dataset" or "space" if creating a dataset or space, default is model.', + ) + repo_create_parser.add_argument("--organization", type=str, help="Optional: organization namespace.") + repo_create_parser.add_argument( + "--space_sdk", + type=str, + help='Optional: Hugging Face Spaces SDK type. Required when --type is set to "space".', + choices=SPACES_SDK_TYPES, + ) + repo_create_parser.add_argument( + "-y", + "--yes", + action="store_true", + help="Optional: answer Yes to the prompt", + ) + repo_create_parser.set_defaults(func=lambda args: RepoCreateCommand(args)) + repo_list_parser = repo_subparsers.add_parser("list", help="List repos on huggingface.co") + repo_list_parser.add_argument( + "--type", + choices=["model", "dataset", "space"], + default="model", + help="Type of repos to list, default is model.", + ) + repo_list_parser.add_argument( + "--author", + type=str, + help="Optional: author namespace.", + ) + repo_list_parser.add_argument( + "--search", + type=str, + help="Optional: A string that will be contained in the returned repo ids.", + ) + repo_list_parser.set_defaults(func=lambda args: RepoListCommand(args)) + repo_delete_parser = repo_subparsers.add_parser("delete", help="Delete a repo on huggingface.co") + repo_delete_parser.add_argument( + "name", + type=str, + help="Name for your repo.", + ) + repo_delete_parser.add_argument( + "--type", + choices=["model", "dataset", "space"], + default="model", + help="Type of repos to list, default is model.", + ) + repo_delete_parser.add_argument("--organization", type=str, help="Optional: organization namespace.") + repo_delete_parser.add_argument( + "-y", + "--yes", + action="store_true", + help="Optional: answer Yes to the prompt", + ) + repo_delete_parser.set_defaults(func=lambda args: RepoDeleteCommand(args)) + repo_toggle_parser = repo_subparsers.add_parser("toggle", help="Toggle a repo on huggingface.co private or public") + repo_toggle_parser.add_argument( + "name", + type=str, + help="Name for your repo.", + ) + repo_toggle_parser.add_argument( + "private", + choices=["public", "private"], + default="public", + help="Name for your repo.", + ) + repo_toggle_parser.add_argument( + "--type", + choices=["model", "dataset", "space"], + default="model", + help="Type of repos to list, default is model.", + ) + repo_toggle_parser.add_argument("--organization", type=str, help="Optional: organization namespace.") + repo_toggle_parser.add_argument( + "-y", + "--yes", + action="store_true", + help="Optional: answer Yes to the prompt", + ) + repo_toggle_parser.set_defaults(func=lambda args: RepoToggleCommand(args)) + +class BaseRepoCommand: + def __init__(self, args: Namespace): + self.args = args + self._api = HfApi() + self.token = HfFolder.get_token() + if self.token is None: + print("Not logged in") + exit(1) + try: + stdout = subprocess.check_output(["git", "--version"]).decode("utf-8") + print(ANSI.gray(stdout.strip())) + except FileNotFoundError: + print("Looks like you do not have git installed, please install.") + + +class RepoCreateCommand(BaseRepoCommand): + def run(self): + try: + stdout = subprocess.check_output(["git-lfs", "--version"]).decode("utf-8") + print(ANSI.gray(stdout.strip())) + except FileNotFoundError: + print( + ANSI.red( + "Looks like you do not have git-lfs installed, please install." + " You can install from https://git-lfs.github.com/." + " Then run `git lfs install` (you only have to do this once)." + ) + ) + print("") + + user = self._api.whoami(self.token)["name"] + namespace = self.args.organization if self.args.organization is not None else user + + repo_id = f"{namespace}/{self.args.name}" + + if self.args.type not in REPO_TYPES: + print("Invalid repo --type") + exit(1) + + if self.args.type in REPO_TYPES_URL_PREFIXES: + prefixed_repo_id = REPO_TYPES_URL_PREFIXES[self.args.type] + repo_id + else: + prefixed_repo_id = repo_id + + print(f"You are about to create {ANSI.bold(prefixed_repo_id)}") + + if not self.args.yes: + choice = input("Proceed? [Y/n] ").lower() + if not (choice == "" or choice == "y" or choice == "yes"): + print("Abort") + exit() + try: + url = self._api.create_repo( + repo_id=repo_id, + token=self.token, + repo_type=self.args.type, + space_sdk=self.args.space_sdk, + ) + except HTTPError as e: + print(e) + print(ANSI.red(e.response.text)) + exit(1) + print("\nYour repo now lives at:") + print(f" {ANSI.bold(url)}") + print("\nYou can clone it locally with the command below, and commit/push as usual.") + print(f"\n git clone {url}") + print("") + +class RepoListCommand(BaseRepoCommand): + def run(self): + self.type = self.args.type + self.author = self.args.author + self.search = self.args.search + try: + if self.type is None or self.type == "model": + repos = self._api.list_models(token=self.token, author=self.author, search=self.search) + elif self.type == "dataset": + repos = self._api.list_datasets(token=self.token, author=self.author, search=self.search) + elif self.type == "space": + repos = self._api.list_spaces(token=self.token, author=self.author, search=self.search) + except HTTPError as e: + print(e) + print(ANSI.red(e.response.text)) + exit(1) + print("\nYour repos:") + for repo in repos: + print(f" {ANSI.bold(repo.id)}") + print("") + + +class RepoDeleteCommand(BaseRepoCommand): + def run(self): + user = self._api.whoami(self.token)["name"] + namespace = self.args.organization if self.args.organization is not None else user + + repo_id = f"{namespace}/{self.args.name}" + + if self.args.type not in REPO_TYPES: + print("Invalid repo --type") + exit(1) + + if self.args.type in REPO_TYPES_URL_PREFIXES: + prefixed_repo_id = REPO_TYPES_URL_PREFIXES[self.args.type] + repo_id + else: + prefixed_repo_id = repo_id + + print(f"You are about to delete {ANSI.bold(prefixed_repo_id)}") + + if not self.args.yes: + choice = input("Proceed? [Y/n] ").lower() + if not (choice == "" or choice == "y" or choice == "yes"): + print("Abort") + exit() + try: + self._api.delete_repo(repo_id=repo_id, token=self.token, repo_type=self.args.type) + except HTTPError as e: + print(e) + print(ANSI.red(e.response.text)) + exit(1) + print("\nYour repo has been deleted.") + print("") + + +class RepoToggleCommand(BaseRepoCommand): + def run(self): + self.private = self.args.private + user = self._api.whoami(self.token)["name"] + namespace = self.args.organization if self.args.organization is not None else user + + repo_id = f"{namespace}/{self.args.name}" + + if self.args.type not in REPO_TYPES: + print("Invalid repo --type") + exit(1) + + if self.args.type in REPO_TYPES_URL_PREFIXES: + prefixed_repo_id = REPO_TYPES_URL_PREFIXES[self.args.type] + repo_id + else: + prefixed_repo_id = repo_id + + print(f"You are about to toggle {ANSI.bold(prefixed_repo_id)} to {self.private}") + + if not self.args.yes: + choice = input("Proceed? [Y/n] ").lower() + if not (choice == "" or choice == "y" or choice == "yes"): + print("Abort") + exit() + self.privateBool = False if self.private == "public" else True + try: + self._api.update_repo_visibility(repo_id=repo_id, private=self.privateBool, token=self.token, repo_type=self.args.type) + except HTTPError as e: + print(e) + print(ANSI.red(e.response.text)) + exit(1) + print(f"\nYour repo has been toggled to {self.private}.") + print("") \ No newline at end of file diff --git a/src/huggingface_hub/commands/user.py b/src/huggingface_hub/commands/user.py index b6a7a0145c..0d6931b3db 100644 --- a/src/huggingface_hub/commands/user.py +++ b/src/huggingface_hub/commands/user.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import subprocess from argparse import _SubParsersAction from requests.exceptions import HTTPError @@ -19,9 +18,6 @@ from huggingface_hub.commands import BaseHuggingfaceCLICommand from huggingface_hub.constants import ( ENDPOINT, - REPO_TYPES, - REPO_TYPES_URL_PREFIXES, - SPACES_SDK_TYPES, ) from huggingface_hub.hf_api import HfApi @@ -57,39 +53,6 @@ def register_subcommand(parser: _SubParsersAction): logout_parser = parser.add_parser("logout", help="Log out") logout_parser.set_defaults(func=lambda args: LogoutCommand(args)) - # new system: git-based repo system - repo_parser = parser.add_parser( - "repo", - help="{create, ls-files} Commands to interact with your huggingface.co repos.", - ) - repo_subparsers = repo_parser.add_subparsers(help="huggingface.co repos related commands") - repo_create_parser = repo_subparsers.add_parser("create", help="Create a new repo on huggingface.co") - repo_create_parser.add_argument( - "name", - type=str, - help="Name for your repo. Will be namespaced under your username to build the repo id.", - ) - repo_create_parser.add_argument( - "--type", - type=str, - help='Optional: repo_type: set to "dataset" or "space" if creating a dataset or space, default is model.', - ) - repo_create_parser.add_argument("--organization", type=str, help="Optional: organization namespace.") - repo_create_parser.add_argument( - "--space_sdk", - type=str, - help='Optional: Hugging Face Spaces SDK type. Required when --type is set to "space".', - choices=SPACES_SDK_TYPES, - ) - repo_create_parser.add_argument( - "-y", - "--yes", - action="store_true", - help="Optional: answer Yes to the prompt", - ) - repo_create_parser.set_defaults(func=lambda args: RepoCreateCommand(args)) - - class BaseUserCommand: def __init__(self, args): self.args = args @@ -127,65 +90,3 @@ def run(self): exit(1) -class RepoCreateCommand(BaseUserCommand): - def run(self): - token = HfFolder.get_token() - if token is None: - print("Not logged in") - exit(1) - try: - stdout = subprocess.check_output(["git", "--version"]).decode("utf-8") - print(ANSI.gray(stdout.strip())) - except FileNotFoundError: - print("Looks like you do not have git installed, please install.") - - try: - stdout = subprocess.check_output(["git-lfs", "--version"]).decode("utf-8") - print(ANSI.gray(stdout.strip())) - except FileNotFoundError: - print( - ANSI.red( - "Looks like you do not have git-lfs installed, please install." - " You can install from https://git-lfs.github.com/." - " Then run `git lfs install` (you only have to do this once)." - ) - ) - print("") - - user = self._api.whoami(token)["name"] - namespace = self.args.organization if self.args.organization is not None else user - - repo_id = f"{namespace}/{self.args.name}" - - if self.args.type not in REPO_TYPES: - print("Invalid repo --type") - exit(1) - - if self.args.type in REPO_TYPES_URL_PREFIXES: - prefixed_repo_id = REPO_TYPES_URL_PREFIXES[self.args.type] + repo_id - else: - prefixed_repo_id = repo_id - - print(f"You are about to create {ANSI.bold(prefixed_repo_id)}") - - if not self.args.yes: - choice = input("Proceed? [Y/n] ").lower() - if not (choice == "" or choice == "y" or choice == "yes"): - print("Abort") - exit() - try: - url = self._api.create_repo( - repo_id=repo_id, - token=token, - repo_type=self.args.type, - space_sdk=self.args.space_sdk, - ) - except HTTPError as e: - print(e) - print(ANSI.red(e.response.text)) - exit(1) - print("\nYour repo now lives at:") - print(f" {ANSI.bold(url)}") - print("\nYou can clone it locally with the command below, and commit/push as usual.") - print(f"\n git clone {url}") - print("") From 2b84dc5c2c0e5c57390d81f3b2865254d476f77e Mon Sep 17 00:00:00 2001 From: martinbrose <13284268+martinbrose@users.noreply.github.com> Date: Sat, 16 Sep 2023 09:51:11 +0100 Subject: [PATCH 2/6] Make style / quality --- .../commands/huggingface_cli.py | 2 +- src/huggingface_hub/commands/repo.py | 18 ++++++++++++++---- src/huggingface_hub/commands/user.py | 3 +-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/huggingface_hub/commands/huggingface_cli.py b/src/huggingface_hub/commands/huggingface_cli.py index a8914ab6ff..bc8b2804f9 100644 --- a/src/huggingface_hub/commands/huggingface_cli.py +++ b/src/huggingface_hub/commands/huggingface_cli.py @@ -19,10 +19,10 @@ from huggingface_hub.commands.download import DownloadCommand from huggingface_hub.commands.env import EnvironmentCommand from huggingface_hub.commands.lfs import LfsCommands +from huggingface_hub.commands.repo import RepoCommands from huggingface_hub.commands.scan_cache import ScanCacheCommand from huggingface_hub.commands.upload import UploadCommand from huggingface_hub.commands.user import UserCommands -from huggingface_hub.commands.repo import RepoCommands def main(): diff --git a/src/huggingface_hub/commands/repo.py b/src/huggingface_hub/commands/repo.py index de9965cc01..71579e8da5 100644 --- a/src/huggingface_hub/commands/repo.py +++ b/src/huggingface_hub/commands/repo.py @@ -43,12 +43,16 @@ from ..utils import HfFolder from ._cli_utils import ANSI + class RepoCommands(BaseHuggingfaceCLICommand): @staticmethod def register_subcommand(parser: _SubParsersAction): repo_parser = parser.add_parser( "repo", - help="{create, ls-files, list, delete, toggle visibility} commands to interact with your huggingface.co repos.", + help=( + "{create, ls-files, list, delete, toggle visibility} commands to interact with your huggingface.co" + " repos." + ), ) repo_subparsers = repo_parser.add_subparsers(help="huggingface.co repos related commands") repo_create_parser = repo_subparsers.add_parser("create", help="Create a new repo on huggingface.co") @@ -115,7 +119,9 @@ def register_subcommand(parser: _SubParsersAction): help="Optional: answer Yes to the prompt", ) repo_delete_parser.set_defaults(func=lambda args: RepoDeleteCommand(args)) - repo_toggle_parser = repo_subparsers.add_parser("toggle", help="Toggle a repo on huggingface.co private or public") + repo_toggle_parser = repo_subparsers.add_parser( + "toggle", help="Toggle a repo on huggingface.co private or public" + ) repo_toggle_parser.add_argument( "name", type=str, @@ -142,6 +148,7 @@ def register_subcommand(parser: _SubParsersAction): ) repo_toggle_parser.set_defaults(func=lambda args: RepoToggleCommand(args)) + class BaseRepoCommand: def __init__(self, args: Namespace): self.args = args @@ -210,6 +217,7 @@ def run(self): print(f"\n git clone {url}") print("") + class RepoListCommand(BaseRepoCommand): def run(self): self.type = self.args.type @@ -291,10 +299,12 @@ def run(self): exit() self.privateBool = False if self.private == "public" else True try: - self._api.update_repo_visibility(repo_id=repo_id, private=self.privateBool, token=self.token, repo_type=self.args.type) + self._api.update_repo_visibility( + repo_id=repo_id, private=self.privateBool, token=self.token, repo_type=self.args.type + ) except HTTPError as e: print(e) print(ANSI.red(e.response.text)) exit(1) print(f"\nYour repo has been toggled to {self.private}.") - print("") \ No newline at end of file + print("") diff --git a/src/huggingface_hub/commands/user.py b/src/huggingface_hub/commands/user.py index 0d6931b3db..bd10c1b548 100644 --- a/src/huggingface_hub/commands/user.py +++ b/src/huggingface_hub/commands/user.py @@ -53,6 +53,7 @@ def register_subcommand(parser: _SubParsersAction): logout_parser = parser.add_parser("logout", help="Log out") logout_parser.set_defaults(func=lambda args: LogoutCommand(args)) + class BaseUserCommand: def __init__(self, args): self.args = args @@ -88,5 +89,3 @@ def run(self): print(e) print(ANSI.red(e.response.text)) exit(1) - - From 29d6b343032cb74fcfdf0a7789cad1ac2c181426 Mon Sep 17 00:00:00 2001 From: martinbrose <13284268+martinbrose@users.noreply.github.com> Date: Sat, 16 Sep 2023 14:52:18 +0100 Subject: [PATCH 3/6] Rename toggle visibility argument --- src/huggingface_hub/commands/repo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/huggingface_hub/commands/repo.py b/src/huggingface_hub/commands/repo.py index 71579e8da5..edb4bef3aa 100644 --- a/src/huggingface_hub/commands/repo.py +++ b/src/huggingface_hub/commands/repo.py @@ -128,7 +128,7 @@ def register_subcommand(parser: _SubParsersAction): help="Name for your repo.", ) repo_toggle_parser.add_argument( - "private", + "visibility", choices=["public", "private"], default="public", help="Name for your repo.", From 2bd733c18c831d095784539e57bcb426b67faeae Mon Sep 17 00:00:00 2001 From: martinbrose <13284268+martinbrose@users.noreply.github.com> Date: Sat, 16 Sep 2023 14:59:31 +0100 Subject: [PATCH 4/6] Add basic CLI repo tests --- tests/test_cli.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4117eb86f0..7ddd0e9447 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -9,6 +9,7 @@ from huggingface_hub.commands.delete_cache import DeleteCacheCommand from huggingface_hub.commands.download import DownloadCommand +from huggingface_hub.commands.repo import RepoCommands from huggingface_hub.commands.scan_cache import ScanCacheCommand from huggingface_hub.commands.upload import UploadCommand from huggingface_hub.utils import SoftTemporaryDirectory, capture_output @@ -500,6 +501,49 @@ def test_download_with_ignored_patterns(self, mock: Mock) -> None: DownloadCommand(args).run() +class TestRepoCommands(unittest.TestCase): + def setUp(self) -> None: + """ + Set up CLI as in `src/huggingface_hub/commands/huggingface_cli.py`. + """ + self.parser = ArgumentParser("huggingface-cli", usage="huggingface-cli []") + commands_parser = self.parser.add_subparsers() + RepoCommands.register_subcommand(commands_parser) + + def test_repo_create_basic(self) -> None: + """Test `huggingface-cli create dummy-repo`.""" + args = self.parser.parse_args(["repo", "create", DUMMY_MODEL_ID]) + self.assertEqual(args.name, DUMMY_MODEL_ID) + self.assertEqual(args.type, "model") + self.assertIsNone(args.organization) + self.assertIsNone(args.space_sdk) + self.assertFalse(args.yes) + + def test_repo_list_basic(self) -> None: + """Test `huggingface-cli download dummy-repo`.""" + args = self.parser.parse_args(["repo", "list"]) + self.assertEqual(args.type, "model") + self.assertIsNone(args.author) + self.assertIsNone(args.search) + + def test_repo_delete_basic(self) -> None: + """Test `huggingface-cli download dummy-repo`.""" + args = self.parser.parse_args(["repo", "delete", DUMMY_MODEL_ID]) + self.assertEqual(args.name, DUMMY_MODEL_ID) + self.assertEqual(args.type, "model") + self.assertIsNone(args.organization) + self.assertFalse(args.yes) + + def test_repo_toggle_basic(self) -> None: + """Test `huggingface-cli download dummy-repo`.""" + args = self.parser.parse_args(["repo", "toggle", DUMMY_MODEL_ID, "public"]) + self.assertEqual(args.name, DUMMY_MODEL_ID) + self.assertEqual(args.visibility, "public") + self.assertEqual(args.type, "model") + self.assertIsNone(args.organization) + self.assertFalse(args.yes) + + @contextmanager def tmp_current_directory() -> Generator[str, None, None]: """Change current directory to a tmp dir and revert back when exiting.""" From cf4505ca4645a479e666fc1d95cc89753c46fe42 Mon Sep 17 00:00:00 2001 From: martinbrose <13284268+martinbrose@users.noreply.github.com> Date: Sat, 16 Sep 2023 22:27:27 +0100 Subject: [PATCH 5/6] Correct help strings --- src/huggingface_hub/commands/repo.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/huggingface_hub/commands/repo.py b/src/huggingface_hub/commands/repo.py index edb4bef3aa..a23ecb054f 100644 --- a/src/huggingface_hub/commands/repo.py +++ b/src/huggingface_hub/commands/repo.py @@ -103,13 +103,13 @@ def register_subcommand(parser: _SubParsersAction): repo_delete_parser.add_argument( "name", type=str, - help="Name for your repo.", + help="Name of your repo to delete.", ) repo_delete_parser.add_argument( "--type", choices=["model", "dataset", "space"], default="model", - help="Type of repos to list, default is model.", + help="Type of repos to delete, default is model.", ) repo_delete_parser.add_argument("--organization", type=str, help="Optional: organization namespace.") repo_delete_parser.add_argument( @@ -125,19 +125,19 @@ def register_subcommand(parser: _SubParsersAction): repo_toggle_parser.add_argument( "name", type=str, - help="Name for your repo.", + help="Name of your repo to toggle.", ) repo_toggle_parser.add_argument( "visibility", choices=["public", "private"], default="public", - help="Name for your repo.", + help="Visibility to change repo to, default is public.", ) repo_toggle_parser.add_argument( "--type", choices=["model", "dataset", "space"], default="model", - help="Type of repos to list, default is model.", + help="Type of repo to toggle, default is model.", ) repo_toggle_parser.add_argument("--organization", type=str, help="Optional: organization namespace.") repo_toggle_parser.add_argument( From 6205c76016f9fcec13c96d3e5bd7e0d08bad3aa4 Mon Sep 17 00:00:00 2001 From: martinbrose <13284268+martinbrose@users.noreply.github.com> Date: Sun, 17 Sep 2023 09:24:57 +0100 Subject: [PATCH 6/6] Correct test case description & change toggle test --- tests/test_cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7ddd0e9447..d5f64a155e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -520,14 +520,14 @@ def test_repo_create_basic(self) -> None: self.assertFalse(args.yes) def test_repo_list_basic(self) -> None: - """Test `huggingface-cli download dummy-repo`.""" + """Test `huggingface-cli list repos`.""" args = self.parser.parse_args(["repo", "list"]) self.assertEqual(args.type, "model") self.assertIsNone(args.author) self.assertIsNone(args.search) def test_repo_delete_basic(self) -> None: - """Test `huggingface-cli download dummy-repo`.""" + """Test `huggingface-cli delete dummy-repo`.""" args = self.parser.parse_args(["repo", "delete", DUMMY_MODEL_ID]) self.assertEqual(args.name, DUMMY_MODEL_ID) self.assertEqual(args.type, "model") @@ -535,10 +535,10 @@ def test_repo_delete_basic(self) -> None: self.assertFalse(args.yes) def test_repo_toggle_basic(self) -> None: - """Test `huggingface-cli download dummy-repo`.""" - args = self.parser.parse_args(["repo", "toggle", DUMMY_MODEL_ID, "public"]) + """Test `huggingface-cli toggle dummy-repo visibility to private`.""" + args = self.parser.parse_args(["repo", "toggle", DUMMY_MODEL_ID, "private"]) self.assertEqual(args.name, DUMMY_MODEL_ID) - self.assertEqual(args.visibility, "public") + self.assertEqual(args.visibility, "private") self.assertEqual(args.type, "model") self.assertIsNone(args.organization) self.assertFalse(args.yes)