fix: resolve CI linting and type checking errors
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
"""Template engine for ScaffoldForge."""
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
from typing import Any, Optional
|
||||
|
||||
from jinja2 import (
|
||||
BaseLoader,
|
||||
Environment,
|
||||
FileSystemLoader,
|
||||
PackageLoader,
|
||||
@@ -27,12 +25,12 @@ class TemplateEngine:
|
||||
"""
|
||||
self.template_dir = template_dir
|
||||
self.env = self._create_environment()
|
||||
self._loaded_templates: Dict[str, Dict[str, Any]] = {}
|
||||
self._loaded_templates: dict[str, dict[str, str]] = {}
|
||||
|
||||
def _create_environment(self) -> Environment:
|
||||
"""Create Jinja2 environment with appropriate loader."""
|
||||
if self.template_dir and Path(self.template_dir).exists():
|
||||
loader = FileSystemLoader(self.template_dir)
|
||||
loader: FileSystemLoader | PackageLoader = FileSystemLoader(self.template_dir)
|
||||
else:
|
||||
loader = PackageLoader("scaffoldforge", "templates")
|
||||
|
||||
@@ -45,7 +43,7 @@ class TemplateEngine:
|
||||
|
||||
def load_templates(
|
||||
self, language: str, template_name: str = "default"
|
||||
) -> Dict[str, str]:
|
||||
) -> dict[str, str]:
|
||||
"""Load templates for a specific language and template type.
|
||||
|
||||
Args:
|
||||
@@ -59,7 +57,7 @@ class TemplateEngine:
|
||||
if key in self._loaded_templates:
|
||||
return self._loaded_templates[key]
|
||||
|
||||
templates = {}
|
||||
templates: dict[str, str] = {}
|
||||
template_dir = Path(__file__) / language / template_name
|
||||
|
||||
if template_dir.exists():
|
||||
@@ -88,14 +86,14 @@ class TemplateEngine:
|
||||
template_path = f"{language}/{template_type}/{filename}"
|
||||
try:
|
||||
template = self.env.get_template(template_path)
|
||||
return template.filename
|
||||
return template.filename or ""
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
def render(
|
||||
self,
|
||||
template_name: str,
|
||||
context: Dict[str, Any],
|
||||
context: dict[str, Any],
|
||||
language: str = "python",
|
||||
) -> str:
|
||||
"""Render a template with the given context.
|
||||
@@ -117,7 +115,7 @@ class TemplateEngine:
|
||||
except Exception as e:
|
||||
raise ValueError(f"Failed to render template {template_name}: {e}")
|
||||
|
||||
def render_string(self, template_content: str, context: Dict[str, Any]) -> str:
|
||||
def render_string(self, template_content: str, context: dict[str, Any]) -> str:
|
||||
"""Render a template string directly.
|
||||
|
||||
Args:
|
||||
@@ -131,7 +129,7 @@ class TemplateEngine:
|
||||
return template.render(**context)
|
||||
|
||||
@staticmethod
|
||||
def list_available_templates(language: str) -> List[str]:
|
||||
def list_available_templates(language: str) -> list[str]:
|
||||
"""List available templates for a language.
|
||||
|
||||
Args:
|
||||
@@ -144,14 +142,14 @@ class TemplateEngine:
|
||||
if not templates_dir.exists():
|
||||
return []
|
||||
|
||||
templates = []
|
||||
templates: list[str] = []
|
||||
for item in templates_dir.iterdir():
|
||||
if item.is_dir():
|
||||
templates.append(item.name)
|
||||
return sorted(templates)
|
||||
|
||||
@staticmethod
|
||||
def list_available_languages() -> List[str]:
|
||||
def list_available_languages() -> list[str]:
|
||||
"""List all available programming languages.
|
||||
|
||||
Returns:
|
||||
@@ -161,13 +159,13 @@ class TemplateEngine:
|
||||
if not templates_dir.exists():
|
||||
return []
|
||||
|
||||
languages = []
|
||||
languages: list[str] = []
|
||||
for item in templates_dir.iterdir():
|
||||
if item.is_dir() and not item.name.startswith("_"):
|
||||
languages.append(item.name)
|
||||
return sorted(languages)
|
||||
|
||||
def get_template_context(self, issue_data: IssueData) -> Dict[str, Any]:
|
||||
def get_template_context(self, issue_data: IssueData) -> dict[str, Any]:
|
||||
"""Generate template context from issue data.
|
||||
|
||||
Args:
|
||||
|
||||
Reference in New Issue
Block a user