Skip to content

Commit bed265b

Browse files
committed
update to UV
1 parent e3d0dbd commit bed265b

File tree

133 files changed

+7050
-1184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+7050
-1184
lines changed

.gitignore

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1+
# Environment
12
.env
3+
.venv/
4+
venv/
5+
6+
# AWS SAM
27
.aws-sam
38
build.toml
9+
10+
# Build artifacts
411
model.tar.gz
512
.checksum
613
.checksums/
714
.build_checksum
815
.lib_checksum
16+
dist/
17+
build/
18+
*.egg-info/
19+
20+
# Python
21+
__pycache__
22+
*.py[cod]
23+
*$py.class
24+
*.so
25+
.Python
26+
27+
# UV specific
28+
.python-version
29+
30+
# Ruff
31+
.ruff_cache
32+
33+
# IDEs
934
.vscode/
35+
.idea/
36+
*.code-workspace
37+
38+
# OS
1039
.DS_Store
11-
dist/
40+
41+
# Project specific
1242
.sav/
1343
.delete/
1444
.data/
15-
*.egg-info/
16-
build/
17-
__pycache__
18-
*.code-workspace
19-
.ruff_cache
2045
.kiro
2146
rvl_cdip_*
2247
notebooks/examples/data
23-
.idea/
2448
.dsr/
2549
*tmp-dev-assets*
2650
scratch/

.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

Dockerfile.optimized

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Optimized Dockerfile for Lambda functions with minimal dependencies
2-
# This builds each function with ONLY the dependencies it needs
1+
# Optimized Dockerfile for Lambda functions with UV and pyproject.toml dependency groups
2+
# This builds each function with ONLY the dependencies it needs from the root pyproject.toml
33

44
# checkov:skip=CKV_DOCKER_3: "The Dockerfile uses the official AWS Lambda Python base image (public.ecr.aws/lambda/python:3.12-arm64), which already configures the appropriate non-root user for Lambda execution"
55
# checkov:skip=CKV_DOCKER_2: "The Dockerfile.optimized is specifically designed for AWS Lambda container images, which don't use Docker HEALTHCHECK instructions."
@@ -10,25 +10,24 @@ FROM public.ecr.aws/lambda/python:3.12-arm64 AS builder
1010
# Copy uv from official distroless image
1111
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
1212

13-
# Build argument for function path
13+
# Build argument for dependency group from root pyproject.toml
14+
ARG DEPENDENCY_GROUP
1415
ARG FUNCTION_PATH
15-
ARG INSTALL_IDP_COMMON=true
1616

1717
# Create working directory
1818
WORKDIR /build
1919

20-
# Copy idp_common_pkg and requirements for installation
21-
COPY lib/idp_common_pkg /tmp/idp_common_pkg
22-
COPY ${FUNCTION_PATH}/requirements.txt* /build/
20+
# Copy root pyproject.toml, uv.lock, and idp_common_pkg
21+
COPY pyproject.toml uv.lock /build/
22+
COPY lib/idp_common_pkg /build/lib/idp_common_pkg
2323

24-
# Install all dependencies including idp_common_pkg in one step
24+
# Install dependencies from the specified dependency group
2525
RUN --mount=type=cache,target=/root/.cache/uv \
26-
if [ -f /build/requirements.txt ]; then \
27-
sed 's|^\.\./\.\.\(/\.\.\)\?/lib/idp_common_pkg|/tmp/idp_common_pkg|' /build/requirements.txt > /tmp/requirements.txt && \
28-
uv pip install --python python3.12 --target /opt/python -r /tmp/requirements.txt && \
29-
rm /tmp/requirements.txt; \
30-
fi && \
31-
rm -rf /tmp/idp_common_pkg
26+
if [ -n "$DEPENDENCY_GROUP" ]; then \
27+
uv pip install --python python3.12 --project /build --group "$DEPENDENCY_GROUP" --target /opt/python; \
28+
else \
29+
echo "ERROR: DEPENDENCY_GROUP not specified" && exit 1; \
30+
fi
3231

3332
# Final stage - minimal runtime
3433
FROM public.ecr.aws/lambda/python:3.12-arm64
@@ -44,4 +43,4 @@ COPY ${FUNCTION_PATH}/*.py ${LAMBDA_TASK_ROOT}/
4443
ENV PYTHONPATH=/opt/python:${LAMBDA_TASK_ROOT}
4544

4645
# Set handler
47-
CMD ["index.handler"]
46+
CMD ["index.handler"]

Makefile

Lines changed: 164 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,134 @@
1-
# Makefile for code quality and formatting
1+
# Makefile for IDP Accelerator - UV + Hatchling build system
22

33
# Define color codes
44
RED := \033[0;31m
55
GREEN := \033[0;32m
66
YELLOW := \033[1;33m
7+
BLUE := \033[0;34m
78
NC := \033[0m # No Color
89

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)
1113

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
1616

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"
1997

2098
# 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"
23103

24104
# 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
27112

28113
# CI/CD version of lint that only checks but doesn't modify files
29114
# 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"; \
35120
exit 1; \
36121
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"; \
40125
exit 1; \
41126
fi
42-
@echo -e "$(GREEN)All code quality checks passed!$(NC)"
127+
@printf "$(GREEN)All code quality checks passed!$(NC)\n"
43128

44129
# Check CloudFormation templates for hardcoded AWS partition ARNs and service principals
45130
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"
47132
@FOUND_ISSUES=0; \
48133
for template in template.yaml patterns/*/template.yaml patterns/*/sagemaker_classifier_endpoint.yaml options/*/template.yaml; do \
49134
if [ -f "$$template" ]; then \
@@ -72,10 +157,66 @@ check-arn-partitions:
72157
exit 1; \
73158
fi
74159

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+
75212
# A convenience Makefile target that runs
76213
commit: lint test
77214
$(info Generating commit message...)
78215
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')" && \
79216
git add . && \
80217
git commit -am "$${COMMIT_MESSAGE}" && \
81218
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

Comments
 (0)