codekingpro/portable-devtools
114k
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 at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# 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 and13# limitations under the License.14 15import sys16import traceback17from typing import Annotated18 19import typer20 21from huggingface_hub import __version__, constants22from huggingface_hub.cli._cli_utils import check_cli_update, fallback_typer_group_factory, typer_factory23from huggingface_hub.cli._errors import format_known_exception24from huggingface_hub.cli.auth import auth_cli25from huggingface_hub.cli.buckets import buckets_cli, sync26from huggingface_hub.cli.cache import cache_cli27from huggingface_hub.cli.collections import collections_cli28from huggingface_hub.cli.datasets import datasets_cli29from huggingface_hub.cli.discussions import discussions_cli30from huggingface_hub.cli.download import DOWNLOAD_EXAMPLES, download31from huggingface_hub.cli.extensions import (32 dispatch_unknown_top_level_extension,33 extensions_cli,34 list_installed_extensions_for_help,35)36from huggingface_hub.cli.inference_endpoints import ie_cli37from huggingface_hub.cli.jobs import jobs_cli38from huggingface_hub.cli.lfs import lfs_enable_largefiles, lfs_multipart_upload39from huggingface_hub.cli.models import models_cli40from huggingface_hub.cli.papers import papers_cli41from huggingface_hub.cli.repo_files import repo_files_cli42from huggingface_hub.cli.repos import repos_cli43from huggingface_hub.cli.skills import skills_cli44from huggingface_hub.cli.spaces import spaces_cli45from huggingface_hub.cli.system import env, update, version46from huggingface_hub.cli.upload import UPLOAD_EXAMPLES, upload47from huggingface_hub.cli.upload_large_folder import UPLOAD_LARGE_FOLDER_EXAMPLES, upload_large_folder48from huggingface_hub.cli.webhooks import webhooks_cli49from huggingface_hub.utils import ANSI, logging50 51 52app = typer_factory(53 help="Hugging Face Hub CLI",54 cls=fallback_typer_group_factory(55 dispatch_unknown_top_level_extension,56 extra_commands_provider=list_installed_extensions_for_help,57 ),58)59 60 61def _version_callback(value: bool) -> None:62 if value:63 print(__version__)64 raise typer.Exit()65 66 67@app.callback(invoke_without_command=True)68def app_callback(69 version: Annotated[70 bool | None, typer.Option("-v", "--version", callback=_version_callback, is_eager=True, hidden=True)71 ] = None,72) -> None:73 pass74 75 76# top level single commands (defined in their respective files)77app.command()(sync)78app.command(examples=DOWNLOAD_EXAMPLES)(download)79app.command(examples=UPLOAD_EXAMPLES)(upload)80app.command(examples=UPLOAD_LARGE_FOLDER_EXAMPLES)(upload_large_folder)81 82app.command(topic="help")(env)83app.command(topic="help")(update)84app.command(topic="help")(version)85 86app.command(hidden=True)(lfs_enable_largefiles)87app.command(hidden=True)(lfs_multipart_upload)88 89# command groups90app.add_typer(auth_cli, name="auth")91app.add_typer(buckets_cli, name="buckets")92app.add_typer(cache_cli, name="cache")93app.add_typer(collections_cli, name="collections")94app.add_typer(datasets_cli, name="datasets")95app.add_typer(discussions_cli, name="discussions")96app.add_typer(jobs_cli, name="jobs")97app.add_typer(models_cli, name="models")98app.add_typer(papers_cli, name="papers")99app.add_typer(repos_cli, name="repos | repo")100app.add_typer(repo_files_cli, name="repo-files", hidden=True)101app.add_typer(skills_cli, name="skills")102app.add_typer(spaces_cli, name="spaces")103app.add_typer(webhooks_cli, name="webhooks")104app.add_typer(ie_cli, name="endpoints")105app.add_typer(extensions_cli, name="extensions | ext")106 107 108def main():109 if not constants.HF_DEBUG:110 logging.set_verbosity_info()111 check_cli_update("huggingface_hub")112 113 try:114 app()115 except Exception as e:116 message = format_known_exception(e)117 if message:118 print(f"Error: {message}", file=sys.stderr)119 if constants.HF_DEBUG:120 traceback.print_exc()121 else:122 print(ANSI.gray("Set HF_DEBUG=1 as environment variable for full traceback."))123 sys.exit(1)124 raise125 126 127if __name__ == "__main__":128 main()129 