generator
¶
Full name: tenets.core.reporting.generator
generator¶
Report generation module.
This module orchestrates report generation by combining analysis data with visualizations from the viz package. It creates structured reports in various formats without duplicating visualization logic.
Classes¶
ReportSectiondataclass
¶
ReportSection(id: str, title: str, level: int = 1, order: int = 0, icon: Optional[str] = None, content: Optional[Union[str, List[str], Dict[str, Any]]] = None, metrics: Dict[str, Any] = dict(), tables: List[Dict[str, Any]] = list(), charts: List[Dict[str, Any]] = list(), code_snippets: List[Dict[str, Any]] = list(), subsections: List[ReportSection] = list(), visible: bool = True, collapsed: bool = False, collapsible: bool = False)
Represents a section in the report.
A report section contains structured content including text, metrics, tables, and charts. Sections can be nested to create hierarchical report structures.
ATTRIBUTE | DESCRIPTION |
---|---|
id | Unique section identifier TYPE: |
title | Section title TYPE: |
level | Heading level (1-6) TYPE: |
order | Display order TYPE: |
icon | Optional icon/emoji |
content | Section text content |
metrics | Key metrics dictionary |
tables | List of table data |
charts | List of chart configurations |
code_snippets | List of code examples |
subsections | Nested sections TYPE: |
visible | Whether section is visible TYPE: |
collapsed | Whether section starts collapsed TYPE: |
Functions¶
add_metric¶
add_table¶
Add a table to the section.
PARAMETER | DESCRIPTION |
---|---|
table_data | Table configuration with headers and rows |
add_chart¶
Add a chart to the section.
PARAMETER | DESCRIPTION |
---|---|
chart_config | Chart configuration from viz modules |
add_subsection¶
Add a subsection.
PARAMETER | DESCRIPTION |
---|---|
subsection | Nested section TYPE: |
ReportConfigdataclass
¶
ReportConfig(title: str = 'Code Analysis Report', format: str = 'html', include_summary: bool = True, include_toc: bool = True, include_charts: bool = True, include_code_snippets: bool = True, include_recommendations: bool = True, max_items: int = 20, theme: str = 'light', footer_text: str = 'Generated by Tenets Code Analysis', custom_css: Optional[str] = None, chart_config: Optional[ChartConfig] = None, custom_logo: Optional[Path] = None)
Configuration for report generation.
Controls report generation options including format, content inclusion, and visualization settings.
ATTRIBUTE | DESCRIPTION |
---|---|
title | Report title TYPE: |
format | Output format (html, markdown, json) TYPE: |
include_summary | Include executive summary TYPE: |
include_toc | Include table of contents TYPE: |
include_charts | Include visualizations TYPE: |
include_code_snippets | Include code examples TYPE: |
include_recommendations | Include recommendations TYPE: |
max_items | Maximum items in lists TYPE: |
theme | Visual theme (light, dark, auto) TYPE: |
footer_text | Footer text TYPE: |
custom_css | Custom CSS for HTML reports |
chart_config | Default chart configuration TYPE: |
ReportGenerator¶
Main report generator orchestrator.
Coordinates report generation by combining analysis data with visualizations from the viz package. Creates structured reports without duplicating visualization logic.
The generator follows a clear separation of concerns: - Core modules provide analysis data - Viz modules create visualizations - Generator orchestrates and structures the report
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
sections | List of report sections TYPE: |
metadata | Report metadata |
Initialize report generator.
PARAMETER | DESCRIPTION |
---|---|
config | Configuration object TYPE: |
Source code in tenets/core/reporting/generator.py
Functions¶
generate¶
generate(data: Dict[str, Any], output_path: Path, config: Optional[ReportConfig] = None) -> Path
Generate a report from analysis data.
This is the main entry point for report generation. It takes analysis data, creates appropriate visualizations using viz modules, and outputs a formatted report.
PARAMETER | DESCRIPTION |
---|---|
data | Analysis data from core modules |
output_path | Path for output file TYPE: |
config | Report configuration TYPE: |
RETURNS | DESCRIPTION |
---|---|
Path | Path to generated report TYPE: |
Example
generator = ReportGenerator(config) report_path = generator.generate( ... analysis_data, ... Path("report.html"), ... ReportConfig(include_charts=True) ... )
Source code in tenets/core/reporting/generator.py
def generate(
self, data: Dict[str, Any], output_path: Path, config: Optional[ReportConfig] = None
) -> Path:
"""Generate a report from analysis data.
This is the main entry point for report generation. It takes
analysis data, creates appropriate visualizations using viz
modules, and outputs a formatted report.
Args:
data: Analysis data from core modules
output_path: Path for output file
config: Report configuration
Returns:
Path: Path to generated report
Example:
>>> generator = ReportGenerator(config)
>>> report_path = generator.generate(
... analysis_data,
... Path("report.html"),
... ReportConfig(include_charts=True)
... )
"""
if config is None:
config = ReportConfig()
self.logger.info(f"Generating {config.format} report: {output_path}")
# Clear previous sections
self.sections = []
# Build metadata
self.metadata = self._build_metadata(data, config)
# Create report sections using viz modules
if config.include_summary:
self.sections.append(self._create_summary_section(data))
# Add file overview section
if "metrics" in data:
self.sections.append(self._create_file_overview_section(data, config))
# Add excluded files section if available
if data.get("excluded_files") or data.get("ignored_patterns"):
self.sections.append(self._create_excluded_files_section(data, config))
# Add README section if available
readme_info = self._find_readme(data)
if readme_info:
self.sections.append(self._create_readme_section(readme_info))
# Add analysis sections based on available data
# Add defensive checks to prevent NoneType errors
if "complexity" in data and data["complexity"] is not None:
self.sections.append(self._create_complexity_section(data["complexity"], config))
if "contributors" in data and data["contributors"] is not None:
self.sections.append(self._create_contributors_section(data["contributors"], config))
if "hotspots" in data and data["hotspots"] is not None:
self.sections.append(self._create_hotspots_section(data["hotspots"], config))
if "dependencies" in data and data["dependencies"] is not None:
self.sections.append(self._create_dependencies_section(data["dependencies"], config))
if "coupling" in data and data["coupling"] is not None:
self.sections.append(self._create_coupling_section(data["coupling"], config))
if "momentum" in data and data["momentum"] is not None:
self.sections.append(self._create_momentum_section(data["momentum"], config))
if config.include_recommendations:
self.sections.append(self._create_recommendations_section(data))
# Generate output based on format
if config.format == "html":
from .html_reporter import HTMLReporter
reporter = HTMLReporter(self.config)
return reporter.generate(self.sections, self.metadata, output_path, config)
elif config.format == "markdown":
from .markdown_reporter import MarkdownReporter
reporter = MarkdownReporter(self.config)
return reporter.generate(self.sections, self.metadata, output_path, config)
elif config.format == "json":
return self._generate_json_report(output_path)
else:
raise ValueError(f"Unsupported report format: {config.format}")