Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .github/workflows/update-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -50,39 +50,28 @@ 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:
runs-on: ubuntu-latest
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

Expand Down
24 changes: 16 additions & 8 deletions python/{{cookiecutter.project_slug}}/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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.14.10 # 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
4 changes: 2 additions & 2 deletions python/{{cookiecutter.project_slug}}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pre-commit.com/#usage>`_ to run conformance tests before commits. This provides checks for:
We use `prek <https://prek.j178.dev/>`_ 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 <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.
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.

Tests
-----
Expand Down
2 changes: 1 addition & 1 deletion python/{{cookiecutter.project_slug}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ tests = [
{%- endif %}
]
dev = [
"pre-commit>=4.2.0",
"prek>=0.2.23",
"ruff==0.14.10",
{%- if cookiecutter.add_fastapi %}
"fastapi[standard]"
Expand Down
Loading