diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc4e015 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Build directory for template testing +build/ + +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +env/ +venv/ +.venv +.eggs/ +*.egg-info/ +dist/ +.pytest_cache/ +.mypy_cache/ +.ruff_cache/ + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db \ No newline at end of file diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..beb4467 --- /dev/null +++ b/test.sh @@ -0,0 +1,165 @@ +#!/bin/bash + +set -euo pipefail + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Function to print colored output +print_status() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +# Cleanup function +cleanup() { + # Optional cleanup - can be commented out to keep build directory for inspection + # if [ -n "${TEMP_DIR:-}" ] && [ -d "$TEMP_DIR" ]; then + # print_status "Keeping build directory for inspection: $TEMP_DIR" + # fi + print_status "Test completed. Build directory: ${TEMP_DIR:-}" +} + +# Set up trap for cleanup on exit +trap cleanup EXIT + +# Check for required tools +check_tool() { + if ! command -v "$1" &> /dev/null; then + print_error "$1 is not installed. Please install it first." + exit 1 + fi +} + +# Main test function +main() { + print_status "Starting template test..." + + # Check which template tool is available + if command -v cruft &> /dev/null; then + TEMPLATE_TOOL="cruft" + print_status "Using cruft for template generation" + elif command -v cookiecutter &> /dev/null; then + TEMPLATE_TOOL="cookiecutter" + print_status "Using cookiecutter for template generation" + else + print_error "Neither cruft nor cookiecutter is installed. Please install one of them." + print_status "Install with: pip install cruft or pip install cookiecutter" + exit 1 + fi + + # Check for uv + check_tool "uv" + + # Get the template directory + TEMPLATE_DIR="$(cd "$(dirname "$0")" && pwd)" + print_status "Template directory: $TEMPLATE_DIR" + + # Set up build directory + TEMP_DIR="$TEMPLATE_DIR/build" + + # Check if build directory exists and ask for confirmation + if [ -d "$TEMP_DIR" ]; then + print_warning "Build directory already exists: $TEMP_DIR" + read -p "Remove existing build directory and continue? (y/n) [y]: " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]] && [[ ! -z $REPLY ]]; then + print_status "Aborted by user" + exit 0 + fi + print_status "Removing existing build directory..." + rm -rf "$TEMP_DIR" + fi + + # Create build directory + mkdir -p "$TEMP_DIR" + print_status "Created build directory: $TEMP_DIR" + + # Generate project from template + print_status "Generating example project from template..." + + # Default values for the template + PROJECT_NAME="test-project" + + if [ "$TEMPLATE_TOOL" = "cruft" ]; then + cd "$TEMP_DIR" + cruft create "$TEMPLATE_DIR" \ + --no-input \ + --extra-context '{"project_name": "Test Project", "project_slug": "test-project", "package_name": "test_project", "description": "A test project", "author_name": "Test Author", "author_email": "test@example.com", "version": "0.1.0", "python_version": "3.12"}' \ + || { print_error "Failed to generate project with cruft"; exit 1; } + else + cd "$TEMP_DIR" + cookiecutter "$TEMPLATE_DIR" \ + --no-input \ + project_name="Test Project" \ + project_slug="test-project" \ + package_name="test_project" \ + description="A test project" \ + author_name="Test Author" \ + author_email="test@example.com" \ + version="0.1.0" \ + python_version="3.12" \ + || { print_error "Failed to generate project with cookiecutter"; exit 1; } + fi + + # Navigate to generated project + cd "$TEMP_DIR/$PROJECT_NAME" + print_status "Generated project at: $(pwd)" + + # List generated files + print_status "Generated files:" + ls -la + + # Install dependencies + print_status "Installing dependencies with uv..." + uv sync || { print_error "Failed to install dependencies"; exit 1; } + + # Run ruff check + print_status "Running ruff check..." + uv run ruff check src || { print_error "Ruff check failed"; exit 1; } + + # Run ruff format check + print_status "Running ruff format check..." + uv run ruff format --check src || { print_error "Ruff format check failed"; exit 1; } + + # Run mypy + print_status "Running mypy type checking..." + uv run mypy src || { print_error "Mypy type checking failed"; exit 1; } + + # Run tests + print_status "Running tests..." + uv run pytest || { print_error "Tests failed"; exit 1; } + + # Run tests with coverage + print_status "Running tests with coverage..." + uv run pytest --cov=src --cov-report=term-missing || { print_error "Tests with coverage failed"; exit 1; } + + # Try running invoke tasks + print_status "Testing invoke lint task..." + uv run invoke lint || { print_error "Invoke lint task failed"; exit 1; } + + print_status "Testing invoke test task..." + uv run invoke test || { print_error "Invoke test task failed"; exit 1; } + + # Check if example script runs + if [ -f "examples/basic_usage.py" ]; then + print_status "Running example script..." + uv run python examples/basic_usage.py || print_warning "Example script failed (this may be expected if it's a placeholder)" + fi + + print_status "✅ All tests passed successfully!" + print_status "Template is working correctly." +} + +# Run main function +main "$@" \ No newline at end of file