__init__.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 .core import ParameterSource as ParameterSource
  16. from .decorators import argument as argument
  17. from .decorators import command as command
  18. from .decorators import confirmation_option as confirmation_option
  19. from .decorators import custom_version_option as custom_version_option
  20. from .decorators import group as group
  21. from .decorators import help_option as help_option
  22. from .decorators import make_pass_decorator as make_pass_decorator
  23. from .decorators import option as option
  24. from .decorators import pass_context as pass_context
  25. from .decorators import pass_obj as pass_obj
  26. from .decorators import password_option as password_option
  27. from .decorators import version_option as version_option
  28. from .exceptions import Abort as Abort
  29. from .exceptions import BadArgumentUsage as BadArgumentUsage
  30. from .exceptions import BadOptionUsage as BadOptionUsage
  31. from .exceptions import BadParameter as BadParameter
  32. from .exceptions import ClickException as ClickException
  33. from .exceptions import FileError as FileError
  34. from .exceptions import MissingParameter as MissingParameter
  35. from .exceptions import NoSuchCommand as NoSuchCommand
  36. from .exceptions import NoSuchOption as NoSuchOption
  37. from .exceptions import UsageError as UsageError
  38. from .formatting import HelpFormatter as HelpFormatter
  39. from .formatting import wrap_text as wrap_text
  40. from .globals import get_current_context as get_current_context
  41. from .termui import clear as clear
  42. from .termui import confirm as confirm
  43. from .termui import echo_via_pager as echo_via_pager
  44. from .termui import edit as edit
  45. from .termui import get_pager_file as get_pager_file
  46. from .termui import getchar as getchar
  47. from .termui import launch as launch
  48. from .termui import pause as pause
  49. from .termui import progressbar as progressbar
  50. from .termui import prompt as prompt
  51. from .termui import secho as secho
  52. from .termui import style as style
  53. from .termui import unstyle as unstyle
  54. from .types import BOOL as BOOL
  55. from .types import Choice as Choice
  56. from .types import DateTime as DateTime
  57. from .types import File as File
  58. from .types import FLOAT as FLOAT
  59. from .types import FloatRange as FloatRange
  60. from .types import INT as INT
  61. from .types import IntRange as IntRange
  62. from .types import ParamType as ParamType
  63. from .types import Path as Path
  64. from .types import STRING as STRING
  65. from .types import Tuple as Tuple
  66. from .types import UNPROCESSED as UNPROCESSED
  67. from .types import UUID as UUID
  68. from .utils import echo as echo
  69. from .utils import format_filename as format_filename
  70. from .utils import get_app_dir as get_app_dir
  71. from .utils import open_file as open_file
  72. def __getattr__(name: str) -> object:
  73. import warnings
  74. if name == "BaseCommand":
  75. from .core import _BaseCommand
  76. warnings.warn(
  77. "'BaseCommand' is deprecated and will be removed in Click 9.0. Use"
  78. " 'Command' instead.",
  79. DeprecationWarning,
  80. stacklevel=2,
  81. )
  82. return _BaseCommand
  83. if name == "MultiCommand":
  84. from .core import _MultiCommand
  85. warnings.warn(
  86. "'MultiCommand' is deprecated and will be removed in Click 9.0. Use"
  87. " 'Group' instead.",
  88. DeprecationWarning,
  89. stacklevel=2,
  90. )
  91. return _MultiCommand
  92. if name == "OptionParser":
  93. from .parser import _OptionParser
  94. warnings.warn(
  95. "'OptionParser' is deprecated and will be removed in Click 9.0. The"
  96. " old parser is available in 'optparse'.",
  97. DeprecationWarning,
  98. stacklevel=2,
  99. )
  100. return _OptionParser
  101. if name == "__version__":
  102. import importlib.metadata
  103. warnings.warn(
  104. "The '__version__' attribute is deprecated and will be removed in"
  105. " Click 9.1. Use feature detection or"
  106. " 'importlib.metadata.version(\"click\")' instead.",
  107. DeprecationWarning,
  108. stacklevel=2,
  109. )
  110. return importlib.metadata.version("click")
  111. if name == "get_binary_stream":
  112. from .utils import _get_binary_stream
  113. warnings.warn(
  114. "'get_binary_stream' is deprecated and will be removed in Click 9.0.",
  115. DeprecationWarning,
  116. stacklevel=2,
  117. )
  118. return _get_binary_stream
  119. if name == "get_text_stream":
  120. from .utils import _get_text_stream
  121. warnings.warn(
  122. "'get_text_stream' is deprecated and will be removed in Click 9.0.",
  123. DeprecationWarning,
  124. stacklevel=2,
  125. )
  126. return _get_text_stream
  127. raise AttributeError(name)