From d99abdc174501306c24b2efcf2c194f3eba2bea7 Mon Sep 17 00:00:00 2001 From: "Xuan (Sean) Hu" Date: Thu, 7 Mar 2024 10:37:15 +0800 Subject: [PATCH] chore: fix Python 3.8 compatibility issue (#368) --- .devcontainer/Dockerfile | 12 ++++++++++-- .renovaterc.json | 10 +++++++++- template/.devcontainer/Dockerfile.jinja | 12 ++++++++++-- template/.renovaterc.json.jinja | 11 ++++++++++- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 971d8b2a..9cd5a56a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -6,6 +6,10 @@ ARG PYTHON_VERSION=3.12 FROM python:${PYTHON_VERSION} as dev +# NOTE: python docker image has env `PYTHON_VERSION` but with patch version. +# ARG is used here for temporary override without changing the original env. +ARG PYTHON_VERSION + RUN apt-get update && apt-get install -y --no-install-recommends \ # pipx: To install Python applications. pipx \ @@ -22,7 +26,11 @@ ENV PIPX_DEFAULT_PYTHON=/usr/local/bin/python RUN pipx install pdm==2.12.4 # Install pre-commit -RUN pipx install pre-commit==3.6.2 +RUN if [ "${PYTHON_VERSION}" = "3.8" ]; then \ + pipx install pre-commit==3.5.0; \ + else \ + pipx install pre-commit==3.6.2; \ + fi # Create a non-root user with sudo permission ARG USERNAME=ss-python @@ -60,7 +68,7 @@ FROM python:${PYTHON_VERSION}-slim as prod # NOTE: python docker image has env `PYTHON_VERSION` but with patch version. # ARG is used here for temporary override without changing the original env. -ARG PYTHON_VERSION=3.12 +ARG PYTHON_VERSION # Retrieve packages from build stage. ENV PYTHONPATH=/workspace/pkgs diff --git a/.renovaterc.json b/.renovaterc.json index 03320258..b4197662 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -9,7 +9,7 @@ "^template\\/\\.devcontainer/Dockerfile\\.jinja$" ], "matchStrings": [ - "RUN pipx install (?.*?)==(?.*?)\n" + "pipx install (?.*?)==(?.*?)[;\n]" ] }, { @@ -59,6 +59,14 @@ ] }, "semanticCommitScope": "copier-template" + }, + { + "description": "Pre-commit 3.5.0 is pinned as the last version supporting Python 3.8.", + "enabled": false, + "matchCurrentVersion": "==3.5.0", + "matchPackageNames": [ + "pre-commit" + ] } ] } diff --git a/template/.devcontainer/Dockerfile.jinja b/template/.devcontainer/Dockerfile.jinja index 08d4fc48..16a3be4b 100644 --- a/template/.devcontainer/Dockerfile.jinja +++ b/template/.devcontainer/Dockerfile.jinja @@ -6,6 +6,10 @@ ARG PYTHON_VERSION={{ default_py }} FROM python:${PYTHON_VERSION} as dev +# NOTE: python docker image has env `PYTHON_VERSION` but with patch version. +# ARG is used here for temporary override without changing the original env. +ARG PYTHON_VERSION + RUN apt-get update && apt-get install -y --no-install-recommends \ # pipx: To install Python applications. pipx \ @@ -22,7 +26,11 @@ ENV PIPX_DEFAULT_PYTHON=/usr/local/bin/python RUN pipx install pdm==2.12.4 # Install pre-commit -RUN pipx install pre-commit==3.6.2 +RUN if [ "${PYTHON_VERSION}" = "3.8" ]; then \ + pipx install pre-commit==3.5.0; \ + else \ + pipx install pre-commit==3.6.2; \ + fi # Create a non-root user with sudo permission ARG USERNAME={{ repo_name }} @@ -60,7 +68,7 @@ FROM python:${PYTHON_VERSION}-slim as prod # NOTE: python docker image has env `PYTHON_VERSION` but with patch version. # ARG is used here for temporary override without changing the original env. -ARG PYTHON_VERSION={{ default_py }} +ARG PYTHON_VERSION # Retrieve packages from build stage. ENV PYTHONPATH=/workspace/pkgs diff --git a/template/.renovaterc.json.jinja b/template/.renovaterc.json.jinja index bc543c6f..af3b0ac7 100644 --- a/template/.renovaterc.json.jinja +++ b/template/.renovaterc.json.jinja @@ -1,3 +1,4 @@ +[% from pathjoin("includes", "version_compare.jinja") import version_higher_than -%] { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "customManagers": [ @@ -11,7 +12,7 @@ [%- endif %] ], "matchStrings": [ - "RUN pipx install (?.*?)==(?.*?)\n" + "pipx install (?.*?)==(?.*?)[;\n]" ] }, { @@ -65,6 +66,14 @@ ] }, "semanticCommitScope": "copier-template" + }, + { + "description": "Pre-commit 3.5.0 is pinned as the last version supporting Python 3.8.", + "enabled": false, + "matchCurrentVersion": "==3.5.0", + "matchPackageNames": [ + "pre-commit" + ] } ] }