Coverage for src / ezqt_widgets / cli / commands / _info.py: 0.00%

73 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-01 22:46 +0000

1# /////////////////////////////////////////////////////////////// 

2# EZQT_WIDGETS - CLI Info Command 

3# Project: ezqt_widgets 

4# /////////////////////////////////////////////////////////////// 

5 

6""" 

7CLI command for displaying package information. 

8 

9This module provides the info command for EzQt-Widgets. 

10""" 

11 

12from __future__ import annotations 

13 

14# /////////////////////////////////////////////////////////////// 

15# IMPORTS 

16# /////////////////////////////////////////////////////////////// 

17# Standard library imports 

18from importlib.metadata import PackageNotFoundError, version 

19from pathlib import Path 

20 

21# Third-party imports 

22import click 

23from rich.panel import Panel 

24from rich.table import Table 

25from rich.text import Text 

26 

27# Local imports 

28import ezqt_widgets 

29 

30from .._console import console 

31from ._demo import ExampleRunner 

32 

33# /////////////////////////////////////////////////////////////// 

34# COMMANDS 

35# /////////////////////////////////////////////////////////////// 

36 

37 

38@click.command(name="info", help="Display package information") 

39def info_command() -> None: 

40 """ 

41 Display package information. 

42 

43 Show detailed information about the EzQt-Widgets package including 

44 version, location, and dependencies. 

45 """ 

46 try: 

47 # Package info 

48 pkg_version = getattr(ezqt_widgets, "__version__", "unknown") 

49 author = getattr(ezqt_widgets, "__author__", "unknown") 

50 maintainer = getattr(ezqt_widgets, "__maintainer__", "unknown") 

51 description = getattr(ezqt_widgets, "__description__", "unknown") 

52 url = getattr(ezqt_widgets, "__url__", "unknown") 

53 

54 try: 

55 package_path = ( 

56 Path(ezqt_widgets.__file__).parent 

57 if hasattr(ezqt_widgets, "__file__") 

58 else None 

59 ) 

60 except (AttributeError, TypeError, OSError): 

61 package_path = None 

62 try: 

63 runner = ExampleRunner() 

64 examples = runner.get_available_examples() 

65 example_count = len(examples) 

66 except FileNotFoundError: 

67 example_count = None 

68 

69 # Build info text 

70 text = Text() 

71 text.append("Package Information\n", style="bold bright_blue") 

72 text.append("=" * 50 + "\n\n", style="dim") 

73 

74 # Version 

75 text.append("Version: ", style="bold") 

76 text.append(f"{pkg_version}\n", style="white") 

77 

78 # Author 

79 text.append("Author: ", style="bold") 

80 text.append(f"{author}\n", style="white") 

81 

82 if maintainer != author: 

83 text.append("Maintainer: ", style="bold") 

84 text.append(f"{maintainer}\n", style="white") 

85 

86 # Description 

87 text.append("\nDescription:\n", style="bold") 

88 text.append(f" {description}\n", style="dim white") 

89 

90 # URL 

91 text.append("\nURL: ", style="bold") 

92 text.append(f"{url}\n", style="cyan") 

93 

94 # Package location 

95 if package_path: 

96 text.append("\nPackage Location: ", style="bold") 

97 text.append(f"{package_path}\n", style="dim white") 

98 

99 # Examples 

100 if example_count is not None: 

101 text.append("\nExamples: ", style="bold") 

102 text.append(f"{example_count} found\n", style="white") 

103 else: 

104 text.append("\nExamples: ", style="bold") 

105 text.append("Not found\n", style="white") 

106 

107 # Display panel 

108 panel = Panel( 

109 text, 

110 title="[bold bright_blue]EzQt-Widgets Information[/bold bright_blue]", 

111 border_style="bright_blue", 

112 padding=(1, 2), 

113 ) 

114 console.print(panel) 

115 

116 # Dependencies table 

117 try: 

118 import PySide6 

119 import rich 

120 

121 try: 

122 click_version = version("click") 

123 except PackageNotFoundError: 

124 click_version = "unknown" 

125 

126 deps_table = Table( 

127 title="Dependencies", show_header=True, header_style="bold blue" 

128 ) 

129 deps_table.add_column("Package", style="cyan") 

130 deps_table.add_column("Version", style="green") 

131 

132 deps_table.add_row("PySide6", getattr(PySide6, "__version__", "unknown")) 

133 deps_table.add_row("rich", getattr(rich, "__version__", "unknown")) 

134 deps_table.add_row("click", click_version) 

135 

136 console.print("\n") 

137 console.print(deps_table) 

138 except (ImportError, OSError, RuntimeError, ValueError) as e: 

139 console.print(f"[bold red]Error:[/bold red] {e}") 

140 

141 except click.ClickException: 

142 raise 

143 except (OSError, RuntimeError, ValueError, TypeError, AttributeError) as e: 

144 raise click.ClickException(str(e)) from e