Skip to content

Commit d9d8d54

Browse files
committed
update to UV
1 parent 13d0da6 commit d9d8d54

File tree

111 files changed

+13389
-773
lines changed

Some content is hidden

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

111 files changed

+13389
-773
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/

Dockerfile.optimized

Lines changed: 13 additions & 14 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 --target /opt/python "/build[${DEPENDENCY_GROUP}]"; \
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

Makefile

Lines changed: 82 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,100 @@
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

10+
# Check for UV
11+
UV := $(shell command -v uv 2> /dev/null)
12+
913
# Default target - run both lint and test
10-
all: lint test
14+
all: check-uv lint test
15+
16+
# Ensure UV is installed
17+
check-uv:
18+
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"
22+
@exit 1
23+
endif
24+
@echo -e "$(GREEN)✅ UV is installed: $(UV)$(NC)"
25+
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)"
31+
32+
# 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)"
37+
38+
# 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)"
43+
44+
# Update dependencies
45+
update: check-uv
46+
@echo -e "$(BLUE)⬆️ Updating dependencies...$(NC)"
47+
$(UV) lock --upgrade
48+
@echo -e "$(GREEN)✅ Dependencies updated$(NC)"
49+
50+
# Update specific package
51+
update-package: check-uv
52+
ifndef PKG
53+
@echo -e "$(RED)❌ ERROR: PKG variable not set$(NC)"
54+
@echo "Usage: make update-package PKG=boto3"
55+
@exit 1
56+
endif
57+
@echo -e "$(BLUE)⬆️ Updating $(PKG)...$(NC)"
58+
$(UV) lock --upgrade-package $(PKG)
59+
@echo -e "$(GREEN)✅ $(PKG) updated$(NC)"
60+
61+
# 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)"
66+
67+
# 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)"
72+
73+
# Build all Python packages
74+
build-packages: build-idp-common build-idp-cli
75+
@echo -e "$(GREEN)✅ All packages built$(NC)"
1176

1277
# Run tests in idp_common_pkg and idp_cli directories
13-
test:
78+
test: check-uv
79+
@echo -e "$(BLUE)🧪 Running tests...$(NC)"
1480
$(MAKE) -C lib/idp_common_pkg test
15-
cd idp_cli && python -m pytest -v
16-
17-
# Run both linting and formatting in one command
18-
lint: ruff-lint format check-arn-partitions
81+
cd idp_cli && $(UV) run pytest -v
82+
@echo -e "$(GREEN)✅ All tests passed$(NC)"
1983

2084
# Run linting checks and fix issues automatically
21-
ruff-lint:
22-
ruff check --fix
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)"
2389

2490
# Format code according to project standards
25-
format:
26-
ruff format
91+
format: check-uv
92+
@echo -e "$(BLUE)✨ Formatting code...$(NC)"
93+
$(UV) run ruff format
94+
@echo -e "$(GREEN)✅ Formatting complete$(NC)"
95+
96+
# Run both linting and formatting in one command
97+
lint: ruff-lint format check-arn-partitions
2798

2899
# CI/CD version of lint that only checks but doesn't modify files
29100
# Used in CI pipelines to verify code quality without making changes

