diff --git a/.circleci/config.yml b/.circleci/config.yml index 706e8e41..282842da 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,11 @@ version: 2.1 orbs: python: circleci/python@2.1.1 +commands: + install_uv: + steps: + - run: pip install --upgrade uv">=0.4.27,<0.5.0" + jobs: install_and_update_dependencies: docker: @@ -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 @@ -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 @@ -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/ @@ -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 \ @@ -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 \ @@ -182,7 +189,7 @@ 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 \ @@ -190,10 +197,10 @@ jobs: - 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 \ @@ -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: | diff --git a/Makefile b/Makefile index dbb74be2..94f66463 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/scripts/format.sh b/scripts/format.sh index 0f425227..ac3fe061 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -1,4 +1,4 @@ #!/bin/bash set -euxo pipefail -pipenv run ruff format . --check +uv run ruff format . --check diff --git a/scripts/lint.sh b/scripts/lint.sh index a7e4d875..af649f0e 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -1,4 +1,4 @@ #!/bin/bash set -euxo pipefail -pipenv run ruff check . +uv run ruff check . diff --git a/thumbs/Makefile b/thumbs/Makefile index 3ae0e19d..3f962822 100644 --- a/thumbs/Makefile +++ b/thumbs/Makefile @@ -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