Skip to content

Commit a7904d3

Browse files
authored
cicd(python): update pre-commit git hooks (#132)
1 parent fd7519d commit a7904d3

File tree

6 files changed

+47
-49
lines changed

6 files changed

+47
-49
lines changed

.github/workflows/update-python.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7272

7373
update_precommit_and_hooks:
74-
name: Update Python pre-commit version pins and hooks
74+
name: Update Python prek version pins and hooks
7575
runs-on: ubuntu-latest
7676
steps:
7777
- name: Check out repository
@@ -84,19 +84,19 @@ jobs:
8484
with:
8585
python-version: ${{ env.MIN_PYTHON_VERSION }}
8686

87-
- name: Install latest pre-commit
88-
run: python3 -m pip install pre-commit
87+
- name: Install latest prek
88+
run: python3 -m pip install prek
8989

90-
- name: Get latest pre-commit version
91-
id: precommit-version
90+
- name: Get latest prek version
91+
id: prek-version
9292
run: |
93-
echo "PRECOMMIT_VERSION=$(pip show pre-commit | grep 'Version' | cut -d ' ' -f 2)" >> $GITHUB_ENV
93+
echo "PRECOMMIT_VERSION=$(pip show prek | grep 'Version' | cut -d ' ' -f 2)" >> $GITHUB_ENV
9494
95-
- name: Update pre-commit version in pyproject.toml
95+
- name: Update prek version in pyproject.toml
9696
run: |
97-
sed -i "s/\"pre-commit>=.*\"/\"pre-commit>=${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml
97+
sed -i "s/\"prek>=.*\"/\"prek>=${{ env.PRECOMMIT_VERSION }}\"/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/pyproject.toml
9898
99-
- name: Update min pre-commit version requirement in .pre-commit-config.yaml
99+
- name: Update min prek version requirement in .pre-commit-config.yaml
100100
run: |
101101
sed -i "s/minimum_pre_commit_version: .*/minimum_pre_commit_version: ${{ env.PRECOMMIT_VERSION }}/" ${{ env.PYTHON_TEMPLATE_LOCATION }}/.pre-commit-config.yaml
102102
@@ -119,7 +119,7 @@ jobs:
119119
if: env.new_commits == 'true'
120120
run: |
121121
gh pr create --title "cicd(python): update precommit to ${{ env.PRECOMMIT_VERSION }}" \
122-
--body "Automatically update the pre-commit version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \
122+
--body "Automatically update the prek version in \`pyproject.toml\` and \`.pre-commit-config.yaml\`." \
123123
--base main \
124124
--head update-precommit-${{ env.PRECOMMIT_VERSION }} \
125125
--reviewer "jsstevenson,korikuzma" \

python/{{cookiecutter.project_slug}}/.github/workflows/checks.yaml

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ jobs:
88
matrix:
99
python-version: ["3.11", "3.12", "3.13"]
1010
steps:
11-
- uses: actions/checkout@v4
11+
- uses: actions/checkout@v6
1212

1313
- name: Set up Python
14-
uses: actions/setup-python@v5
14+
uses: actions/setup-python@v6
1515
with:
1616
python-version: {{ "${{ matrix.python-version }}" }}
1717

1818
- name: Install uv
19-
uses: astral-sh/setup-uv@v6
19+
uses: astral-sh/setup-uv@v7
2020
with:
2121
enable-cache: true
2222

@@ -30,15 +30,15 @@ jobs:
3030
name: lint
3131
runs-on: ubuntu-latest
3232
steps:
33-
- uses: actions/checkout@v4
33+
- uses: actions/checkout@v6
3434

3535
- name: Setup Python
36-
uses: actions/setup-python@v5
36+
uses: actions/setup-python@v6
3737
with:
38-
python-version: "3.11"
38+
python-version: "3.13"
3939

4040
- name: Install uv
41-
uses: astral-sh/setup-uv@v6
41+
uses: astral-sh/setup-uv@v7
4242
with:
4343
enable-cache: true
4444

@@ -50,39 +50,28 @@ jobs:
5050

5151
precommit_hooks:
5252
runs-on: ubuntu-latest
53-
strategy:
54-
matrix:
55-
cmd:
56-
- "end-of-file-fixer"
57-
- "trailing-whitespace"
58-
- "mixed-line-ending"
5953
steps:
60-
- uses: actions/checkout@v4
61-
62-
- name: Set up Python 3.12
63-
uses: actions/setup-python@v5
64-
with:
65-
python-version: 3.12
54+
- uses: actions/checkout@v6
6655

67-
- uses: pre-commit/action@v3.0.1
56+
- uses: j178/prek-action@v1
6857
with:
69-
extra_args: {{ "${{ matrix.cmd }}" }} --all-files
58+
extra_args: '--all-files --skip "ruff-format" --skip "ruff-check"'
7059

7160
{% if cookiecutter.add_docs %}
7261
docs:
7362
runs-on: ubuntu-latest
7463
env:
7564
SPHINX_GITHUB_CHANGELOG_TOKEN: {{ "${{ secrets.GITHUB_TOKEN }}" }}
7665
steps:
77-
- uses: actions/checkout@v4
66+
- uses: actions/checkout@v6
7867

7968
- name: Set up Python
80-
uses: actions/setup-python@v5
69+
uses: actions/setup-python@v6
8170
with:
82-
python-version: 3.11
71+
python-version: 3.12 # broken on 3.13
8372

8473
- name: Install uv
85-
uses: astral-sh/setup-uv@v6
74+
uses: astral-sh/setup-uv@v7
8675
with:
8776
enable-cache: true
8877

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v5.0.0 # pre-commit-hooks version
3+
rev: v6.0.0 # pre-commit-hooks version
44
hooks:
5-
- id: check-added-large-files
6-
- id: detect-private-key
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-merge-conflict
105
- id: detect-aws-credentials
116
args: [ --allow-missing-credentials ]
7+
- repo: builtin
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: check-added-large-files
11+
args: ['--maxkb=1500']
12+
- id: check-case-conflict
13+
- id: end-of-file-fixer
14+
- id: fix-byte-order-marker
15+
- id: check-json
16+
- id: check-toml
17+
- id: check-yaml
1218
- id: mixed-line-ending
1319
args: [ --fix=lf ]
20+
- id: check-merge-conflict
21+
- id: detect-private-key
1422
- repo: https://github.com/astral-sh/ruff-pre-commit
1523
rev: v0.14.10 # ruff version
1624
hooks:
1725
- id: ruff-format
18-
- id: ruff
26+
- id: ruff-check
1927
args: [ --fix, --exit-non-zero-on-fix ]
20-
minimum_pre_commit_version: 4.2.0
28+
minimum_prek_version: 0.2.23

python/{{cookiecutter.project_slug}}/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ python3 -m virtualenv venv
4040
source venv/bin/activate
4141
```
4242

43-
Install development dependencies and `pre-commit`:
43+
Install development dependencies and `prek`:
4444

4545
```shell
4646
python3 -m pip install -e '.[dev,tests]'
47-
pre-commit install
47+
prek install
4848
```
4949

5050
Check style with `ruff`:

python/{{cookiecutter.project_slug}}/docs/source/contributing.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,22 @@ Then initialize a virtual environment: ::
2222
source venv/bin/activate
2323
python3 -m pip install -e '.[dev,tests,docs]'
2424

25-
We use `pre-commit <https://pre-commit.com/#usage>`_ to run conformance tests before commits. This provides checks for:
25+
We use `prek <https://prek.j178.dev/>`_ to run conformance tests before commits. This provides checks for:
2626

2727
* Code format and style
2828
* Added large files
2929
* AWS credentials
3030
* Private keys
31+
* Other formatting things
3132

3233
Before your first commit, run: ::
3334

34-
pre-commit install
35+
prek install
3536

3637
Style
3738
-----
3839

39-
Code style is managed by `Ruff <https://github.com/astral-sh/ruff>`_, and should be checked via pre-commit hook before commits. Final QC is applied with GitHub Actions to every pull request.
40+
Code style is managed by `Ruff <https://github.com/astral-sh/ruff>`_, and should be checked via ``prek`` hook before commits. Final QC is applied with GitHub Actions to every pull request.
4041

4142
Tests
4243
-----

python/{{cookiecutter.project_slug}}/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tests = [
4343
{%- endif %}
4444
]
4545
dev = [
46-
"pre-commit>=4.2.0",
46+
"prek>=0.2.23",
4747
"ruff==0.14.10",
4848
{%- if cookiecutter.add_fastapi %}
4949
"fastapi[standard]"

0 commit comments

Comments
 (0)