@@ -7,114 +7,128 @@ YELLOW := \033[1;33m
77BLUE := \033[0;34m
88NC := \033[0m # No Color
99
10- # Check for UV
10+ # Virtual environment and UV paths
11+ VENV := .venv
1112UV := $(shell command -v uv 2> /dev/null)
1213
13- # Default target - run both lint and test
14- all : check-uv lint test
14+ # Default target - ensure UV and venv, then run lint and test
15+ all : setup lint test
1516
16- # Ensure UV is installed
17- check -uv :
17+ # Install UV if not present
18+ install -uv :
1819ifndef UV
19- @echo -e "$(RED)❌ ERROR: uv is not installed$(NC)"
20- @echo -e "$(YELLOW)Install from: https://astral.sh/uv$(NC)"
21- @echo " curl -LsSf https://astral.sh/uv/install.sh | sh"
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"
2225 @exit 1
26+ else
27+ @printf "$(GREEN)✅ UV is already installed: $(UV)$(NC)\n"
2328endif
24- @echo -e "$(GREEN)✅ UV is installed: $(UV)$(NC)"
2529
26- # Initialize UV environment
27- init : check-uv
28- @echo -e " $( BLUE) 🚀 Initializing UV workspace...$( NC) "
29- $(UV ) sync --all-extras
30- @echo -e " $( GREEN) ✅ Workspace initialized$( NC) "
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"
3145
3246# Lock dependencies
33- lock : check -uv
34- @echo -e " $( BLUE) 🔒 Locking dependencies...$( NC) "
35- $(UV ) lock
36- @echo -e " $( GREEN) ✅ Dependencies locked (uv.lock updated)$( NC) "
47+ lock : install -uv
48+ @printf " $( BLUE) 🔒 Locking dependencies...$( NC) \n "
49+ @ $(UV ) lock
50+ @printf " $( GREEN) ✅ Dependencies locked (uv.lock updated)$( NC) \n "
3751
3852# Sync local development environment
39- sync : check-uv
40- @echo -e " $( BLUE) 📦 Syncing development environment...$( NC) "
41- $(UV ) sync --all-extras
42- @echo -e " $( GREEN) ✅ Environment synced$( NC) "
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 "
4357
4458# Update dependencies
45- update : check-uv
46- @echo -e " $( BLUE) ⬆️ Updating dependencies...$( NC) "
47- $(UV ) lock --upgrade
48- @echo -e " $( GREEN) ✅ Dependencies updated$( NC) "
59+ update : setup
60+ @printf " $( BLUE) ⬆️ Updating dependencies...$( NC) \n "
61+ @ $(UV ) lock --upgrade
62+ @printf " $( GREEN) ✅ Dependencies updated$( NC) \n "
4963
5064# Update specific package
51- update-package : check-uv
65+ update-package : setup
5266ifndef PKG
53- @echo -e "$(RED)❌ ERROR: PKG variable not set$(NC)"
67+ @printf "$(RED)❌ ERROR: PKG variable not set$(NC)\n "
5468 @echo "Usage: make update-package PKG=boto3"
5569 @exit 1
5670endif
57- @echo -e "$(BLUE)⬆️ Updating $(PKG)...$(NC)"
58- $(UV) lock --upgrade-package $(PKG)
59- @echo -e "$(GREEN)✅ $(PKG) updated$(NC)"
71+ @printf "$(BLUE)⬆️ Updating $(PKG)...$(NC)\n "
72+ @ $(UV) lock --upgrade-package $(PKG)
73+ @printf "$(GREEN)✅ $(PKG) updated$(NC)\n "
6074
6175# Build idp_common package
62- build-idp-common : check-uv
63- @echo -e " $( BLUE) 🔨 Building idp_common package...$( NC) "
64- cd lib/idp_common_pkg && $(UV ) build
65- @echo -e " $( GREEN) ✅ idp_common built$( NC) "
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 "
6680
6781# Build idp_cli package
68- build-idp-cli : check-uv
69- @echo -e " $( BLUE) 🔨 Building idp_cli package...$( NC) "
70- cd idp_cli && $(UV ) build
71- @echo -e " $( GREEN) ✅ idp_cli built$( NC) "
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 "
7286
7387# Build all Python packages
7488build-packages : build-idp-common build-idp-cli
75- @echo -e " $( GREEN) ✅ All packages built$( NC) "
89+ @printf " $( GREEN) ✅ All packages built$( NC) \n "
7690
7791# Run tests in idp_common_pkg and idp_cli directories
78- test : check-uv
79- @echo -e " $( BLUE) 🧪 Running tests...$( NC) "
80- $( MAKE ) -C lib/idp_common_pkg test
81- cd idp_cli && $(UV ) run pytest -v
82- @echo -e " $( GREEN) ✅ All tests passed$( NC) "
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 "
8397
8498# Run linting checks and fix issues automatically
85- ruff-lint : check-uv
86- @echo -e " $( BLUE) 🔍 Running ruff linting...$( NC) "
87- $(UV ) run ruff check --fix
88- @echo -e " $( GREEN) ✅ Linting complete$( NC) "
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 "
89103
90104# Format code according to project standards
91- format : check-uv
92- @echo -e " $( BLUE) ✨ Formatting code...$( NC) "
93- $(UV ) run ruff format
94- @echo -e " $( GREEN) ✅ Formatting complete$( NC) "
105+ format : setup
106+ @printf " $( BLUE) ✨ Formatting code...$( NC) \n "
107+ @ $(UV ) run --group dev ruff format
108+ @printf " $( GREEN) ✅ Formatting complete$( NC) \n "
95109
96110# Run both linting and formatting in one command
97111lint : ruff-lint format check-arn-partitions
98112
99113# CI/CD version of lint that only checks but doesn't modify files
100114# Used in CI pipelines to verify code quality without making changes
101- lint-cicd :
102- @echo " Running code quality checks..."
103- @if ! ruff check; then \
104- echo -e " $( RED) ERROR: Ruff linting failed!$( NC) " ; \
105- 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 " ; \
106120 exit 1; \
107121 fi
108- @if ! ruff format --check; then \
109- echo -e " $( RED) ERROR: Code formatting check failed!$( NC) " ; \
110- 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 " ; \
111125 exit 1; \
112126 fi
113- @echo -e " $( GREEN) All code quality checks passed!$( NC) "
127+ @printf " $( GREEN) All code quality checks passed!$( NC) \n "
114128
115129# Check CloudFormation templates for hardcoded AWS partition ARNs and service principals
116130check-arn-partitions :
117- @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 "
118132 @FOUND_ISSUES=0; \
119133 for template in template.yaml patterns/* /template.yaml patterns/* /sagemaker_classifier_endpoint.yaml options/* /template.yaml; do \
120134 if [ -f " $$ template" ]; then \
@@ -143,10 +157,66 @@ check-arn-partitions:
143157 exit 1; \
144158 fi
145159
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+
146212# A convenience Makefile target that runs
147213commit : lint test
148214 $(info Generating commit message...)
149215 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' ) " && \
150216 git add . && \
151217 git commit -am " $$ {COMMIT_MESSAGE}" && \
152218 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