system.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 commands to print information about the environment and version.
  15. Usage:
  16. hf env
  17. hf version
  18. """
  19. from argparse import _SubParsersAction
  20. from huggingface_hub import __version__
  21. from ..utils import dump_environment_info
  22. from . import BaseHuggingfaceCLICommand
  23. class EnvironmentCommand(BaseHuggingfaceCLICommand):
  24. def __init__(self, args):
  25. self.args = args
  26. @staticmethod
  27. def register_subcommand(parser: _SubParsersAction):
  28. env_parser = parser.add_parser("env", help="Print information about the environment.")
  29. env_parser.set_defaults(func=EnvironmentCommand)
  30. def run(self) -> None:
  31. dump_environment_info()
  32. class VersionCommand(BaseHuggingfaceCLICommand):
  33. def __init__(self, args):
  34. self.args = args
  35. @staticmethod
  36. def register_subcommand(parser: _SubParsersAction):
  37. version_parser = parser.add_parser("version", help="Print information about the hf version.")
  38. version_parser.set_defaults(func=VersionCommand)
  39. def run(self) -> None:
  40. print(f"huggingface_hub version: {__version__}")