Skip to content

Commit

Permalink
Replace pipenv with UV in CircleCI config
Browse files Browse the repository at this point in the history
  • Loading branch information
symroe committed Dec 2, 2024
1 parent e01f452 commit 4f7524f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 50 deletions.
86 changes: 46 additions & 40 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ version: 2.1
orbs:
python: circleci/[email protected]

commands:
install_uv:
steps:
- run: pip install --upgrade uv">=0.4.27,<0.5.0"

jobs:
install_and_update_dependencies:
docker:
Expand All @@ -13,36 +18,36 @@ jobs:
- checkout
- restore_cache:
keys:
- v8-dependencies-{{ checksum "Pipfile.lock" }}-{{ checksum "thumbs/Pipfile.lock" }}
- v8-dependencies-default
# Ensure pip and pipenv are installed
- run:
name: Install pipenv
command: |
pip install --upgrade pipenv==2024.0.1 pip --quiet --no-input
- v9-dependencies-{{ checksum "uv.lock" }}
- v9-dependencies-default
- install_uv
- run:
name: Set up virtual environment
command: |
pipenv sync --dev
uv sync --dev --no-python-downloads
- run: pipenv run ruff check .
- run: ./scripts/lint.sh
- run: ./scripts/format.sh
- run: make lambda-layers/DependenciesLayer/requirements.txt
- run: npm install
- run: npm run build
- run: pipenv run collectstatic --settings electionleaflets.settings.testing
- run: uv run python manage.py collectstatic --settings electionleaflets.settings.testing
- persist_to_workspace:
root: ~/repo/
paths:
- lambda-layers/DependenciesLayer/requirements.txt
- electionleaflets/static/
- electionleaflets/assets/
- run:
name: Prune UV cache
command: uv cache prune --ci
- save_cache:
when: on_success
paths:
- ~/.local/share/virtualenvs/
key: v8-dependencies-{{ checksum "Pipfile.lock" }}-{{ checksum "thumbs/Pipfile.lock" }}
- ./.venv
- ./node_modules
- $HOME/.cache/uv
key: v9-dependencies-{{ checksum "uv.lock" }}
run-tests:
docker:
- image: cimg/python:3.12-browsers
Expand All @@ -62,20 +67,20 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v8-dependencies-{{ checksum "Pipfile.lock" }}
- run: pipenv run pipenv verify

- run: pipenv run python manage.py check
- v9-dependencies-{{ checksum "uv.lock" }}
- install_uv
- run: uv sync --no-python-downloads
- run: uv run python manage.py check

# TODO: enable this once we drop uk_political_parties package
#- run: pipenv run python manage.py makemigrations --check
#- run: uv run python manage.py makemigrations --check

# Run tests
- run: pipenv run playwright install --with-deps chromium
- run: uv run playwright install --with-deps chromium
- run:
name: Run tests
command: |
pipenv run pytest
uv run pytest
- store_artifacts:
path: test-results
destination: test-results
Expand All @@ -90,10 +95,10 @@ jobs:
- checkout
- attach_workspace:
at: ~/repo/
- run: pip install --upgrade pip
- run: pip install -r deploy-requirements.txt
- run: pip install -r lambda-layers/DependenciesLayer/requirements.txt
- run: sam build ${DASH_DASH_DEBUG}
- install_uv
- run: uv sync --only-group deploy --no-python-downloads
- run: make lambda-layers/DependenciesLayer/requirements.txt
- run: sam build

- persist_to_workspace:
root: ~/repo/
Expand Down Expand Up @@ -128,22 +133,22 @@ jobs:
at: ~/repo/
- restore_cache:
keys:
- v8-dependencies-{{ checksum "Pipfile.lock" }}
- v8-dependencies-default
- v9-dependencies-{{ checksum "uv.lock" }}
- v9-dependencies-default
- run:
name: Install pipenv
name: Install UV
command: |
pip install --upgrade pipenv==2024.0.1 pip --quiet --no-input
- run: pip install -r deploy-requirements.txt
pip install --upgrade uv">=0.4.27,<0.5.0" --quiet --no-input
- run: uv sync --only-group deploy --no-python-downloads
- run: printenv DC_DEPLOY_NAME DJANGO_SETTINGS_MODULE SAM_CONFIG_FILE DC_ENVIRONMENT SAM_PUBLIC_CONFIG_ENV
- run: printenv SECRET_KEY | md5sum
- run: printenv AWS_ACCESS_KEY_ID | md5sum
- run: sudo apt update && sudo apt install postgresql-client
- run: PGPASSWORD=$DATABASE_PASS createdb --host $DATABASE_HOST --username $DATABASE_USER $POSTGRES_DATABASE_NAME || true
- run:
name: "pipenv run sam deploy # App: Lambda + API Gateway"
name: "sam deploy # App: Lambda + API Gateway"
command: |
sam deploy ${DASH_DASH_DEBUG} \
uv run sam deploy ${DASH_DASH_DEBUG} \
--config-file ~/repo/${SAM_CONFIG_FILE} \
--config-env $DC_ENVIRONMENT \
--template-file ~/repo/.aws-sam/build/template.yaml \
Expand All @@ -161,18 +166,20 @@ jobs:
AppDomain='$PUBLIC_FQDN' \
AppLeafletImagesBucketName='$LEAFLET_IMAGES_BUCKET_NAME' \
"
- run: pipenv run migratedb
- run: pipenv run createcachetable
- run: uv run python manage.py migrate
- run: uv run python manage.py createcachetable
- run: printenv LEAFLET_IMAGES_BUCKET_NAME
- run: echo $LEAFLET_IMAGES_BUCKET_NAME > thumbs/LEAFLET_IMAGES_BUCKET_NAME
- run: make thumbs/requirements.txt
- run: pipenv run thumbs_sam_build
- run: pipenv run sam validate --region eu-west-2
- run: |
cd thumbs
uv run sam build
- run: uv run sam validate --region eu-west-2

