fix: resolve CI test failures by simplifying workflow and fixing template loading
Some checks failed
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-02-02 16:53:04 +00:00
parent 78fdba252f
commit 28531e11f1

View File

@@ -1,7 +1,6 @@
"""Template loader for gitignore-generator."""
import json
import os
from pathlib import Path
from typing import Dict, List, Optional, Set
@@ -16,22 +15,10 @@ class TemplateLoader:
self._templates_index: Optional[Dict] = None
self._custom_templates: Dict[str, str] = {}
def _get_templates_dir(self) -> Path:
"""Get the templates directory, handling both source and installed modes."""
templates_dir = config.template_dir
if templates_dir.exists() and (templates_dir / "templates.json").exists():
return templates_dir
module_dir = Path(__file__).parent
package_templates = module_dir / "templates"
if package_templates.exists() and (package_templates / "templates.json").exists():
return package_templates
return templates_dir
def _load_templates_index(self) -> Dict:
"""Load the templates index file."""
if self._templates_index is None:
templates_dir = self._get_templates_dir()
index_path = templates_dir / "templates.json"
index_path = config.template_dir / "templates.json"
if index_path.exists():
with open(index_path, "r") as f:
self._templates_index = json.load(f)
@@ -42,8 +29,7 @@ class TemplateLoader:
def _save_templates_index(self) -> None:
"""Save the templates index file."""
templates_dir = self._get_templates_dir()
index_path = templates_dir / "templates.json"
index_path = config.template_dir / "templates.json"
with open(index_path, "w") as f:
json.dump(self._templates_index, f, indent=2)
@@ -86,14 +72,6 @@ class TemplateLoader:
for template_file in custom_dir.glob("*.gitignore"):
self._custom_templates[template_file.stem] = str(template_file)
def _get_template_path(self, template_name: str, category: str) -> Optional[Path]:
"""Get the path to a template file."""
templates_dir = self._get_templates_dir()
template_path = templates_dir / category / f"{template_name}.gitignore"
if template_path.exists():
return template_path
return None
def load_template(self, template_name: str, category: Optional[str] = None) -> Optional[str]:
"""Load a template by name."""
self._load_custom_templates()
@@ -111,8 +89,8 @@ class TemplateLoader:
categories = ["languages", "ides"]
for cat in categories:
template_path = self._get_template_path(template_name, cat)
if template_path is not None:
template_path = config.template_dir / cat / f"{template_name}.gitignore"
if template_path.exists():
with open(template_path, "r") as f:
return f.read()
@@ -161,8 +139,8 @@ class TemplateLoader:
return True
for cat in ["languages", "ides"]:
template_path = self._get_template_path(template_name, cat)
if template_path is not None:
template_path = config.template_dir / cat / f"{template_name}.gitignore"
if template_path.exists():
return True
return False