Skip to content

Commit 44bfef4

Browse files
committed
Replace pipenv with uv
Why these changes are being introduced: uv is a modern python project and dependency manager with increasingly attractive features and community support. By contrast, pipenv is feeling a bit stale in terms of features, community support, and even performance. Additionally, without going into great detail here, uv is part of a larger ecocsystem of python tooling that work very well together, including uv, ruff, and ty (type checking). How this addresses that need: * Virtually anywhere pipenv was used, uv is now used * Makefile updated to use uv * Makefile installation recipes updated to utilize uv best * Dockerfile updated to align with uv installation approaches Side effects of this change: * Before this template code can be used by a project, Github actions will need to be updated to intelligently use pipenv or uv depending on the project as we incrementally convert them. Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/IN-1298
1 parent 6341bc7 commit 44bfef4

File tree

9 files changed

+884
-823
lines changed

9 files changed

+884
-823
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
default_language_version:
2-
python: python3.12 # set for project python version
2+
python: python3.13 # set for project python version
33
repos:
44
- repo: local
55
hooks:
66
- id: black-apply
77
name: black-apply
8-
entry: pipenv run black
8+
entry: uv run black
99
language: system
1010
pass_filenames: true
1111
types: ["python"]
1212
- id: mypy
1313
name: mypy
14-
entry: pipenv run mypy
14+
entry: uv run mypy
1515
language: system
1616
pass_filenames: true
1717
types: ["python"]
1818
exclude: "tests/"
1919
- id: ruff-apply
2020
name: ruff-apply
21-
entry: pipenv run ruff check --fix
21+
entry: uv run ruff check --fix
2222
language: system
2323
pass_filenames: true
2424
types: ["python"]
2525
- id: pip-audit
2626
name: pip-audit
27-
entry: pipenv run pip-audit
27+
entry: uv run pip-audit
2828
language: system
2929
pass_filenames: false

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.12
1+
3.13

Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
FROM public.ecr.aws/lambda/python:3.12
1+
FROM public.ecr.aws/lambda/python:3.13
22

3-
# Copy function code
3+
# Install uv
4+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
5+
6+
# Copy project files
47
COPY . ${LAMBDA_TASK_ROOT}/
58

69
# Install dependencies
7-
RUN pip3 install pipenv
8-
RUN pipenv requirements > requirements.txt
9-
RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}"
10+
RUN cd ${LAMBDA_TASK_ROOT} && \
11+
uv export --format requirements-txt --no-hashes --no-dev > requirements.txt && \
12+
uv pip install -r requirements.txt --target "${LAMBDA_TASK_ROOT}" --system
1013

1114
# Default handler. See README for how to override to a different handler.
1215
CMD [ "lambdas.my_function.lambda_handler" ]

Makefile

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@ help: # Preview Makefile commands
55
@awk 'BEGIN { FS = ":.*#"; print "Usage: make <target>\n\nTargets:" } \
66
/^[-_[:alpha:]]+:.?*#/ { printf " %-15s%s\n", $$1, $$2 }' $(MAKEFILE_LIST)
77

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

12-
install: # Install Python dependencies
13-
pipenv install --dev
14-
pipenv run pre-commit install
11+
##############################################
12+
# Python Environment and Dependency commands
13+
##############################################
1514

16-
update: install # Update Python dependencies
17-
pipenv clean
18-
pipenv update --dev
15+
install: .venv .git/hooks/pre-commit # Install Python dependencies and create virtual environment if not exists
16+
uv sync --dev
17+
18+
.venv: # Creates virtual environment if not found
19+
@echo "Creating virtual environment at .venv..."
20+
uv venv .venv
21+
22+
.git/hooks/pre-commit: # Sets up pre-commit hook if not setup
23+
@echo "Installing pre-commit hooks..."
24+
uv run pre-commit install
25+
26+
venv: .venv # Create the Python virtual environment
27+
28+
update: # Update Python dependencies
29+
uv lock --upgrade
30+
uv sync --dev
1931

2032
######################
2133
# Unit test commands
2234
######################
2335

2436
test: # Run tests and print a coverage report
25-
pipenv run coverage run --source=lambdas -m pytest -vv
26-
pipenv run coverage report -m
37+
uv run coverage run --source=lambdas -m pytest -vv
38+
uv run coverage report -m
2739

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

3143
####################################
3244
# Code quality and safety commands
@@ -35,23 +47,21 @@ coveralls: test # Write coverage data to an LCOV report
3547
lint: black mypy ruff safety # Run linters
3648

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

4052
mypy: # Run 'mypy' linter
41-
pipenv run mypy .
53+
uv run mypy .
4254

4355
ruff: # Run 'ruff' linter and print a preview of errors
44-
pipenv run ruff check .
56+
uv run ruff check .
4557

46-
safety: # Check for security vulnerabilities and verify Pipfile.lock is up-to-date
47-
pipenv run pip-audit
48-
pipenv verify
58+
safety: # Check for security vulnerabilities
59+
uv run pip-audit
4960

50-
lint-apply: # Apply changes with 'black' and resolve 'fixable errors' with 'ruff'
51-
black-apply ruff-apply
61+
lint-apply: black-apply ruff-apply # Apply changes with 'black' and resolve 'fixable errors' with 'ruff'
5262

5363
black-apply: # Apply changes with 'black'
54-
pipenv run black .
64+
uv run black .
5565

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

Pipfile

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)