@@ -49,13 +49,20 @@ class TemplateInspector:
4949 Uses context manager protocol for proper resource cleanup.
5050 """
5151
52- def __init__ (self , template_path : str ):
52+ def __init__ (self , template_path : str , temp_base_dir : Optional [ str ] = None ):
5353 self .template_path = Path (template_path )
5454 self .errors : List [str ] = []
5555 self .warnings : List [str ] = []
56- # Create unique temp directory for each template to avoid conflicts
5756 template_name = Path (template_path ).name
58- self .temp_dir = os .path .join (os .path .dirname (__file__ ), f"temp_{ template_name } " )
57+
58+ # use temp_base_dir or fall back to backend directory (temp)
59+ if temp_base_dir :
60+ self .temp_dir = os .path .join (temp_base_dir , f"temp_{ template_name } " )
61+ else :
62+ self .temp_dir = os .path .join (
63+ os .path .dirname (__file__ ), f"temp_{ template_name } "
64+ )
65+
5966 self ._cleanup_needed = False
6067 self .template_config : Optional [Dict [str , Any ]] = None
6168
@@ -1234,19 +1241,22 @@ def get_report(self) -> Dict[str, Any]:
12341241 }
12351242
12361243
1237- def inspect_fastapi_template (template_path : str ) -> Dict [str , Any ]:
1244+ def inspect_fastapi_template (
1245+ template_path : str , temp_base_dir : Optional [str ] = None
1246+ ) -> Dict [str , Any ]:
12381247 """
12391248 Convenience function to inspect a FastAPI template.
12401249
12411250 :param template_path: Path to the template to inspect
1251+ :param temp_base_dir: Base directory for temporary files (defaults to backend directory)
12421252 :return: Inspection report dictionary
12431253 """
12441254 template_name = Path (template_path ).name
12451255 debug_log (
12461256 f"Starting template inspection for { template_name } at { template_path } " , "info"
12471257 )
12481258
1249- with TemplateInspector (template_path ) as inspector :
1259+ with TemplateInspector (template_path , temp_base_dir ) as inspector :
12501260 is_valid = inspector .inspect_template ()
12511261 report = inspector .get_report ()
12521262
0 commit comments