|
1 | | -# Makefile for code quality and formatting |
| 1 | +# Makefile for IDP Accelerator - UV + Hatchling build system |
2 | 2 |
|
3 | 3 | # Define color codes |
4 | 4 | RED := \033[0;31m |
5 | 5 | GREEN := \033[0;32m |
6 | 6 | YELLOW := \033[1;33m |
| 7 | +BLUE := \033[0;34m |
7 | 8 | NC := \033[0m # No Color |
8 | 9 |
|
9 | | -# Default target - run both lint and test |
10 | | -all: lint test |
| 10 | +# Virtual environment and UV paths |
| 11 | +VENV := .venv |
| 12 | +UV := $(shell command -v uv 2> /dev/null) |
11 | 13 |
|
12 | | -# Run tests in idp_common_pkg and idp_cli directories |
13 | | -test: |
14 | | - $(MAKE) -C lib/idp_common_pkg test |
15 | | - cd idp_cli && python -m pytest -v |
| 14 | +# Default target - ensure UV and venv, then run lint and test |
| 15 | +all: setup lint test |
16 | 16 |
|
17 | | -# Run both linting and formatting in one command |
18 | | -lint: ruff-lint format check-arn-partitions |
| 17 | +# Install UV if not present |
| 18 | +install-uv: |
| 19 | +ifndef UV |
| 20 | + @printf "$(YELLOW)📦 UV not found. Installing UV...$(NC)\n" |
| 21 | + @curl -LsSf https://astral.sh/uv/install.sh | sh |
| 22 | + @printf "$(GREEN)✅ UV installed!$(NC)\n" |
| 23 | + @printf "$(YELLOW)⚠️ Please restart your shell or run: source ~/.bashrc (or ~/.zshrc)$(NC)\n" |
| 24 | + @printf "$(YELLOW)⚠️ Then re-run make$(NC)\n" |
| 25 | + @exit 1 |
| 26 | +else |
| 27 | + @printf "$(GREEN)✅ UV is already installed: $(UV)$(NC)\n" |
| 28 | +endif |
| 29 | + |
| 30 | +# Create .venv using UV if it doesn't exist |
| 31 | +$(VENV): |
| 32 | + @printf "$(BLUE)🏗️ Creating virtual environment with UV...$(NC)\n" |
| 33 | + @$(UV) venv |
| 34 | + @printf "$(GREEN)✅ Virtual environment created at $(VENV)$(NC)\n" |
| 35 | + |
| 36 | +# Setup: ensure UV is installed and create venv |
| 37 | +setup: install-uv $(VENV) |
| 38 | + @printf "$(GREEN)✅ Setup complete!$(NC)\n" |
| 39 | + |
| 40 | +# Initialize UV environment (creates .venv and syncs all dependencies) |
| 41 | +init: setup |
| 42 | + @printf "$(BLUE)🚀 Initializing UV workspace...$(NC)\n" |
| 43 | + @$(UV) sync --all-extras --group dev |
| 44 | + @printf "$(GREEN)✅ Workspace initialized with all features + dev dependencies$(NC)\n" |
| 45 | + |
| 46 | +# Lock dependencies |
| 47 | +lock: install-uv |
| 48 | + @printf "$(BLUE)🔒 Locking dependencies...$(NC)\n" |
| 49 | + @$(UV) lock |
| 50 | + @printf "$(GREEN)✅ Dependencies locked (uv.lock updated)$(NC)\n" |
| 51 | + |
| 52 | +# Sync local development environment |
| 53 | +sync: setup |
| 54 | + @printf "$(BLUE)📦 Syncing development environment...$(NC)\n" |
| 55 | + @$(UV) sync --all-extras --group dev |
| 56 | + @printf "$(GREEN)✅ Environment synced with all features$(NC)\n" |
| 57 | + |
| 58 | +# Update dependencies |
| 59 | +update: setup |
| 60 | + @printf "$(BLUE)⬆️ Updating dependencies...$(NC)\n" |
| 61 | + @$(UV) lock --upgrade |
| 62 | + @printf "$(GREEN)✅ Dependencies updated$(NC)\n" |
| 63 | + |
| 64 | +# Update specific package |
| 65 | +update-package: setup |
| 66 | +ifndef PKG |
| 67 | + @printf "$(RED)❌ ERROR: PKG variable not set$(NC)\n" |
| 68 | + @echo "Usage: make update-package PKG=boto3" |
| 69 | + @exit 1 |
| 70 | +endif |
| 71 | + @printf "$(BLUE)⬆️ Updating $(PKG)...$(NC)\n" |
| 72 | + @$(UV) lock --upgrade-package $(PKG) |
| 73 | + @printf "$(GREEN)✅ $(PKG) updated$(NC)\n" |
| 74 | + |
| 75 | +# Build idp_common package |
| 76 | +build-idp-common: setup |
| 77 | + @printf "$(BLUE)🔨 Building idp_common package...$(NC)\n" |
| 78 | + @cd lib/idp_common_pkg && $(UV) build |
| 79 | + @printf "$(GREEN)✅ idp_common built$(NC)\n" |
| 80 | + |
| 81 | +# Build idp_cli package |
| 82 | +build-idp-cli: setup |
| 83 | + @printf "$(BLUE)🔨 Building idp_cli package...$(NC)\n" |
| 84 | + @cd idp_cli && $(UV) build |
| 85 | + @printf "$(GREEN)✅ idp_cli built$(NC)\n" |
| 86 | + |
| 87 | +# Build all Python packages |
| 88 | +build-packages: build-idp-common build-idp-cli |
| 89 | + @printf "$(GREEN)✅ All packages built$(NC)\n" |
| 90 | + |
| 91 | +# Run tests in idp_common_pkg and idp_cli directories |
| 92 | +test: setup |
| 93 | + @printf "$(BLUE)🧪 Running tests...$(NC)\n" |
| 94 | + @cd lib/idp_common_pkg && $(UV) run --all-extras --group dev pytest -m "unit" |
| 95 | + @cd idp_cli && $(UV) run --group dev pytest -v |
| 96 | + @printf "$(GREEN)✅ All tests passed$(NC)\n" |
19 | 97 |
|
20 | 98 | # Run linting checks and fix issues automatically |
21 | | -ruff-lint: |
22 | | - ruff check --fix |
| 99 | +ruff-lint: setup |
| 100 | + @printf "$(BLUE)🔍 Running ruff linting...$(NC)\n" |
| 101 | + @$(UV) run --group dev ruff check --fix |
| 102 | + @printf "$(GREEN)✅ Linting complete$(NC)\n" |
23 | 103 |
|
24 | 104 | # Format code according to project standards |
25 | | -format: |
26 | | - ruff format |
| 105 | +format: setup |
| 106 | + @printf "$(BLUE)✨ Formatting code...$(NC)\n" |
| 107 | + @$(UV) run --group dev ruff format |
| 108 | + @printf "$(GREEN)✅ Formatting complete$(NC)\n" |
| 109 | + |
| 110 | +# Run both linting and formatting in one command |
| 111 | +lint: ruff-lint format check-arn-partitions |
27 | 112 |
|
28 | 113 | # CI/CD version of lint that only checks but doesn't modify files |
29 | 114 | # Used in CI pipelines to verify code quality without making changes |
30 | | -lint-cicd: |
31 | | - @echo "Running code quality checks..." |
32 | | - @if ! ruff check; then \ |
33 | | - echo -e "$(RED)ERROR: Ruff linting failed!$(NC)"; \ |
34 | | - echo -e "$(YELLOW)Please run 'make ruff-lint' locally to fix these issues.$(NC)"; \ |
| 115 | +lint-cicd: setup |
| 116 | + @printf "$(BLUE)Running code quality checks...$(NC)\n" |
| 117 | + @if ! $(UV) run --group dev ruff check; then \ |
| 118 | + printf "$(RED)ERROR: Ruff linting failed!$(NC)\n"; \ |
| 119 | + printf "$(YELLOW)Please run 'make ruff-lint' locally to fix these issues.$(NC)\n"; \ |
35 | 120 | exit 1; \ |
36 | 121 | fi |
37 | | - @if ! ruff format --check; then \ |
38 | | - echo -e "$(RED)ERROR: Code formatting check failed!$(NC)"; \ |
39 | | - echo -e "$(YELLOW)Please run 'make format' locally to fix these issues.$(NC)"; \ |
| 122 | + @if ! $(UV) run --group dev ruff format --check; then \ |
| 123 | + printf "$(RED)ERROR: Code formatting check failed!$(NC)\n"; \ |
| 124 | + printf "$(YELLOW)Please run 'make format' locally to fix these issues.$(NC)\n"; \ |
40 | 125 | exit 1; \ |
41 | 126 | fi |
42 | | - @echo -e "$(GREEN)All code quality checks passed!$(NC)" |
| 127 | + @printf "$(GREEN)All code quality checks passed!$(NC)\n" |
43 | 128 |
|
44 | 129 | # Check CloudFormation templates for hardcoded AWS partition ARNs and service principals |
45 | 130 | check-arn-partitions: |
46 | | - @echo "Checking CloudFormation templates for hardcoded ARN partitions and service principals..." |
| 131 | + @printf "$(BLUE)Checking CloudFormation templates for hardcoded ARN partitions and service principals...$(NC)\n" |
47 | 132 | @FOUND_ISSUES=0; \ |
48 | 133 | for template in template.yaml patterns/*/template.yaml patterns/*/sagemaker_classifier_endpoint.yaml options/*/template.yaml; do \ |
49 | 134 | if [ -f "$$template" ]; then \ |
@@ -72,10 +157,66 @@ check-arn-partitions: |
72 | 157 | exit 1; \ |
73 | 158 | fi |
74 | 159 |
|
| 160 | +# Clean up build artifacts and caches |
| 161 | +clean: |
| 162 | + @printf "$(BLUE)🧹 Cleaning build artifacts...$(NC)\n" |
| 163 | + @rm -rf .venv |
| 164 | + @rm -rf lib/idp_common_pkg/dist lib/idp_common_pkg/build lib/idp_common_pkg/*.egg-info |
| 165 | + @rm -rf idp_cli/dist idp_cli/build idp_cli/*.egg-info |
| 166 | + @find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true |
| 167 | + @find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true |
| 168 | + @find . -type d -name ".ruff_cache" -exec rm -rf {} + 2>/dev/null || true |
| 169 | + @find . -type f -name "*.pyc" -delete 2>/dev/null || true |
| 170 | + @printf "$(GREEN)✅ Cleanup complete$(NC)\n" |
| 171 | + |
| 172 | +# Clean everything including uv.lock (use with caution) |
| 173 | +clean-all: clean |
| 174 | + @printf "$(YELLOW)⚠️ Removing uv.lock...$(NC)\n" |
| 175 | + @rm -f uv.lock |
| 176 | + @printf "$(GREEN)✅ Deep cleanup complete$(NC)\n" |
| 177 | + |
| 178 | +# Show help |
| 179 | +help: |
| 180 | + @printf "$(BLUE)IDP Accelerator Makefile - UV-based Python Development$(NC)\n" |
| 181 | + @echo "" |
| 182 | + @printf "$(YELLOW)Setup Targets:$(NC)" |
| 183 | + @echo " make setup - Install UV and create .venv (automatically done by other targets)" |
| 184 | + @echo " make init - Initialize workspace with dev dependencies" |
| 185 | + @echo " make sync - Sync development environment" |
| 186 | + @echo "" |
| 187 | + @printf "$(YELLOW)Development Targets:$(NC)" |
| 188 | + @echo " make lint - Run linting and formatting" |
| 189 | + @echo " make ruff-lint - Run ruff linting with auto-fix" |
| 190 | + @echo " make format - Format code with ruff" |
| 191 | + @echo " make test - Run all tests" |
| 192 | + @echo "" |
| 193 | + @printf "$(YELLOW)Dependency Management:$(NC)" |
| 194 | + @echo " make lock - Lock dependencies (update uv.lock)" |
| 195 | + @echo " make update - Update all dependencies" |
| 196 | + @echo " make update-package PKG=<name> - Update specific package" |
| 197 | + @echo "" |
| 198 | + @printf "$(YELLOW)Build Targets:$(NC)" |
| 199 | + @echo " make build-idp-common - Build idp_common package" |
| 200 | + @echo " make build-idp-cli - Build idp_cli package" |
| 201 | + @echo " make build-packages - Build all packages" |
| 202 | + @echo "" |
| 203 | + @printf "$(YELLOW)Cleanup Targets:$(NC)" |
| 204 | + @echo " make clean - Remove .venv and build artifacts" |
| 205 | + @echo " make clean-all - Remove .venv, build artifacts, and uv.lock" |
| 206 | + @echo "" |
| 207 | + @printf "$(YELLOW)Other Targets:$(NC)" |
| 208 | + @echo " make all - Run setup, lint, and test" |
| 209 | + @echo " make check-arn-partitions - Check CFN templates for GovCloud compatibility" |
| 210 | + @echo " make help - Show this help message" |
| 211 | + |
75 | 212 | # A convenience Makefile target that runs |
76 | 213 | commit: lint test |
77 | 214 | $(info Generating commit message...) |
78 | 215 | export COMMIT_MESSAGE="$(shell q chat --no-interactive --trust-all-tools "Understand pending local git change and changes to be committed, then infer a commit message. Return this commit message only" | tail -n 1 | sed 's/\x1b\[[0-9;]*m//g')" && \ |
79 | 216 | git add . && \ |
80 | 217 | git commit -am "$${COMMIT_MESSAGE}" && \ |
81 | 218 | git push |
| 219 | + |
| 220 | +.PHONY: all setup install-uv init lock sync update update-package \ |
| 221 | + build-idp-common build-idp-cli build-packages test ruff-lint format \ |
| 222 | + lint lint-cicd check-arn-partitions clean clean-all help commit |
0 commit comments