From 228e86b00fc28e22d2386f4bd34867f84da28834 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 12 May 2025 17:12:37 -0400 Subject: [PATCH] Enhance TemplateManager initialization: improve template_root handling with type validation and default path fallback --- template_automation/template_manager.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/template_automation/template_manager.py b/template_automation/template_manager.py index 8951790..eea8986 100644 --- a/template_automation/template_manager.py +++ b/template_automation/template_manager.py @@ -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 )