Skip to content

Commit 314b9f7

Browse files
committed
Make the entire project UV first
1 parent 4c1bdef commit 314b9f7

File tree

11 files changed

+412
-275
lines changed

11 files changed

+412
-275
lines changed

.gitlab-ci.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ developer_tests:
3131
before_script:
3232
- python --version
3333
- apt-get update -y
34-
- apt-get install make -y
35-
- pip install ruff
36-
# Install dependencies needed by publish.py for test imports
37-
- pip install typer rich boto3
38-
# Install test dependencies
39-
- cd lib/idp_common_pkg && pip install -e ".[test]" && cd ../..
34+
- apt-get install make curl -y
35+
# Install UV
36+
- curl -LsSf https://astral.sh/uv/install.sh | sh
37+
- export PATH="$HOME/.local/bin:$PATH"
38+
# Sync all dependencies (includes ruff, pytest, publish deps, etc.)
39+
- uv sync --all-extras --group dev
4040

4141
script:
4242
- make lint-cicd
@@ -65,8 +65,10 @@ deployment_validation:
6565
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
6666
- unzip awscliv2.zip
6767
- ./aws/install
68-
# Install PyYAML for template analysis
69-
- pip install PyYAML
68+
# Install UV and PyYAML for template analysis
69+
- curl -LsSf https://astral.sh/uv/install.sh | sh
70+
- export PATH="$HOME/.local/bin:$PATH"
71+
- uv pip install PyYAML
7072

7173
script:
7274
# Check if service role has sufficient permissions for main stack deployment
@@ -97,13 +99,15 @@ integration_tests:
9799

98100
before_script:
99101
- apt-get update -y
100-
- apt-get install zip unzip curl python3-pip -y
102+
- apt-get install zip unzip curl -y
101103
# Install AWS CLI
102104
- curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
103105
- unzip awscliv2.zip
104106
- ./aws/install
105-
# Install boto3 for Python script
106-
- pip install boto3
107+
# Install UV and boto3 for Python script
108+
- curl -LsSf https://astral.sh/uv/install.sh | sh
109+
- export PATH="$HOME/.local/bin:$PATH"
110+
- uv pip install boto3
107111

108112
script:
109113
- aws --version

Makefile

Lines changed: 133 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,114 +7,128 @@ YELLOW := \033[1;33m
77
BLUE := \033[0;34m
88
NC := \033[0m # No Color
99

10-
# Check for UV
10+
# Virtual environment and UV paths
11+
VENV := .venv
1112
UV := $(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:
1819
ifndef 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"
2328
endif
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
5266
ifndef 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
5670
endif
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
7488
build-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
97111
lint: 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
116130
check-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
147213
commit: 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

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,25 @@ pytest
233233

234234
### Publishing and Deployment
235235

236-
The publish script automatically validates UV is installed:
236+
The publish script automatically syncs all required dependencies using UV:
237237

238238
```bash
239+
# One-time setup: sync development dependencies
240+
uv sync --group dev
241+
239242
# Publish with parallel builds (faster with UV!)
240243
./publish.sh my-bucket prefix us-east-1 --max-workers 4
241244

242245
# UV enables safe parallel builds with built-in locking
243246
# Typical speedup: 4x faster than sequential builds
244247
```
245248

249+
The `publish.sh` script automatically:
250+
- Validates Python 3.12+, UV, and Node.js are installed
251+
- Syncs all required Python dependencies (boto3, PyYAML, rich, ruff, etc.)
252+
- Builds and packages Lambda functions
253+
- Uploads artifacts to S3
254+
246255
For more details on the UV migration and dependency management, see:
247256
- [Setup Development Environment (macOS)](./docs/setup-development-env-macos.md)
248257
- [Setup Development Environment (Linux)](./docs/setup-development-env-linux.md)

0 commit comments

Comments
 (0)