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
15 changes: 8 additions & 7 deletions .github/workflows/pre-commit.yml → .github/workflows/prek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
permissions: {}

jobs:
pre-commit:
prek:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -35,10 +35,11 @@ jobs:
- name: Install deptry
run: uv tool install deptry

- name: Run pre-commit
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
- name: Install prek
run: uv tool install prek

- name: Run pre-commit (extra)
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
with:
extra_args: --config .pre-commit-config-extra.yaml
- name: Run prek
run: prek run --all-files --show-diff-on-failure

- name: Run prek (extra)
run: prek run --all-files --show-diff-on-failure --config prek-extra.toml
8 changes: 0 additions & 8 deletions .pre-commit-config-extra.yaml

This file was deleted.

70 changes: 0 additions & 70 deletions .pre-commit-config.yaml

This file was deleted.

24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Why should I use this template:
- **Auto formatting and code checking** using `ruff`
- **Updatable template** - Easy to keep up to date with latest practices
- **Visual Studio Code** configurations included
- **Pre-commit hooks** for code quality enforcement
- **Git hooks with prek** for code quality enforcement
- **GitHub Actions** workflows for CI/CD

### Optional features
Expand Down Expand Up @@ -62,22 +62,28 @@ In both cases, copier will try to check differences between your project and the

