From acd620891937d077468064f2b9ece5d8729bd41c Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Mon, 22 Dec 2025 10:38:35 -0500 Subject: [PATCH 1/4] cicd(python): update pre-commit git hooks --- .../.github/workflows/checks.yaml | 39 +++++++------------ .../.pre-commit-config.yaml | 24 ++++++++---- .../pyproject.toml | 2 +- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/python/{{cookiecutter.project_slug}}/.github/workflows/checks.yaml b/python/{{cookiecutter.project_slug}}/.github/workflows/checks.yaml index eba0204..7d06e60 100644 --- a/python/{{cookiecutter.project_slug}}/.github/workflows/checks.yaml +++ b/python/{{cookiecutter.project_slug}}/.github/workflows/checks.yaml @@ -8,15 +8,15 @@ jobs: matrix: python-version: ["3.11", "3.12", "3.13"] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: python-version: {{ "${{ matrix.python-version }}" }} - name: Install uv - uses: astral-sh/setup-uv@v6 + uses: astral-sh/setup-uv@v7 with: enable-cache: true @@ -30,15 +30,15 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Setup Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: - python-version: "3.11" + python-version: "3.13" - name: Install uv - uses: astral-sh/setup-uv@v6 + uses: astral-sh/setup-uv@v7 with: enable-cache: true @@ -50,23 +50,12 @@ jobs: precommit_hooks: runs-on: ubuntu-latest - strategy: - matrix: - cmd: - - "end-of-file-fixer" - - "trailing-whitespace" - - "mixed-line-ending" steps: - - uses: actions/checkout@v4 - - - name: Set up Python 3.12 - uses: actions/setup-python@v5 - with: - python-version: 3.12 + - uses: actions/checkout@v6 - - uses: pre-commit/action@v3.0.1 + - uses: j178/prek-action@v1 with: - extra_args: {{ "${{ matrix.cmd }}" }} --all-files + extra_args: '--all-files --skip "ruff-format" --skip "ruff-check"' {% if cookiecutter.add_docs %} docs: @@ -74,15 +63,15 @@ jobs: env: SPHINX_GITHUB_CHANGELOG_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }} steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Set up Python - uses: actions/setup-python@v5 + uses: actions/setup-python@v6 with: - python-version: 3.11 + python-version: 3.12 # broken on 3.13 - name: Install uv - uses: astral-sh/setup-uv@v6 + uses: astral-sh/setup-uv@v7 with: enable-cache: true diff --git a/python/{{cookiecutter.project_slug}}/.pre-commit-config.yaml b/python/{{cookiecutter.project_slug}}/.pre-commit-config.yaml index 31a7668..ed5ab96 100644 --- a/python/{{cookiecutter.project_slug}}/.pre-commit-config.yaml +++ b/python/{{cookiecutter.project_slug}}/.pre-commit-config.yaml @@ -1,20 +1,28 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 # pre-commit-hooks version + rev: v6.0.0 # pre-commit-hooks version hooks: - - id: check-added-large-files - - id: detect-private-key - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-merge-conflict - id: detect-aws-credentials args: [ --allow-missing-credentials ] + - repo: builtin + hooks: + - id: trailing-whitespace + - id: check-added-large-files + args: ['--maxkb=1500'] + - id: check-case-conflict + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: check-json + - id: check-toml + - id: check-yaml - id: mixed-line-ending args: [ --fix=lf ] + - id: check-merge-conflict + - id: detect-private-key - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.12.1 # ruff version hooks: - id: ruff-format - - id: ruff + - id: ruff-check args: [ --fix, --exit-non-zero-on-fix ] -minimum_pre_commit_version: 4.2.0 +minimum_prek_version: 0.2.23 diff --git a/python/{{cookiecutter.project_slug}}/pyproject.toml b/python/{{cookiecutter.project_slug}}/pyproject.toml index 1937371..7f1c8b9 100644 --- a/python/{{cookiecutter.project_slug}}/pyproject.toml +++ b/python/{{cookiecutter.project_slug}}/pyproject.toml @@ -43,7 +43,7 @@ tests = [ {%- endif %} ] dev = [ - "pre-commit>=4.2.0", + "prek>=0.2.23", "ruff==0.12.1", {%- if cookiecutter.add_fastapi %} "fastapi[standard]" From 65c0bd5d02fa6e642954471209471d8aee883f38 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Mon, 22 Dec 2025 10:48:31 -0500 Subject: [PATCH 2/4] update docs --- .../docs/source/contributing.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/{{cookiecutter.project_slug}}/docs/source/contributing.rst b/python/{{cookiecutter.project_slug}}/docs/source/contributing.rst index f94538a..1f7351f 100644 --- a/python/{{cookiecutter.project_slug}}/docs/source/contributing.rst +++ b/python/{{cookiecutter.project_slug}}/docs/source/contributing.rst @@ -22,21 +22,22 @@ Then initialize a virtual environment: :: source venv/bin/activate python3 -m pip install -e '.[dev,tests,docs]' -We use `pre-commit `_ to run conformance tests before commits. This provides checks for: +We use `prek `_ to run conformance tests before commits. This provides checks for: * Code format and style * Added large files * AWS credentials * Private keys +* Other formatting things Before your first commit, run: :: - pre-commit install + prek install Style ----- -Code style is managed by `Ruff `_, and should be checked via pre-commit hook before commits. Final QC is applied with GitHub Actions to every pull request. +Code style is managed by `Ruff `_, and should be checked via ``prek`` hook before commits. Final QC is applied with GitHub Actions to every pull request. Tests ----- From bbb588b55ba208abb3ddf65735bc9a6398fbe3e0 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Mon, 22 Dec 2025 10:49:23 -0500 Subject: [PATCH 3/4] update readme --- python/{{cookiecutter.project_slug}}/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/{{cookiecutter.project_slug}}/README.md b/python/{{cookiecutter.project_slug}}/README.md index 8114d3d..2f57703 100644 --- a/python/{{cookiecutter.project_slug}}/README.md +++ b/python/{{cookiecutter.project_slug}}/README.md @@ -40,11 +40,11 @@ python3 -m virtualenv venv source venv/bin/activate ``` -Install development dependencies and `pre-commit`: +Install development dependencies and `prek`: ```shell python3 -m pip install -e '.[dev,tests]' -pre-commit install +prek install ``` Check style with `ruff`: From 3f59cb6c607533138c39d44dc1575758df361f71 Mon Sep 17 00:00:00 2001 From: James Stevenson Date: Mon, 22 Dec 2025 13:37:44 -0500 Subject: [PATCH 4/4] update updater --- .github/workflows/update-python.yaml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/update-python.yaml b/.github/workflows/update-python.yaml index 4abcdb4..d461c57 100644 --- a/.github/workflows/update-python.yaml +++ b/.github/workflows/update-python.yaml @@ -71,7 +71,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} update_precommit_and_hooks: - name: Update Python pre-commit version pins and hooks + name: Update Python prek version pins and hooks runs-on: ubuntu-latest steps: - name: Check out repository @@ -84,19 +84,19 @@ jobs: with: python-version: ${{ env.MIN_PYTHON_VERSION }} - - name: Install latest pre-commit - run: python3 -m pip install pre-commit + - name: Install latest prek + run: python3 -m pip install prek - - name: Get latest pre-commit version - id: precommit-version + - name: Get latest prek version + id: prek-version run: | - echo "PRECOMMIT_VERSION=$(pip show pre-commit | grep 'Version' | cut -d ' ' -f 2)" >> $GITHUB_ENV + echo "PRECOMMIT_VERSION=$(pip show prek | grep 'Version' | cut -d ' ' -f 2)" >> $GITHUB_ENV - - name: Update pre-commit version in pyproject.toml + - name: Update prek version in pyproject.toml run: | - sed -i "s/\"pre-commit>=.*\"/\"pre-commit>=${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml + sed -i "s/\"prek>=.*\"/\"prek>=${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml - - name: Update min pre-commit version requirement in .pre-commit-config.yaml + - name: Update min prek version requirement in .pre-commit-config.yaml run: | sed -i "s/minimum_pre_commit_version: .*/minimum_pre_commit_version: ${{ env.PRECOMMIT_VERSION }}/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml @@ -119,7 +119,7 @@ jobs: if: env.new_commits == 'true' run: | gh pr create --title "cicd(python): update precommit to ${{ env.PRECOMMIT_VERSION }}" \ - --body "Automatically update the pre-commit version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \ + --body "Automatically update the prek version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \ --base main \ --head update-precommit-${{ env.PRECOMMIT_VERSION }} \ --reviewer "jsstevenson,korikuzma" \