Skip to content

Commit 656c21e

Browse files
committed
Pylint touches.
1 parent 59bf373 commit 656c21e

File tree

3 files changed

+80
-59
lines changed

3 files changed

+80
-59
lines changed

living_documentation_generator/generator.py

Lines changed: 54 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from living_documentation_generator.model.project_issue import ProjectIssue
3636
from living_documentation_generator.utils.decorators import safe_call_decorator
3737
from living_documentation_generator.utils.github_rate_limiter import GithubRateLimiter
38-
from living_documentation_generator.utils.utils import make_issue_key, generate_root_level_index_page
38+
from living_documentation_generator.utils.utils import make_issue_key, generate_root_level_index_page, load_template
3939
from living_documentation_generator.utils.constants import (
4040
ISSUES_PER_PAGE_LIMIT,
4141
ISSUE_STATE_ALL,
@@ -294,57 +294,16 @@ def _generate_markdown_pages(self, issues: dict[str, ConsolidatedIssue]) -> None
294294
is_structured_output = ActionInputs.get_is_structured_output_enabled()
295295
is_grouping_by_topics = ActionInputs.get_is_grouping_by_topics_enabled()
296296
output_path = ActionInputs.get_output_directory()
297-
issue_page_detail_template = None
298-
index_page_template = None
299-
index_root_level_page = None
300-
index_org_level_template = None
301-
index_repo_page_template = None
302-
index_data_level_template = None
303297

304298
# Load the template files for generating the Markdown pages
305-
try:
306-
with open(LivingDocumentationGenerator.ISSUE_PAGE_TEMPLATE_FILE, "r", encoding="utf-8") as f:
307-
issue_page_detail_template = f.read()
308-
except IOError:
309-
logger.error("Issue page template file was not successfully loaded.", exc_info=True)
310-
311-
try:
312-
with open(LivingDocumentationGenerator.INDEX_NO_STRUCT_TEMPLATE_FILE, "r", encoding="utf-8") as f:
313-
index_page_template = f.read()
314-
except IOError:
315-
logger.error("Index page template file was not successfully loaded.", exc_info=True)
316-
317-
try:
318-
with open(LivingDocumentationGenerator.INDEX_ROOT_LEVEL_TEMPLATE_FILE, "r", encoding="utf-8") as f:
319-
index_root_level_page = f.read()
320-
except IOError:
321-
logger.error(
322-
"Structured index page template file for root level was not successfully loaded.", exc_info=True
323-
)
324-
325-
try:
326-
with open(LivingDocumentationGenerator.INDEX_ORG_LEVEL_TEMPLATE_FILE, "r", encoding="utf-8") as f:
327-
index_org_level_template = f.read()
328-
except IOError:
329-
logger.error(
330-
"Structured index page template file for organization level was not successfully loaded.", exc_info=True
331-
)
332-
333-
try:
334-
with open(LivingDocumentationGenerator.INDEX_TOPIC_PAGE_TEMPLATE_FILE, "r", encoding="utf-8") as f:
335-
index_repo_page_template = f.read()
336-
except IOError:
337-
logger.error(
338-
"Structured index page template file for repository level was not successfully loaded.", exc_info=True
339-
)
340-
341-
try:
342-
with open(LivingDocumentationGenerator.INDEX_DATA_LEVEL_TEMPLATE_FILE, "r", encoding="utf-8") as f:
343-
index_data_level_template = f.read()
344-
except IOError:
345-
logger.error(
346-
"Structured index page template file for data level was not successfully loaded.", exc_info=True
347-
)
299+
(
300+
issue_page_detail_template,
301+
index_page_template,
302+
index_root_level_page,
303+
index_org_level_template,
304+
index_repo_page_template,
305+
index_data_level_template,
306+
) = self._load_all_templates()
348307

349308
# Generate a markdown page for every issue
350309
for consolidated_issue in issues.values():
@@ -361,7 +320,7 @@ def _generate_markdown_pages(self, issues: dict[str, ConsolidatedIssue]) -> None
361320
# Generate an index page with a summary table about all issues grouped by topics
362321
elif is_grouping_by_topics:
363322
issues = list(issues.values())
364-
topics = set([issue.topic for issue in issues])
323+
topics = {issue.topic for issue in issues}
365324
generate_root_level_index_page(index_root_level_page, output_path)
366325

367326
for topic in topics:
@@ -447,14 +406,15 @@ def _generate_structured_index_pages(
447406
organization_name,
448407
)
449408

409+
# Generate an index pages for the documentation based on the grouped issues by topics
450410
if ActionInputs.get_is_grouping_by_topics_enabled():
451411
self._generate_sub_level_index_page(index_repo_level_template, "repo", repository_id)
452412
logger.debug(
453413
"Generated repository level _index.md` for repository: %s.",
454414
repository_name,
455415
)
456416

457-
topics = set([issue.topic for issue in issues])
417+
topics = {issue.topic for issue in issues}
458418
for topic in topics:
459419
self._generate_index_page(index_data_level_template, issues, repository_id, topic)
460420
logger.debug(
@@ -465,7 +425,7 @@ def _generate_structured_index_pages(
465425
else:
466426
self._generate_index_page(index_data_level_template, issues, repository_id)
467427
logger.debug(
468-
"Generated repository level `_index.md` for %s",
428+
"Generated data level `_index.md` for %s",
469429
repository_id,
470430
)
471431

@@ -700,3 +660,44 @@ def _generate_index_directory_path(repository_id: Optional[str], topic: Optional
700660
os.makedirs(output_path, exist_ok=True)
701661

702662
return output_path
663+
664+
@staticmethod
665+
def _load_all_templates() -> tuple[str, ...]:
666+
"""
667+
Load all template files for generating the Markdown pages.
668+
669+
@return: A tuple containing all loaded template files.
670+
"""
671+
issue_page_detail_template = load_template(
672+
LivingDocumentationGenerator.ISSUE_PAGE_TEMPLATE_FILE,
673+
"Issue page template file was not successfully loaded.",
674+
)
675+
index_page_template = load_template(
676+
LivingDocumentationGenerator.INDEX_NO_STRUCT_TEMPLATE_FILE,
677+
"Index page template file was not successfully loaded.",
678+
)
679+
index_root_level_page = load_template(
680+
LivingDocumentationGenerator.INDEX_ROOT_LEVEL_TEMPLATE_FILE,
681+
"Structured index page template file for root level was not successfully loaded.",
682+
)
683+
index_org_level_template = load_template(
684+
LivingDocumentationGenerator.INDEX_ORG_LEVEL_TEMPLATE_FILE,
685+
"Structured index page template file for organization level was not successfully loaded.",
686+
)
687+
index_repo_page_template = load_template(
688+
LivingDocumentationGenerator.INDEX_TOPIC_PAGE_TEMPLATE_FILE,
689+
"Structured index page template file for repository level was not successfully loaded.",
690+
)
691+
index_data_level_template = load_template(
692+
LivingDocumentationGenerator.INDEX_DATA_LEVEL_TEMPLATE_FILE,
693+
"Structured index page template file for data level was not successfully loaded.",
694+
)
695+
696+
return (
697+
issue_page_detail_template,
698+
index_page_template,
699+
index_root_level_page,
700+
index_org_level_template,
701+
index_repo_page_template,
702+
index_data_level_template,
703+
)

living_documentation_generator/model/consolidated_issue.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ def __init__(self, repository_id: str, repository_issue: Issue = None):
4242
# save issue from repository (got from GitHub library & keep connection to repository for lazy loading)
4343
# Warning: several issue properties requires additional API calls - use wisely to keep low API usage
4444
self.__issue: Issue = repository_issue
45-
4645
self.__repository_id: str = repository_id
47-
parts = repository_id.split("/")
48-
self.__organization_name: str = parts[0] if len(parts) == 2 else ""
49-
self.__repository_name: str = parts[1] if len(parts) == 2 else ""
5046
self.__topic: str = ""
5147

5248
# Extra project data (optionally provided from GithubProjects class)
@@ -69,12 +65,14 @@ def repository_id(self) -> str:
6965
@property
7066
def organization_name(self) -> str:
7167
"""Getter of the organization where the issue was fetched from."""
72-
return self.__organization_name
68+
parts = self.__repository_id.split("/")
69+
return parts[0] if len(parts) == 2 else ""
7370

7471
@property
7572
def repository_name(self) -> str:
7673
"""Getter of the repository name where the issue was fetched from."""
77-
return self.__repository_name
74+
parts = self.__repository_id.split("/")
75+
return parts[1] if len(parts) == 2 else ""
7876

7977
@property
8078
def topic(self) -> str:
@@ -172,6 +170,12 @@ def generate_page_filename(self) -> str:
172170
return page_filename
173171

174172
def generate_directory_path(self, issue_table: str) -> str:
173+
"""
174+
Generate a directory path based on enabled features.
175+
176+
@param issue_table: The consolidated issue summary table.
177+
@return: The generated directory path.
178+
"""
175179
output_path = ActionInputs.get_output_directory()
176180

177181
# If structured output is enabled, create a directory path based on the repository

living_documentation_generator/utils/utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,22 @@ def generate_root_level_index_page(index_root_level_page: str, output_path: str)
113113
f.write(index_root_level_page)
114114

115115

116+
def load_template(file_path: str, error_message: str) -> Optional[str]:
117+
"""
118+
Load the content of the template file.
119+
120+
@param file_path: The path to the template file.
121+
@param error_message: The error message to log if the file cannot be read.
122+
@return: The content of the template file or None if the file cannot be read.
123+
"""
124+
try:
125+
with open(file_path, "r", encoding="utf-8") as f:
126+
return f.read()
127+
except IOError:
128+
logger.error(error_message, exc_info=True)
129+
return None
130+
131+
116132
# GitHub action utils
117133
def get_action_input(name: str, default: Optional[str] = None) -> str:
118134
"""

0 commit comments

Comments
 (0)