Check this [page](https://copier.readthedocs.io/en/stable/updating/) for more specific info about this feature.

## Running pre-commit
## Running prek

[pre-commit](https://github.com/pre-commit/pre-commit) is a framework for managing pre-commit git hooks. The pre-commit git hooks are ways to identify issues in your code before pushing your changes to the repository, for instance missing semicolons, trailing whitespace, unused dependencies.
[prek](https://prek.j178.dev/) is a fast, Rust-based framework for managing git hooks. It's 100% compatible with pre-commit configs but significantly faster. Git hooks help identify issues in your code before pushing to the repository, such as missing semicolons, trailing whitespace, or unused dependencies.

:sparkles: pre-commit doesn't change the functionality of your code
:sparkles: prek doesn't change the functionality of your code

To run pre-commit on your code, first install pre-commit:
To run prek on your code, first install prek:

```
uv tool install pre-commit
uv tool install prek
```

Then run:
Then install the git hooks:

```
pre-commit run --all
prek install
```

To run manually on all files:

```
prek run --all-files
```

## Struggling with a template?
Expand All @@ -91,7 +97,7 @@ Install development dependencies:
## Testing the template
To test the template using copier-template-tester, run:
```bash
pre-commit run -c .pre-commit-config-extra.yaml
prek run -c prek-extra.toml
```

## Maintenance
Expand Down
4 changes: 2 additions & 2 deletions ctt.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[defaults]
# Test pre-commit functionality
# Test prek functionality
_extra_tasks = [
"git init",
"git add .",
"uv sync --dev",
"uv run pre-commit run --all-files end-of-file-fixer || uv run pre-commit run --all-files"
"uv run prek run --all-files end-of-file-fixer || uv run prek run --all-files"
]
author_name = "Test Author"
debug = true
Expand Down
9 changes: 9 additions & 0 deletions prek-extra.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See https://prek.j178.dev for more information.
# :schema https://www.schemastore.org/prek.json

default_stages = ["pre-commit"]

[[repos]]
hooks = [{id = "copier-template-tester", additional_dependencies = ["copier-template-extensions"]}]
repo = "https://github.com/KyleKing/copier-template-tester"
rev = "2.3.0"
70 changes: 70 additions & 0 deletions prek.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# See https://prek.j178.dev for more information.
# schema: https://www.schemastore.org/prek.json

default_stages = ["pre-commit"]

[[repos]]
hooks = [
{id = "trailing-whitespace"},
{id = "end-of-file-fixer"},
{id = "check-json"},
{id = "check-toml"},
{id = "check-xml"},
{id = "check-yaml"},
{id = "debug-statements"},
{id = "check-builtin-literals"},
{id = "check-case-conflict"},
{id = "check-docstring-first"},
{id = "detect-private-key"},
{id = "check-merge-conflict", args = ["--assume-in-merge"]}
]
repo = "https://github.com/pre-commit/pre-commit-hooks"
rev = "v6.0.0"

[[repos]]
hooks = [
{id = "pretty-format-toml", args = ["--autofix"], exclude = '^uv\.lock$'}
]
repo = "https://github.com/macisamuele/language-formatters-pre-commit-hooks"
rev = "v2.16.0"

[[repos]]
hooks = [
{id = "detect-secrets", args = ["--exclude-files=django/src/fixtures/users.json"]}
]
repo = "https://github.com/Yelp/detect-secrets"
rev = "v1.5.0"

[[repos]]
hooks = [
{id = "forbidden-files", name = "forbidden files", entry = "found Copier update rejection files", description = "review and remove .rej files before merging.", language = "fail", files = '\.rej$'}
]
repo = "local"

[[repos]]
hooks = [
{id = "zizmor"}
]
repo = "https://github.com/woodruffw/zizmor-pre-commit"
rev = "v1.23.1"

[[repos]]
hooks = [
{id = "ruff"},
{id = "ruff-format"}
]
repo = "https://github.com/astral-sh/ruff-pre-commit"
rev = "v0.15.7"

[[repos]]
hooks = [
{id = "uv-lock"}
]
repo = "https://github.com/astral-sh/uv-pre-commit"
rev = "0.10.12"

[[repos]]
hooks = [
{id = "deptry", name = "deptry", entry = "uv run deptry .", language = "system", types = ["python"], pass_filenames = false}
]
repo = "local"
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
permissions: {}

jobs:
pre-commit:
prek:
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -27,5 +27,8 @@ jobs:
- name: Install deptry
run: uv tool install deptry

- name: Run pre-commit
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
- name: Install prek
run: uv tool install prek

- name: Run prek
run: prek run --all-files --show-diff-on-failure
1 change: 0 additions & 1 deletion python/.pre-commit-config.yaml.jinja

This file was deleted.

20 changes: 10 additions & 10 deletions python/README.md.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git init
uv sync --dev
git add .
git commit -m "Initial commit"
uv run pre-commit install # optional
uv run prek install # optional
```

{% if notebook %}
Expand Down Expand Up @@ -60,22 +60,22 @@ You can keep your previous answers by using:
uvx --with copier-template-extensions copier update --trust --defaults
```

### (Optional) pre-commit
pre-commit is a set of tools that help you ensure code quality. It runs every time you make a commit.
### (Optional) prek
prek is a fast, Rust-based tool for managing git hooks (100% compatible with pre-commit). It helps ensure code quality by running checks every time you make a commit.

First, install pre-commit:
First, install prek:
```bash
uv tool install pre-commit
uv tool install prek
```

Then install pre-commit hooks:
Then install git hooks:
```bash
pre-commit install
prek install
```

To run pre-commit on all files:
To run prek on all files:
```bash
pre-commit run --all-files
prek run --all-files
```

### How to install a package
Expand All @@ -97,7 +97,7 @@ docker compose up --build watch

### Tools installed
- uv
- pre-commit (optional)
- prek (optional)

#### What is an environment variable? and why should I use them?
Environment variables are variables that are not populated in your code but rather in the environment
Expand Down
1 change: 1 addition & 0 deletions python/prek.toml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include_raw 'prek.toml' %}
3 changes: 2 additions & 1 deletion python/{% if docker %}.dockerignore{% endif %}.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ _build/
__pycache__/
.vscode
.git
.pre-commit-config.yaml
prek.toml
prek-extra.toml
.venv
.env
{% block extra %}{% endblock %}
6 changes: 3 additions & 3 deletions scripts/maintenance.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ set -e

echo "🔧 Running maintenance tasks..."

echo "📦 Updating pre-commit hooks..."
uvx pre-commit autoupdate
uvx pre-commit autoupdate --config .pre-commit-config-extra.yaml
echo "📦 Updating prek hooks..."
prek autoupdate
prek autoupdate --config prek-extra.toml

echo "🚀 Updating pinned GitHub Actions..."
pinact run --update
Expand Down
Loading