Skip to content

Commit

Permalink
Enhance TemplateManager initialization: improve template_root handlin…
Browse files Browse the repository at this point in the history
…g with type validation and default path fallback
  • Loading branch information
Your Name committed May 12, 2025
1 parent 1322ac5 commit 228e86b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions template_automation/template_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,24 @@ def __init__(self, template_root: Optional[str] = None, template_repo_name: Opti
'templates' directory in the same location as this file.
template_repo_name (str, optional): The name of the template repository.
"""
if template_root is None:
template_root = os.path.join(os.path.dirname(__file__), "templates")
default_template_path = os.path.join(os.path.dirname(__file__), "templates")

effective_template_root: str
if isinstance(template_root, str):
effective_template_root = template_root
elif template_root is None:
effective_template_root = default_template_path
else:
# template_root is not a string and not None (e.g., a tuple was passed)
print(
f"Warning: TemplateManager's template_root argument expected str or None, "
f"but received type {type(template_root)}. Using default template path: "
f"'{default_template_path}'"
)
effective_template_root = default_template_path

self.env = Environment(
loader=FileSystemLoader(template_root),
loader=FileSystemLoader(effective_template_root),
trim_blocks=True,
lstrip_blocks=True
)
Expand Down

0 comments on commit 228e86b

Please sign in to comment.