-
Notifications
You must be signed in to change notification settings - Fork 0
IN-1298 - Spike to replace pipenv with uv #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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.13 # 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 | ||
| entry: uv run pip-audit | ||
| language: system | ||
| pass_filenames: false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 3.12 | ||
| 3.13 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,15 @@ | ||
| FROM public.ecr.aws/lambda/python:3.12 | ||
| FROM public.ecr.aws/lambda/python:3.13 | ||
|
|
||
| # Copy function code | ||
| # Install uv | ||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ | ||
|
|
||
| # Copy project files | ||
| 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}" | ||
| 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}" --system | ||
|
|
||
| # Default handler. See README for how to override to a different handler. | ||
| CMD [ "lambdas.my_function.lambda_handler" ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,28 +5,40 @@ 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 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 | ||
|
Comment on lines
+15
to
+30
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is 50/50 new functionality from When running Similar story for pre-commit. The net effect is that |
||
|
|
||
| ###################### | ||
| # 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 | ||
|
|
@@ -35,23 +47,21 @@ coveralls: test # Write coverage data to an LCOV report | |
| lint: black mypy ruff safety # 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 . | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commenting here arbitraily: nice example of |
||
|
|
||
| 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 . | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the
pipenvapproach was using a--targetargument to install the libraries in a specific place.For
uv, the equivalant is usinguv pipwhich provides a more pip-like API for specific tasks, in this case installing to a specific location instead of the active virtual environment.I believe there are alternatives to how we could construct the python environment for AWS lambdas, but this approach is readily understandable and conceptually mirrors our previous approach.
Some flags:
--no-hashes: excludes hashes from library versions where the version may be the same but the hash changes; which can wreak havoc with Docker layers--no-dev: skips thedevgroup of dependencies