Coverage for sphinx_reports/Dependency.py: 56%

45 statements  

« prev     ^ index     » next       coverage.py v7.11.1, created at 2025-11-07 22:13 +0000

1# ==================================================================================================================== # 

2# _ _ _ # 

3# ___ _ __ | |__ (_)_ __ __ __ _ __ ___ _ __ ___ _ __| |_ ___ # 

4# / __| '_ \| '_ \| | '_ \\ \/ /____| '__/ _ \ '_ \ / _ \| '__| __/ __| # 

5# \__ \ |_) | | | | | | | |> <_____| | | __/ |_) | (_) | | | |_\__ \ # 

6# |___/ .__/|_| |_|_|_| |_/_/\_\ |_| \___| .__/ \___/|_| \__|___/ # 

7# |_| |_| # 

8# ==================================================================================================================== # 

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

13# ==================================================================================================================== # 

14# Copyright 2023-2025 Patrick Lehmann - Bötzingen, Germany # 

15# # 

16# Licensed under the Apache License, Version 2.0 (the "License"); # 

17# you may not use this file except in compliance with the License. # 

18# You may obtain a copy of the License at # 

19# # 

20# http://www.apache.org/licenses/LICENSE-2.0 # 

21# # 

22# Unless required by applicable law or agreed to in writing, software # 

23# distributed under the License is distributed on an "AS IS" BASIS, # 

24# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

25# See the License for the specific language governing permissions and # 

26# limitations under the License. # 

27# # 

28# SPDX-License-Identifier: Apache-2.0 # 

29# ==================================================================================================================== # 

30# 

31""" 

32**Report unit test results as Sphinx documentation page(s).** 

33""" 

34from typing import Dict, Tuple, Any, List, Mapping, Generator 

35 

36from docutils import nodes 

37from pyTooling.Decorators import export 

38from sphinx.application import Sphinx 

39from sphinx.config import Config 

40 

41from sphinx_reports.Common import ReportExtensionError 

42from sphinx_reports.Sphinx import stripAndNormalize, BaseDirective 

43from sphinx_reports.DataModel.Dependency import Distribution 

44from sphinx_reports.Adapter.Dependency import DependencyScanner 

45 

46 

47@export 

48class DependencyTable(BaseDirective): 

49 """ 

50 This directive will be replaced by a table representing dependencies. 

51 """ 

52 has_content = False 

53 required_arguments = 0 

54 optional_arguments = 1 

55 

56 option_spec = { 

57 "package": stripAndNormalize 

58 } 

59 

60 directiveName: str = "dependency-table" 

61 configPrefix: str = "dep" 

62 configValues: Dict[str, Tuple[Any, str, Any]] = { 

63 # f"{configPrefix}_testsuites": ({}, "env", Dict) 

64 } #: A dictionary of all configuration values used by unittest directives. 

65 

66 _packageName: str 

67 

68 _distribution: Distribution 

69 

70 def _CheckOptions(self) -> None: 

71 """ 

72 Parse all directive options or use default values. 

73 """ 

74 self._packageName = self._ParseStringOption("package") 

75 

76 @classmethod 

77 def CheckConfiguration(cls, sphinxApplication: Sphinx, sphinxConfiguration: Config) -> None: 

78 """ 

79 Check configuration fields and load necessary values. 

80 

81 :param sphinxApplication: Sphinx application instance. 

82 :param sphinxConfiguration: Sphinx configuration instance. 

83 """ 

84 pass 

85 

86 def _GenerateDependencyTable(self) -> nodes.table: 

87 # Create a table and table header with 8 columns 

88 columns = [ 

89 ("Package", None, 500), 

90 ("Version", None, 100), 

91 ("License", None, 100), 

92 ] 

93 

94 tableGroup = self._CreateDoubleRowTableHeader( 

95 identifier=self._packageName, 

96 columns=columns, 

97 classes=["report-dependency-table"] 

98 ) 

99 tableBody = nodes.tbody() 

100 tableGroup += tableBody 

101 

102 # def sortedValues(d: Mapping[str, Testsuite]) -> Generator[Testsuite, None, None]: 

103 # for key in sorted(d.keys()): 

104 # yield d[key] 

105 

106 def renderRoot(tableBody: nodes.tbody, distribution: Distribution) -> None: 

107 tableRow = nodes.row("", classes=["report-dependency-table-row", "report-dependency"]) 

108 tableBody += tableRow 

109 

110 tableRow += nodes.entry("", nodes.Text(f"{distribution.Name}")) 

111 tableRow += nodes.entry("", nodes.Text(f"{distribution.Version}")) 

112 tableRow += nodes.entry("", nodes.Text(f"{distribution.Licenses}")) 

113 

114 # for ts in sortedValues(testsuite._testsuites): 

115 # renderTestsuite(tableBody, ts, 0) 

116 

117 renderRoot(tableBody, self._distribution) 

118 

119 # # Add a summary row 

120 

121 return tableGroup.parent 

122 

123 def run(self) -> List[nodes.Node]: 

124 self._CheckOptions() 

125 

126 # Assemble a list of Python source files 

127 scanner = DependencyScanner(self._packageName) 

128 self._distribution = scanner.Distribution 

129 

130 container = nodes.container() 

131 container += self._GenerateDependencyTable() 

132 

133 return [container]