_lazy_rich.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Source code: https://github.com/hamdanal/rich-argparse
  2. # MIT license: Copyright (c) Ali Hamdan <ali.hamdan.dev@gmail.com>
  3. # for internal use only
  4. from __future__ import annotations
  5. TYPE_CHECKING = False
  6. if TYPE_CHECKING:
  7. from typing import Any
  8. from rich.ansi import re_ansi as re_ansi
  9. from rich.console import Console as Console
  10. from rich.console import ConsoleOptions as ConsoleOptions
  11. from rich.console import RenderableType as RenderableType
  12. from rich.console import RenderResult as RenderResult
  13. from rich.containers import Lines as Lines
  14. from rich.control import strip_control_codes as strip_control_codes
  15. from rich.markup import escape as escape
  16. from rich.padding import Padding as Padding
  17. from rich.segment import Segment as Segment
  18. from rich.style import StyleType as StyleType
  19. from rich.text import Span as Span
  20. from rich.text import Text as Text
  21. from rich.theme import Theme as Theme
  22. __all__ = [
  23. "re_ansi",
  24. "Console",
  25. "ConsoleOptions",
  26. "RenderableType",
  27. "RenderResult",
  28. "Lines",
  29. "strip_control_codes",
  30. "escape",
  31. "Padding",
  32. "Segment",
  33. "StyleType",
  34. "Span",
  35. "Text",
  36. "Theme",
  37. ]
  38. def __getattr__(name: str) -> Any:
  39. if name not in __all__:
  40. raise AttributeError(name)
  41. import rich.ansi
  42. import rich.console
  43. import rich.containers
  44. import rich.control
  45. import rich.markup
  46. import rich.padding
  47. import rich.segment
  48. import rich.style
  49. import rich.text
  50. import rich.theme
  51. globals().update(
  52. {
  53. "re_ansi": rich.ansi.re_ansi,
  54. "Console": rich.console.Console,
  55. "ConsoleOptions": rich.console.ConsoleOptions,
  56. "RenderableType": rich.console.RenderableType,
  57. "RenderResult": rich.console.RenderResult,
  58. "Lines": rich.containers.Lines,
  59. "strip_control_codes": rich.control.strip_control_codes,
  60. "escape": rich.markup.escape,
  61. "Padding": rich.padding.Padding,
  62. "Segment": rich.segment.Segment,
  63. "StyleType": rich.style.StyleType,
  64. "Span": rich.text.Span,
  65. "Text": rich.text.Text,
  66. "Theme": rich.theme.Theme,
  67. }
  68. )
  69. return globals()[name]