diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd7da7d..1878a45 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,6 +32,13 @@ repos: types: [python] pass_filenames: false + - id: inspect-templates + name: inspect changed fastapi templates + entry: python scripts/inspect-changed-templates.py + language: system + pass_filenames: false + stages: [commit] + ci: autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate diff --git a/CHANGELOG.md b/CHANGELOG.md index fa7eccb..c175be2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ # Changelog -## v.1.1.2 (2025-09-05) +## v1.1.3 (2025-09-13) + +### Templates + +- add `fastapi-single-module` template +- update `fastapi-psql-orm` template : fix dockerfile & docker-compose.yml scripts errors + +## v1.1.2 (2025-09-05) ### Improvements diff --git a/scripts/inspect-changed-templates.py b/scripts/inspect-changed-templates.py new file mode 100644 index 0000000..376271f --- /dev/null +++ b/scripts/inspect-changed-templates.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# -------------------------------------------------------------------------- +# Inspect only changed FastAPI templates (for pre-commit / local use) +# -------------------------------------------------------------------------- +import os +import subprocess +import sys +from pathlib import Path +from typing import List, Set + +# Ensure src is importable +PROJECT_ROOT = Path(__file__).parent.parent +sys.path.insert(0, str(PROJECT_ROOT / "src")) + +from fastapi_fastkit.backend.inspector import inspect_fastapi_template + +TEMPLATE_DIR = PROJECT_ROOT / "src" / "fastapi_fastkit" / "fastapi_project_template" + + +def get_changed_files() -> List[str]: + """Return a list of changed files according to git (staged + unstaged).""" + # Include staged and unstaged changes compared to HEAD + cmd = [ + "git", + "diff", + "--name-only", + "--cached", + ] + staged = subprocess.run(cmd, capture_output=True, text=True, check=False) + cmd_unstaged = [ + "git", + "diff", + "--name-only", + ] + unstaged = subprocess.run(cmd_unstaged, capture_output=True, text=True, check=False) + + files: Set[str] = set() + if staged.stdout: + files.update( + [line.strip() for line in staged.stdout.splitlines() if line.strip()] + ) + if unstaged.stdout: + files.update( + [line.strip() for line in unstaged.stdout.splitlines() if line.strip()] + ) + return sorted(files) + + +def extract_changed_templates(changed_files: List[str]) -> List[str]: + """Map changed files to template directory names under TEMPLATE_DIR.""" + templates: Set[str] = set() + template_root_str = str(TEMPLATE_DIR).rstrip("/") + + for f in changed_files: + fp = (PROJECT_ROOT / f).resolve() + # Only consider files under template root + try: + if str(fp).startswith(template_root_str): + # template name is immediate child dir of TEMPLATE_DIR + # e.g., .../fastapi_project_template/