docs/lambda-dependency-groups.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Lambda Dependency Groups
2+
3+
This document maps each Lambda function to its dependency group defined in the root `pyproject.toml`.
4+
5+
## Dependency Group Reference
6+
7+
All dependency groups are defined in `/pyproject.toml` under `[dependency-groups]`.
8+
9+
## Pattern 1 Lambdas (BDA)
10+
11+
| Lambda Function | Directory | Dependency Group |
12+
|----------------|-----------|------------------|
13+
| BDA Discovery | `patterns/pattern-1/src/bda_discovery_function` | `lambda-bda-discovery` |
14+
| BDA Invoke | `patterns/pattern-1/src/bda_invoke_function` | `lambda-bda-invoke` |
15+
| BDA Completion | `patterns/pattern-1/src/bda_completion_function` | `lambda-bda-completion` |
16+
| Summarization | `patterns/pattern-1/src/summarization_function` | `lambda-summarization` |
17+
| Process Results | `patterns/pattern-1/src/processresults_function` | `lambda-process-results` |
18+
| HITL Process | `patterns/pattern-1/src/hitl-process-function` | `lambda-hitl` |
19+
| HITL Status Update | `patterns/pattern-1/src/hitl-status-update-function` | `lambda-hitl` |
20+
| HITL Wait | `patterns/pattern-1/src/hitl-wait-function` | `lambda-hitl` |
21+
22+
## Pattern 2 Lambdas (Bedrock)
23+
24+
| Lambda Function | Directory | Dependency Group |
25+
|----------------|-----------|------------------|
26+
| OCR | `patterns/pattern-2/src/ocr_function` | `lambda-ocr` |
27+
| Classification | `patterns/pattern-2/src/classification_function` | `lambda-classification` |
28+
| Extraction | `patterns/pattern-2/src/extraction_function` | `lambda-extraction` |
29+
| Assessment | `patterns/pattern-2/src/assessment_function` | `lambda-assessment` |
30+
| Summarization | `patterns/pattern-2/src/summarization_function` | `lambda-summarization` |
31+
| Process Results | `patterns/pattern-2/src/processresults_function` | `lambda-process-results` |
32+
| HITL Process | `patterns/pattern-2/src/hitl-process-function` | `lambda-hitl` |
33+
| HITL Status Update | `patterns/pattern-2/src/hitl-status-update-function` | `lambda-hitl` |
34+
| HITL Wait | `patterns/pattern-2/src/hitl-wait-function` | `lambda-hitl` |
35+
36+
## Pattern 3 Lambdas (UDOP)
37+
38+
| Lambda Function | Directory | Dependency Group |
39+
|----------------|-----------|------------------|
40+
| OCR | `patterns/pattern-3/src/ocr_function` | `lambda-ocr` |
41+
| Classification | `patterns/pattern-3/src/classification_function` | `lambda-classification` |
42+
| Extraction | `patterns/pattern-3/src/extraction_function` | `lambda-extraction` |
43+
| Assessment | `patterns/pattern-3/src/assessment_function` | `lambda-assessment` |
44+
| Summarization | `patterns/pattern-3/src/summarization_function` | `lambda-summarization` |
45+
| Process Results | `patterns/pattern-3/src/processresults_function` | `lambda-process-results` |
46+
47+
## Main Lambdas (src/lambda)
48+
49+
| Lambda Function | Directory | Dependency Group |
50+
|----------------|-----------|------------------|
51+
| Agent Processor | `src/lambda/agent_processor` | `lambda-agent-processor` |
52+
| Agent Request Handler | `src/lambda/agent_request_handler` | `lambda-agent-request` |
53+
| Chat with Document | `src/lambda/chat_with_document_resolver` | `lambda-chat-document` |
54+
| Configuration Resolver | `src/lambda/configuration_resolver` | `lambda-configuration` |
55+
| Copy to Baseline | `src/lambda/copy_to_baseline_resolver` | `lambda-document-resolver` |
56+
| Create Document | `src/lambda/create_document_resolver` | `lambda-document-resolver` |
57+
| Dashboard Merger | `src/lambda/dashboard_merger` | `lambda-dashboard` |
58+
| Delete Document | `src/lambda/delete_document_resolver` | `lambda-document-resolver` |
59+
| Discovery Processor | `src/lambda/discovery_processor` | `lambda-discovery-processor` |
60+
| Discovery Upload | `src/lambda/discovery_upload_resolver` | `lambda-document-resolver` |
61+
| Evaluation | `src/lambda/evaluation_function` | `lambda-evaluation` |
62+
| Get File Contents | `src/lambda/get_file_contents_resolver` | `lambda-document-resolver` |
63+
| Process Changes | `src/lambda/process_changes_resolver` | `lambda-document-resolver` |
64+
| Queue Processor | `src/lambda/queue_processor` | `lambda-queue` |
65+
| Queue Sender | `src/lambda/queue_sender` | `lambda-queue` |
66+
| Reprocess Document | `src/lambda/reprocess_document_resolver` | `lambda-document-resolver` |
67+
| Cognito Updater HITL | `src/lambda/cognito_updater_hitl` | `lambda-cognito` |
68+
| IPSet Updater | `src/lambda/ipset_updater` | `lambda-ipset` |
69+
| Initialize Counter | `src/lambda/initialize_counter` | `lambda-minimal` |
70+
| Save Reporting Data | `src/lambda/save_reporting_data` | `lambda-minimal` |
71+
| Get Workforce URL | `src/lambda/get-workforce-url` | `lambda-minimal` |
72+
| Create A2I Resources | `src/lambda/create_a2i_resources` | `lambda-minimal` |
73+
| Get StepFunction Execution | `src/lambda/get_stepfunction_execution_resolver` | `lambda-document-resolver` |
74+
| List Available Agents | `src/lambda/list_available_agents` | `lambda-document-resolver` |
75+
| Lookup Function | `src/lambda/lookup_function` | `lambda-document-resolver` |
76+
| Start CodeBuild | `src/lambda/start_codebuild` | `lambda-minimal` |
77+
| Update Configuration | `src/lambda/update_configuration` | `lambda-configuration` |
78+
| Update Settings | `src/lambda/update_settings` | `lambda-document-resolver` |
79+
| Workflow Tracker | `src/lambda/workflow_tracker` | `lambda-document-resolver` |
80+
81+
## Makefile Template
82+
83+
Each lambda directory should have a `Makefile` with the following structure:
84+
85+
```makefile
86+
# Makefile for <FunctionName>
87+
build-<FunctionName>:
88+
uv pip install --target "$(ARTIFACTS_DIR)" --python 3.12 "../../../..[<dependency-group>]"
89+
cp *.py "$(ARTIFACTS_DIR)/"
90+
rm -rf "$(ARTIFACTS_DIR)"/__pycache__
91+
92+
.PHONY: build-<FunctionName>
93+
```
94+
95+
Example for OCR Function:
96+
97+
```makefile
98+
# Makefile for OCRFunction
99+
build-OCRFunction:
100+
uv pip install --target "$(ARTIFACTS_DIR)" --python 3.12 "../../../../[lambda-ocr]"
101+
cp *.py "$(ARTIFACTS_DIR)/"
102+
rm -rf "$(ARTIFACTS_DIR)"/__pycache__
103+
104+
.PHONY: build-OCRFunction
105+
```
106+
107+
## SAM Template Metadata
108+
109+
Each Lambda in the SAM template must include:
110+
111+
```yaml
112+
Metadata:
113+
BuildMethod: makefile
114+
```
115+
116+
## Adding a New Lambda
117+
118+
1. Add the lambda's dependency group to `/pyproject.toml` under `[dependency-groups]`
119+
2. Run `uv lock` to update the lock file
120+
3. Create a `Makefile` in the lambda directory
121+
4. Update the SAM template with `BuildMethod: makefile` metadata
122+
5. Add entry to this documentation
123+
124+
## Updating Dependencies
125+
126+
To update dependencies for a lambda:
127+
128+
1. Edit the dependency group in `/pyproject.toml`
129+
2. Run `uv lock` to update the lock file
130+
3. Rebuild the lambda: `sam build <FunctionName>`

