Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,19 @@ cython_debug/
output/

# MacOS files
.DS_Store
.DS_Store

# AWS SAM build artifacts
.aws-sam/

.github


.venv/
.git/
__pycache__/
*.pyc
.pytest_cache/
tests/
.env
.mypy_cache/
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ name: CI
on: push
jobs:
test:
uses: mitlibraries/.github/.github/workflows/python-shared-test.yml@main
uses: mitlibraries/.github/.github/workflows/python-uv-shared-test.yml@main
lint:
uses: mitlibraries/.github/.github/workflows/python-shared-lint.yml@main
uses: mitlibraries/.github/.github/workflows/python-uv-shared-lint.yml@main
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ dmypy.json
.vscode/

# jetbrains
.idea/
.idea/

# SAM
.aws-sam/
tests/sam/env.json
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
default_language_version:
python: python3.12 # set for project python version
python: python3.14 # set for project python version
repos:
- repo: local
hooks:
- id: black-apply
name: black-apply
entry: pipenv run black
entry: uv run black
language: system
pass_filenames: true
types: ["python"]
- id: mypy
name: mypy
entry: pipenv run mypy
entry: uv run mypy
language: system
pass_filenames: true
types: ["python"]
exclude: "tests/"
- id: ruff-apply
name: ruff-apply
entry: pipenv run ruff check --fix
entry: uv run ruff check --fix
language: system
pass_filenames: true
types: ["python"]
- id: pip-audit
name: pip-audit
entry: pipenv run pip-audit
language: system
pass_filenames: false
# - id: pip-audit
# name: pip-audit
# entry: uv run pip-audit
# language: system
# pass_filenames: false
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.12
3.14
23 changes: 15 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
FROM public.ecr.aws/lambda/python:3.12
# ---- Build stage ----
FROM public.ecr.aws/lambda/python:3.14 AS builder

COPY --from=ghcr.io/astral-sh/uv:0.10.7 /uv /uvx /bin/

COPY pyproject.toml uv.lock ${LAMBDA_TASK_ROOT}/

RUN cd ${LAMBDA_TASK_ROOT} && \
uv export --format requirements-txt --no-hashes --no-dev > requirements.txt && \
uv pip install -r requirements.txt --target "${LAMBDA_TASK_ROOT}" --no-cache --system

# Copy function code
COPY . ${LAMBDA_TASK_ROOT}/

# Install dependencies
RUN pip3 install pipenv
RUN pipenv requirements > requirements.txt
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
# ---- Runtime stage ----
FROM public.ecr.aws/lambda/python:3.14

COPY --from=builder ${LAMBDA_TASK_ROOT} ${LAMBDA_TASK_ROOT}

# Default handler. See README for how to override to a different handler.
CMD [ "lambdas.my_function.lambda_handler" ]
CMD ["lambdas.my_function.lambda_handler"]
70 changes: 47 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,77 @@ help: # Preview Makefile commands
@awk 'BEGIN { FS = ":.*#"; print "Usage: make <target>\n\nTargets:" } \
/^[-_[:alpha:]]+:.?*#/ { printf " %-15s%s\n", $$1, $$2 }' $(MAKEFILE_LIST)

#######################
# Dependency commands
#######################
# ensure OS binaries aren't called if naming conflict with Make recipes
.PHONY: help venv install update test coveralls lint black mypy ruff safety lint-apply black-apply ruff-apply

install: # Install Python dependencies
pipenv install --dev
pipenv run pre-commit install
##############################################
# Python Environment and Dependency commands
##############################################

update: install # Update Python dependencies
pipenv clean
pipenv update --dev
install: .venv .git/hooks/pre-commit # Install Python dependencies, hooks, and create virtual environment if not exists
uv sync --dev

.venv: # Creates virtual environment if not found
@echo "Creating virtual environment at .venv..."
uv venv .venv

.git/hooks/pre-commit: # Sets up pre-commit hook if not setup
@echo "Installing pre-commit hooks..."
uv run pre-commit install

venv: .venv # Create the Python virtual environment

update: # Update Python dependencies
uv lock --upgrade
uv sync --dev

######################
# Unit test commands
######################

test: # Run tests and print a coverage report
pipenv run coverage run --source=lambdas -m pytest -vv
pipenv run coverage report -m
uv run coverage run --source=lambdas -m pytest -vv
uv run coverage report -m

coveralls: test # Write coverage data to an LCOV report
pipenv run coverage lcov -o ./coverage/lcov.info
uv run coverage lcov -o ./coverage/lcov.info

####################################
# Code quality and safety commands
####################################

lint: black mypy ruff safety # Run linters
lint: black mypy ruff # Run linters

black: # Run 'black' linter and print a preview of suggested changes
pipenv run black --check --diff .
uv run black --check --diff .

mypy: # Run 'mypy' linter
pipenv run mypy .
uv run mypy .

ruff: # Run 'ruff' linter and print a preview of errors
pipenv run ruff check .
uv run ruff check .

safety: # Check for security vulnerabilities and verify Pipfile.lock is up-to-date
pipenv run pip-audit
pipenv verify
safety: # Check for security vulnerabilities
uv run pip-audit

lint-apply: # Apply changes with 'black' and resolve 'fixable errors' with 'ruff'
black-apply ruff-apply
lint-apply: black-apply ruff-apply # Apply changes with 'black' and resolve 'fixable errors' with 'ruff'

black-apply: # Apply changes with 'black'
pipenv run black .
uv run black .

ruff-apply: # Resolve 'fixable errors' with 'ruff'
pipenv run ruff check --fix .
uv run ruff check --fix .

####################################
# SAM Lambda
####################################
sam-build: # Build SAM image for running Lambda locally
sam build --template tests/sam/template.yaml

sam-http-run: # Run lambda locally as an HTTP server
sam local start-api --template tests/sam/template.yaml --env-vars tests/sam/env.json

sam-http-ping: # Send curl command to SAM HTTP server
curl --location 'http://localhost:3000/myapp' \
--header 'Content-Type: application/json' \
--data '{"msg":"in a bottle"}'
19 changes: 0 additions & 19 deletions Pipfile

This file was deleted.

Loading