Initial commit
This commit is contained in:
61
hooks/post_gen_project.py
Executable file
61
hooks/post_gen_project.py
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Post-generation hook for the Python library template."""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run_command(cmd: list[str], description: str) -> None:
|
||||
"""Run a command and handle errors."""
|
||||
print(f"Running: {description}")
|
||||
try:
|
||||
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
||||
if result.stdout:
|
||||
print(result.stdout)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error running {description}: {e}")
|
||||
if e.stderr:
|
||||
print(f"Error output: {e.stderr}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
"""Initialize the generated project."""
|
||||
project_dir = Path.cwd()
|
||||
print(f"Setting up project in: {project_dir}")
|
||||
|
||||
# Initialize git repository
|
||||
run_command(["git", "init"], "git init")
|
||||
|
||||
# Sync dependencies with uv
|
||||
run_command(["uv", "sync"], "uv sync")
|
||||
|
||||
# Run initial formatting and linting
|
||||
run_command(["uv", "run", "ruff", "format", "src"], "ruff format")
|
||||
run_command(["uv", "run", "ruff", "check", "--fix", "src"], "ruff check --fix")
|
||||
|
||||
# Run type checking
|
||||
try:
|
||||
run_command(["uv", "run", "mypy", "src"], "mypy type checking")
|
||||
except SystemExit:
|
||||
# mypy might fail on initial template, continue anyway
|
||||
print("MyPy check failed - this is normal for initial template")
|
||||
|
||||
# Run tests to ensure everything works
|
||||
try:
|
||||
run_command(["uv", "run", "pytest"], "pytest")
|
||||
except SystemExit:
|
||||
print("Tests failed - you may need to adjust the generated code")
|
||||
|
||||
print("\n✅ Project setup complete!")
|
||||
print("Next steps:")
|
||||
print("1. Review and customize the generated files")
|
||||
print("2. Add your actual dependencies to pyproject.toml")
|
||||
print("3. Implement your library functionality in src/")
|
||||
print("4. Update tests as needed")
|
||||
print("5. Update README.md with proper documentation")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user