- run:
name: "Deploy thumbs function"
command: |
pipenv run sam deploy ${DASH_DASH_DEBUG} \
uv run sam deploy ${DASH_DASH_DEBUG} \
--config-file ~/repo/thumbs/${SAM_CONFIG_FILE} \
--config-env $DC_ENVIRONMENT \
--template-file ~/repo/thumbs/.aws-sam/build/ThumbsFunction/template.yml \
Expand All @@ -182,18 +189,18 @@ jobs:
- run:
name: "Deploy thumbs function to eu-west-1 for lambda@edge"
command: |
pipenv run sam deploy ${DASH_DASH_DEBUG} \
uv run sam deploy ${DASH_DASH_DEBUG} \
--config-file ~/repo/thumbs/${SAM_CONFIG_FILE} \
--config-env $DC_ENVIRONMENT \
--template-file ~/repo/thumbs/.aws-sam/build/ThumbsFunction/template.yml \
--region us-east-1
- run:
name: "pipenv run sam deploy # Public access: CDN + DNS"
name: "uv run sam deploy # Public access: CDN + DNS"
no_output_timeout: 20m # CloudFront can take longer than CircleCI's 10m default
command: |
pipenv run sam deploy ${DASH_DASH_DEBUG} \
uv run sam deploy ${DASH_DASH_DEBUG} \
--config-file ~/repo/${SAM_CONFIG_FILE} \
--config-env $SAM_PUBLIC_CONFIG_ENV \
--template-file ~/repo/public-access-template.yaml \
Expand All @@ -203,8 +210,7 @@ jobs:
PublicFqdn=$PUBLIC_FQDN \
LeafletsBucketName=$LEAFLET_IMAGES_BUCKET_NAME
"
- run: pip install -U boto3 pipenv==2024.0.1 --quiet --no-input
- run: python thumbs/attach_lambda_triggers.py
- run: uv run python thumbs/attach_lambda_triggers.py
- run:
name: "Publish a new Sentry Release"
command: |
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ clean: ## Delete any generated static asset or req.txt files and git-restore the

.PHONY: collectstatic
collectstatic: ## Rebuild the static assets
python manage.py collectstatic --noinput --clear
uv run python manage.py collectstatic --noinput --clear

lambda-layers/DependenciesLayer:
mkdir -p $@

lambda-layers/DependenciesLayer/requirements.txt: Pipfile Pipfile.lock lambda-layers/DependenciesLayer lambda-layers/DependenciesLayer ## Update the requirements.txt file used to build this Lambda function's DependenciesLayer
pipenv requirements | sed "s/^-e //" >lambda-layers/DependenciesLayer/requirements.txt
lambda-layers/DependenciesLayer/requirements.txt: pyproject.toml uv.lock lambda-layers/DependenciesLayer lambda-layers/DependenciesLayer ## Update the requirements.txt file used to build this Lambda function's DependenciesLayer
uv export --no-hashes --no-dev > lambda-layers/DependenciesLayer/requirements.txt

thumbs/requirements.txt: thumbs/Pipfile thumbs/Pipfile.lock ## Update the requirements.txt file used to build this Lambda function's DependenciesLayer
cd thumbs && pipenv requirements | sed "s/^-e //" >requirements.txt
thumbs/requirements.txt: thumbs/pyproject.toml uv.lock ## Update the requirements.txt file used to build this Lambda function's DependenciesLayer
uv export --no-hashes --project thumbs > thumbs/requirements.txt

.PHONY: help
# gratuitously adapted from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
Expand Down
2 changes: 1 addition & 1 deletion scripts/format.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -euxo pipefail

pipenv run ruff format . --check
uv run ruff format . --check
2 changes: 1 addition & 1 deletion scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -euxo pipefail

pipenv run ruff check .
uv run ruff check .
3 changes: 0 additions & 3 deletions thumbs/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
requirements.txt: pyproject.toml
uv pip freeze > requirements.txt

.package: requirements.txt
rm -rf .package
pip install --requirement requirements.txt --target .package
Expand Down

0 comments on commit 4f7524f

Please sign in to comment.