refactor template
This commit is contained in:
96
test.sh
96
test.sh
@@ -44,30 +44,56 @@ check_tool() {
|
||||
# Main test function
|
||||
main() {
|
||||
print_status "Starting template test..."
|
||||
|
||||
|
||||
# Get the template directory
|
||||
TEMPLATE_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
# Check which template tool is available
|
||||
CRUFT_AVAILABLE=0
|
||||
COOKIECUTTER_AVAILABLE=0
|
||||
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
|
||||
CRUFT_AVAILABLE=1
|
||||
fi
|
||||
if command -v cookiecutter &> /dev/null; then
|
||||
COOKIECUTTER_AVAILABLE=1
|
||||
fi
|
||||
|
||||
if [ "$CRUFT_AVAILABLE" -eq 0 ] && [ "$COOKIECUTTER_AVAILABLE" -eq 0 ]; then
|
||||
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
|
||||
|
||||
|
||||
if git -C "$TEMPLATE_DIR" rev-parse --is-inside-work-tree &> /dev/null; then
|
||||
if [ -n "$(git -C "$TEMPLATE_DIR" status --porcelain)" ]; then
|
||||
if [ "$COOKIECUTTER_AVAILABLE" -eq 1 ]; then
|
||||
TEMPLATE_TOOL="cookiecutter"
|
||||
print_warning "Working tree is dirty; using cookiecutter to include local changes"
|
||||
else
|
||||
TEMPLATE_TOOL="cruft"
|
||||
print_warning "Working tree is dirty but cookiecutter is unavailable; using cruft"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "${TEMPLATE_TOOL:-}" ]; then
|
||||
if [ "$CRUFT_AVAILABLE" -eq 1 ]; then
|
||||
TEMPLATE_TOOL="cruft"
|
||||
print_status "Using cruft for template generation"
|
||||
else
|
||||
TEMPLATE_TOOL="cookiecutter"
|
||||
print_status "Using cookiecutter for template generation"
|
||||
fi
|
||||
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"
|
||||
@@ -80,17 +106,17 @@ main() {
|
||||
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" \
|
||||
@@ -111,55 +137,55 @@ main() {
|
||||
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; }
|
||||
|
||||
uv sync --group dev || { 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; }
|
||||
|
||||
uv run ruff check src tests || { 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; }
|
||||
|
||||
uv run ruff format --check src tests || { 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
|
||||
if [ -f "examples/config_init.sh" ]; 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)"
|
||||
bash examples/config_init.sh || 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 "$@"
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user