Files
python-cli-template/hooks/post_gen_project.py
2026-02-14 11:47:18 +01:00

33 lines
899 B
Python
Executable File

#!/usr/bin/env python3
"""Post-generation hook for deterministic project bootstrapping."""
from __future__ import annotations
import shutil
import subprocess
import sys
def main() -> None:
"""Create a lockfile so generated projects are reproducible by default."""
if shutil.which("uv") is None:
print("Error: 'uv' is required but was not found on PATH.", file=sys.stderr)
sys.exit(1)
print("Running: uv lock")
try:
subprocess.run(["uv", "lock"], check=True)
except subprocess.CalledProcessError as exc:
print(f"Error: uv lock failed with exit code {exc.returncode}.", file=sys.stderr)
sys.exit(exc.returncode)
print("\nProject lockfile generated.")
print("Next steps:")
print("1. uv sync --frozen --group dev")
print("2. uv run invoke lint")
print("3. uv run invoke test")
if __name__ == "__main__":
main()