Coverage for src / ezxl / cli / commands / _info.py: 78.46%

59 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-10-17 10:25 +0000

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

2# EZXL - CLI Info Command 

3# Project: ezxl 

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

5 

6""" 

7CLI command for displaying package information. 

8 

9This module provides the info command for EzXl. 

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 ezxl 

29 

30from .._console import console 

31 

32# /////////////////////////////////////////////////////////////// 

33# COMMANDS 

34# /////////////////////////////////////////////////////////////// 

35 

36 

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

38def info_command() -> None: 

39 """ 

40 Display package information. 

41 

42 Show detailed information about the EzXl package including 

43 version, location, and dependencies. 

44 """ 

45 try: 

46 # Package info 

47 ezxl_version = getattr(ezxl, "__version__", "unknown") 

48 author = getattr(ezxl, "__author__", "unknown") 

49 maintainer = getattr(ezxl, "__maintainer__", "unknown") 

50 description = getattr(ezxl, "__description__", "unknown") 

51 url = getattr(ezxl, "__url__", "unknown") 

52 

53 # Package location 

54 try: 

55 package_path = ( 

56 Path(ezxl.__file__).parent if hasattr(ezxl, "__file__") else None 

57 ) 

58 except (AttributeError, TypeError, OSError): 

59 package_path = None 

60 

61 # Build info text 

62 text = Text() 

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

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

65 

66 # Version 

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

68 text.append(f"{ezxl_version}\n", style="white") 

69 

70 # Author 

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

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

73 

74 if maintainer != author: 74 ↛ 75line 74 didn't jump to line 75 because the condition on line 74 was never true

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

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

77 

78 # Description 

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

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

81 

82 # URL 

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

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

85 

86 # Package location 

87 if package_path: 87 ↛ 92line 87 didn't jump to line 92 because the condition on line 87 was always true

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

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

90 

91 # Display panel 

92 panel = Panel( 

93 text, 

94 title="[bold bright_blue]EzXl Information[/bold bright_blue]", 

95 border_style="bright_blue", 

96 padding=(1, 2), 

97 ) 

98 console.print(panel) 

99 

100 # Dependencies table 

101 try: 

102 _dep_names = [ 

103 "polars", 

104 "openpyxl", 

105 "xlsxwriter", 

106 "fastexcel", 

107 "rich", 

108 "click", 

109 ] 

110 

111 deps_table = Table( 

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

113 ) 

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

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

116 

117 for dep in _dep_names: 

118 try: 

119 dep_version = version(dep) 

120 except PackageNotFoundError: 

121 dep_version = "unknown" 

122 deps_table.add_row(dep, dep_version) 

123 

124 console.print("\n") 

125 console.print(deps_table) 

126 except (OSError, RuntimeError, ValueError) as e: 

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

128 

129 except click.ClickException: 

130 raise 

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

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