idp_cli/pyproject.toml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
# SPDX-License-Identifier: MIT-0
33

44
[build-system]
5-
requires = ["setuptools>=64", "wheel"]
6-
build-backend = "setuptools.build_meta"
5+
requires = ["hatchling"]
6+
build-backend = "hatchling.build"
77

88
[project]
99
name = "idp-cli"
1010
version = "1.0.0"
1111
description = "Command-line interface for IDP Accelerator batch document processing"
12-
authors = [{name = "AWS"}]
12+
authors = [{name = "AWS", email = "[email protected]"}]
13+
readme = "README.md"
1314
license = {text = "MIT-0"}
1415
requires-python = ">=3.9"
1516
classifiers = [
@@ -39,8 +40,13 @@ test = [
3940
[project.scripts]
4041
idp-cli = "idp_cli.cli:main"
4142

42-
[tool.setuptools]
43+
[project.urls]
44+
Homepage = "https://github.com/aws-samples/accelerated-intelligent-document-processing-on-aws"
45+
46+
# Hatchling configuration
47+
[tool.hatch.build.targets.wheel]
4348
packages = ["idp_cli"]
4449

45-
[tool.setuptools.package-dir]
46-
idp_cli = "idp_cli"
50+
# UV configuration
51+
[tool.uv]
52+
package = true

0 commit comments

Comments
 (0)