repo_files.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright 2023-present, the HuggingFace Inc. team.
  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. """Legacy `hf repo-files` command.
  15. Kept for backward compatibility. Users are nudged to use `hf repos delete-files` instead.
  16. """
  17. from typing import Annotated
  18. import typer
  19. from ._cli_utils import (
  20. FormatWithAutoOpt,
  21. RepoIdArg,
  22. RepoType,
  23. RepoTypeOpt,
  24. RevisionOpt,
  25. TokenOpt,
  26. get_hf_api,
  27. typer_factory,
  28. )
  29. from ._output import OutputFormatWithAuto, out
  30. repo_files_cli = typer_factory(
  31. help="(Deprecated) Manage files in a repo on the Hub. Use `hf repos delete-files` instead."
  32. )
  33. @repo_files_cli.command(
  34. "delete",
  35. )
  36. def repo_files_delete(
  37. repo_id: RepoIdArg,
  38. patterns: Annotated[
  39. list[str],
  40. typer.Argument(
  41. help="Glob patterns to match files to delete. Based on fnmatch, '*' matches files recursively.",
  42. ),
  43. ],
  44. repo_type: RepoTypeOpt = RepoType.model,
  45. revision: RevisionOpt = None,
  46. commit_message: Annotated[
  47. str | None,
  48. typer.Option(
  49. help="The summary / title / first line of the generated commit.",
  50. ),
  51. ] = None,
  52. commit_description: Annotated[
  53. str | None,
  54. typer.Option(
  55. help="The description of the generated commit.",
  56. ),
  57. ] = None,
  58. create_pr: Annotated[
  59. bool,
  60. typer.Option(
  61. help="Whether to create a new Pull Request for these changes.",
  62. ),
  63. ] = False,
  64. token: TokenOpt = None,
  65. format: FormatWithAutoOpt = OutputFormatWithAuto.auto,
  66. ) -> None:
  67. out.warning("`hf repo-files delete` is deprecated. Use `hf repos delete-files` instead.")
  68. api = get_hf_api(token=token)
  69. url = api.delete_files(
  70. delete_patterns=patterns,
  71. repo_id=repo_id,
  72. repo_type=repo_type.value,
  73. revision=revision,
  74. commit_message=commit_message,
  75. commit_description=commit_description,
  76. create_pr=create_pr,
  77. )
  78. out.result("Files deleted", repo_id=repo_id, commit_url=url)