Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: make TableOfContents not inherit from Section #147

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions edvart/report_sections/table_of_contents.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Table of contents analysis package."""
from typing import Any, Dict, List

import nbformat.v4 as nbfv4
from IPython.display import Markdown, display

from edvart.report_sections.section_base import ReportSection, Section, Verbosity
from edvart.report_sections.section_base import ReportSection, Section


class TableOfContents(Section):
class TableOfContents:
"""Generates the Table of Contents section of the report.

Parameters
Expand All @@ -20,14 +19,10 @@ class TableOfContents(Section):

def __init__(self, include_subsections: bool):
self._include_subsections = include_subsections
super().__init__(verbosity=Verbosity.LOW, columns=None)

def required_imports(self) -> List[str]:
return []

@property
def name(self) -> str:
return "Table of Contents"
def _title(self) -> str:
return "# Table of Contents\n---"

@staticmethod
def _get_section_link(section: Section, section_level: int) -> str:
Expand Down Expand Up @@ -71,7 +66,6 @@ def _add_section_lines(
for subsection in section.subsections:
self._add_section_lines(subsection, section_level + 1, lines, True)

# pylint: disable=arguments-renamed
def add_cells(self, sections: List[Section], cells: List[Dict[str, Any]]) -> None:
"""Adds table of contents cells to the list of cells. The subsections won't be included.

Expand All @@ -82,15 +76,14 @@ def add_cells(self, sections: List[Section], cells: List[Dict[str, Any]]) -> Non
cells : List[Dict[str, Any]]
List of generated notebook cells which are represented as dictionaries.
"""
section_header = nbfv4.new_markdown_cell(self.get_title(section_level=1))
section_header = nbfv4.new_markdown_cell(self._title)
cells.append(section_header)

lines: List[str] = []
for section in sections:
lines.append(TableOfContents._get_section_link(section, 1))
cells.append(nbfv4.new_markdown_cell("\n".join(lines)))

# pylint: disable=arguments-renamed
def show(self, sections: List[Section]) -> None:
"""Generates table of contents' cell output in the calling notebook.

Expand All @@ -99,7 +92,7 @@ def show(self, sections: List[Section]) -> None:
sections: List[Section]
List of sections that should be included in the table of contents.
"""
display(Markdown(self.get_title(section_level=1)))
display(Markdown(self._title))

lines = []
for section in sections:
Expand Down