Skip to content

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

Python
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.

ATTRIBUTEDESCRIPTION
id

Unique section identifier

TYPE:str

title

Section title

TYPE:str

level

Heading level (1-6)

TYPE:int

order

Display order

TYPE:int

icon

Optional icon/emoji

TYPE:Optional[str]

content

Section text content

TYPE:Optional[Union[str, List[str], Dict[str, Any]]]

metrics

Key metrics dictionary

TYPE:Dict[str, Any]

tables

List of table data

TYPE:List[Dict[str, Any]]

charts

List of chart configurations

TYPE:List[Dict[str, Any]]

code_snippets

List of code examples

TYPE:List[Dict[str, Any]]

subsections

Nested sections

TYPE:List[ReportSection]

visible

Whether section is visible

TYPE:bool

collapsed

Whether section starts collapsed

TYPE:bool

Functions
add_metric
Python
add_metric(name: str, value: Any) -> None

Add a metric to the section.

PARAMETERDESCRIPTION
name

Metric name

TYPE:str

value

Metric value

TYPE:Any

Source code in tenets/core/reporting/generator.py
Python
def add_metric(self, name: str, value: Any) -> None:
    """Add a metric to the section.

    Args:
        name: Metric name
        value: Metric value
    """
    self.metrics[name] = value
add_table
Python
add_table(table_data: Dict[str, Any]) -> None

Add a table to the section.

PARAMETERDESCRIPTION
table_data

Table configuration with headers and rows

TYPE:Dict[str, Any]

Source code in tenets/core/reporting/generator.py
Python
def add_table(self, table_data: Dict[str, Any]) -> None:
    """Add a table to the section.

    Args:
        table_data: Table configuration with headers and rows
    """
    self.tables.append(table_data)
add_chart
Python
add_chart(chart_config: Dict[str, Any]) -> None

Add a chart to the section.

PARAMETERDESCRIPTION
chart_config

Chart configuration from viz modules

TYPE:Dict[str, Any]

Source code in tenets/core/reporting/generator.py
Python
def add_chart(self, chart_config: Dict[str, Any]) -> None:
    """Add a chart to the section.

    Args:
        chart_config: Chart configuration from viz modules
    """
    self.charts.append(chart_config)
add_subsection
Python
add_subsection(subsection: ReportSection) -> None

Add a subsection.

PARAMETERDESCRIPTION
subsection

Nested section

TYPE:ReportSection

Source code in tenets/core/reporting/generator.py
Python
def add_subsection(self, subsection: "ReportSection") -> None:
    """Add a subsection.

    Args:
        subsection: Nested section
    """
    self.subsections.append(subsection)

ReportConfigdataclass

Python
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.

ATTRIBUTEDESCRIPTION
title

Report title

TYPE:str

format

Output format (html, markdown, json)

TYPE:str

include_summary

Include executive summary

TYPE:bool

include_toc

Include table of contents

TYPE:bool

include_charts

Include visualizations

TYPE:bool

include_code_snippets

Include code examples

TYPE:bool

include_recommendations

Include recommendations

TYPE:bool

max_items

Maximum items in lists

TYPE:int

theme

Visual theme (light, dark, auto)

TYPE:str

footer_text

Footer text

TYPE:str

custom_css

Custom CSS for HTML reports

TYPE:Optional[str]

chart_config

Default chart configuration

TYPE:Optional[ChartConfig]

ReportGenerator

Python
ReportGenerator(config: TenetsConfig)

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

ATTRIBUTEDESCRIPTION
config

Configuration object

logger

Logger instance

sections

List of report sections

TYPE:List[ReportSection]

metadata

Report metadata

TYPE:Dict[str, Any]

Initialize report generator.

PARAMETERDESCRIPTION
config

Configuration object

TYPE:TenetsConfig

Source code in tenets/core/reporting/generator.py
Python
def __init__(self, config: TenetsConfig):
    """Initialize report generator.

    Args:
        config: Configuration object
    """
    self.config = config
    self.logger = get_logger(__name__)
    self.sections: List[ReportSection] = []
    self.metadata: Dict[str, Any] = {}
Functions
generate
Python
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.

PARAMETERDESCRIPTION
data

Analysis data from core modules

TYPE:Dict[str, Any]

output_path

Path for output file

TYPE:Path

config

Report configuration

TYPE:Optional[ReportConfig]DEFAULT:None

RETURNSDESCRIPTION
Path

Path to generated report

TYPE:Path

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
Python
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}")

Functions