From 03e75801954ff60095d028a2a33d223c38d863cb Mon Sep 17 00:00:00 2001 From: Dave O'Connor Date: Wed, 18 Mar 2026 14:49:17 -0700 Subject: [PATCH] feat: auto-update Python version on copier generation --- copier.yml | 1 + template/.github/workflows/main.yaml | 2 +- template/Makefile | 2 +- template/backend/Dockerfile | 4 ++-- template/bitbucket-pipelines.yml | 2 +- template/k8s/base/app.configmap.yaml | 2 +- template/scripts/update-python-version.sh | 29 +++++++++++++++++++++++ 7 files changed, 36 insertions(+), 6 deletions(-) create mode 100755 template/scripts/update-python-version.sh diff --git a/copier.yml b/copier.yml index ab9b9e0..86c0799 100644 --- a/copier.yml +++ b/copier.yml @@ -3,6 +3,7 @@ _templates_suffix: "" _tasks: - python tasks.py + - bash scripts/update-python-version.sh _subdirectory: template diff --git a/template/.github/workflows/main.yaml b/template/.github/workflows/main.yaml index a2de256..5a2afbf 100644 --- a/template/.github/workflows/main.yaml +++ b/template/.github/workflows/main.yaml @@ -58,7 +58,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: "3.14" - name: Run backend tests run: CI=true make backend-test env: diff --git a/template/Makefile b/template/Makefile index 0d5939c..c1588ee 100644 --- a/template/Makefile +++ b/template/Makefile @@ -106,7 +106,7 @@ pipdeptree: ## Show the dependencies of installed packages as a tree structure $(KUBECTL_EXEC_BACKEND) -c "uv pip tree --no-cache" compile: backend/requirements/base.in backend/requirements/tests.in ## compile latest requirements to be built into the docker image - @docker run --rm -v $(shell pwd)/backend/requirements:/local python:3.13-slim /bin/bash -c \ + @docker run --rm -v $(shell pwd)/backend/requirements:/local python:3.14-slim /bin/bash -c \ "apt-get update; apt-get install -y libpq-dev; \ pip install uv; \ touch /local/base.txt; touch /local/production.txt; touch /local/tests.txt; touch /local/local.txt; \ diff --git a/template/backend/Dockerfile b/template/backend/Dockerfile index eba3639..8483cc2 100644 --- a/template/backend/Dockerfile +++ b/template/backend/Dockerfile @@ -1,5 +1,5 @@ # Build all of the dependencies then we will build the actual application image -FROM python:3.13-slim AS build +FROM python:3.14-slim AS build ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 @@ -54,7 +54,7 @@ RUN set -x \ -r /tmp/requirements/tests.txt; fi # Now we can build the application image -FROM python:3.13-slim +FROM python:3.14-slim ENV PYTHONUNBUFFERED=1 ENV PYTHONPATH="/app" diff --git a/template/bitbucket-pipelines.yml b/template/bitbucket-pipelines.yml index aa97b25..5e1e7ab 100644 --- a/template/bitbucket-pipelines.yml +++ b/template/bitbucket-pipelines.yml @@ -1,4 +1,4 @@ -image: python:3.12 +image: python:3.14 definitions: services: diff --git a/template/k8s/base/app.configmap.yaml b/template/k8s/base/app.configmap.yaml index 685be10..d0cbdc1 100644 --- a/template/k8s/base/app.configmap.yaml +++ b/template/k8s/base/app.configmap.yaml @@ -18,7 +18,7 @@ data: # todo: see if PYDEVD_USE_* can be removed later, I was getting this error # with pydevd-pycharm==243.26053.29: # cannot import name 'trace_dispatch' from '_pydevd_bundle.pydevd_trace_dispatch' - # (/app/lib/python3.12/site-packages/_pydevd_bundle/pydevd_trace_dispatch.py) + # (/app/lib/python3.14/site-packages/_pydevd_bundle/pydevd_trace_dispatch.py) # Also probably need to add cython to local.in in that case. PYDEVD_USE_CYTHON: "NO" PYDEVD_USE_FRAME_EVAL: "NO" diff --git a/template/scripts/update-python-version.sh b/template/scripts/update-python-version.sh new file mode 100755 index 0000000..827d9d7 --- /dev/null +++ b/template/scripts/update-python-version.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Kept as a single script so the Docker Hub API is called once and the resolved +# version is shared across all file updates without needing a temp file. + +tags=$(curl -fsSL "https://registry.hub.docker.com/v2/repositories/library/python/tags?page_size=100") + +minor=$(echo "$tags" | jq -r ' + [.results[].name | select(test("^[0-9]+\\.[0-9]+-slim$")) | rtrimstr("-slim")] + | map(split(".") | map(tonumber)) + | max_by(.[0] * 1000 + .[1]) + | join(".") +') + +full=$(echo "$tags" | jq -r --arg minor "$minor" ' + [.results[].name | select(test("^" + $minor + "\\.[0-9]+-slim$")) | rtrimstr("-slim")] + | map(split(".") | map(tonumber)) + | if length > 0 then max_by(.[2]) | join(".") else $minor end +') + +echo "Updating Python version to ${minor} (Docker: ${full})" + +update() { if [ -f "$1" ]; then sed -i "${@:2}" "$1"; fi; } + +update backend/Dockerfile "s|python:[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?-slim|python:${full}-slim|g" +update Makefile "s|python:[0-9]\+\.[0-9]\+\(\.[0-9]\+\)\?-slim|python:${full}-slim|g" # not in django-template +update bitbucket-pipelines.yml "s|image: python:[0-9]\+\.[0-9]\+|image: python:${minor}|g" # not in django-template +update .github/workflows/main.yaml "s|python-version: \"[0-9]\+\.[0-9]\+\"|python-version: \"${minor}\"|g" # not in django-template