__init__.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. """
  2. Click is a simple Python module inspired by the stdlib optparse to make
  3. writing command line scripts fun. Unlike other modules, it's based
  4. around a simple API that does not come with too much magic and is
  5. composable.
  6. """
  7. from __future__ import annotations
  8. from .core import Argument as Argument
  9. from .core import Command as Command
  10. from .core import CommandCollection as CommandCollection
  11. from .core import Context as Context
  12. from .core import Group as Group
  13. from .core import Option as Option
  14. from .core import Parameter as Parameter
  15. from .decorators import argument as argument
  16. from .decorators import command as command
  17. from .decorators import confirmation_option as confirmation_option
  18. from .decorators import group as group
  19. from .decorators import help_option as help_option
  20. from .decorators import make_pass_decorator as make_pass_decorator
  21. from .decorators import option as option
  22. from .decorators import pass_context as pass_context
  23. from .decorators import pass_obj as pass_obj
  24. from .decorators import password_option as password_option
  25. from .decorators import version_option as version_option
  26. from .exceptions import Abort as Abort
  27. from .exceptions import BadArgumentUsage as BadArgumentUsage
  28. from .exceptions import BadOptionUsage as BadOptionUsage
  29. from .exceptions import BadParameter as BadParameter
  30. from .exceptions import ClickException as ClickException
  31. from .exceptions import FileError as FileError
  32. from .exceptions import MissingParameter as MissingParameter
  33. from .exceptions import NoSuchOption as NoSuchOption
  34. from .exceptions import UsageError as UsageError
  35. from .formatting import HelpFormatter as HelpFormatter
  36. from .formatting import wrap_text as wrap_text
  37. from .globals import get_current_context as get_current_context
  38. from .termui import clear as clear
  39. from .termui import confirm as confirm
  40. from .termui import echo_via_pager as echo_via_pager
  41. from .termui import edit as edit
  42. from .termui import getchar as getchar
  43. from .termui import launch as launch
  44. from .termui import pause as pause
  45. from .termui import progressbar as progressbar
  46. from .termui import prompt as prompt
  47. from .termui import secho as secho
  48. from .termui import style as style
  49. from .termui import unstyle as unstyle
  50. from .types import BOOL as BOOL
  51. from .types import Choice as Choice
  52. from .types import DateTime as DateTime
  53. from .types import File as File
  54. from .types import FLOAT as FLOAT
  55. from .types import FloatRange as FloatRange
  56. from .types import INT as INT
  57. from .types import IntRange as IntRange
  58. from .types import ParamType as ParamType
  59. from .types import Path as Path
  60. from .types import STRING as STRING
  61. from .types import Tuple as Tuple
  62. from .types import UNPROCESSED as UNPROCESSED
  63. from .types import UUID as UUID
  64. from .utils import echo as echo
  65. from .utils import format_filename as format_filename
  66. from .utils import get_app_dir as get_app_dir
  67. from .utils import get_binary_stream as get_binary_stream
  68. from .utils import get_text_stream as get_text_stream
  69. from .utils import open_file as open_file
  70. def __getattr__(name: str) -> object:
  71. import warnings
  72. if name == "BaseCommand":
  73. from .core import _BaseCommand
  74. warnings.warn(
  75. "'BaseCommand' is deprecated and will be removed in Click 9.0. Use"
  76. " 'Command' instead.",
  77. DeprecationWarning,
  78. stacklevel=2,
  79. )
  80. return _BaseCommand
  81. if name == "MultiCommand":
  82. from .core import _MultiCommand
  83. warnings.warn(
  84. "'MultiCommand' is deprecated and will be removed in Click 9.0. Use"
  85. " 'Group' instead.",
  86. DeprecationWarning,
  87. stacklevel=2,
  88. )
  89. return _MultiCommand
  90. if name == "OptionParser":
  91. from .parser import _OptionParser
  92. warnings.warn(
  93. "'OptionParser' is deprecated and will be removed in Click 9.0. The"
  94. " old parser is available in 'optparse'.",
  95. DeprecationWarning,
  96. stacklevel=2,
  97. )
  98. return _OptionParser
  99. if name == "__version__":
  100. import importlib.metadata
  101. import warnings
  102. warnings.warn(
  103. "The '__version__' attribute is deprecated and will be removed in"
  104. " Click 9.1. Use feature detection or"
  105. " 'importlib.metadata.version(\"click\")' instead.",
  106. DeprecationWarning,
  107. stacklevel=2,
  108. )
  109. return importlib.metadata.version("click")
  110. raise AttributeError(name)