Skip to content

Commit 3340033

Browse files
update to use prek
1 parent e77ac1f commit 3340033

9 files changed

Lines changed: 58 additions & 44 deletions

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ repos:
88
- id: check-added-large-files
99
- id: check-merge-conflict
1010
- repo: https://github.com/crate-ci/typos
11-
rev: v1.36.2
11+
rev: v1.44.0
1212
hooks:
1313
- id: typos
1414
- repo: https://github.com/DavidAnson/markdownlint-cli2
15-
rev: v0.18.1
15+
rev: v0.21.0
1616
hooks:
1717
- id: markdownlint-cli2

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Python Copier Template for Data Science
22

3-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
55
[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
6-
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
6+
[![prek](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json)](https://github.com/j178/prek)
77

88
This is a template built with [Copier](https://github.com/copier-org/copier) to generate a data science focused python project.
99

@@ -78,16 +78,22 @@ In addition, the following rules are only enforced for module code as they are i
7878

7979
The target line length is 120 and the docstring convention is google.
8080

81-
### [pre-commit](https://github.com/pre-commit/pre-commit)
81+
### [prek](https://github.com/j178/prek) and [pre-commit](https://github.com/pre-commit/pre-commit)
8282

83-
pre-commit is a tool that runs checks on your files before you commit them with git, thereby helping ensure code quality.
84-
Enable it with the following command:
83+
`prek` and `pre-commit` are tools that run checks on your files before you commit them with git, thereby helping ensure code quality.
84+
`prek` is faster than `pre-commit` and has more features, including monorepo support.
85+
86+
Depending on your preference, run one of the following commands to set up.
87+
88+
```shell
89+
prek install --prepare-hooks
90+
```
8591

8692
```shell
8793
pre-commit install --install-hooks
8894
```
8995

90-
The configuration is stored in `.pre-commit-config.yaml`.
96+
The configuration for both is stored in `.pre-commit-config.yaml`.
9197

9298
### [nbwipers](https://github.com/felixgwilliams/nbwipers)
9399

copier.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ github_actions:
1717
type: bool
1818
help: Add github actions
1919
default: false
20+
21+
use_prek:
22+
type: bool
23+
help: Use prek instead of pre-commit
24+
default: true

ctt.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ project_name = "ctt-test"
55

66
[output.".ctt/ga"]
77
github_actions = true
8+
9+
[output.".ctt/no-prek"]
10+
use_prek = false

template/.pre-commit-config.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-merge-conflict
9+
- repo: https://github.com/astral-sh/ruff-pre-commit
10+
# Ruff version.
11+
rev: v0.15.6
12+
hooks:
13+
# Run the linter.
14+
- id: ruff
15+
types_or: [python, pyi, jupyter]
16+
# Run the formatter.
17+
- id: ruff-format
18+
types_or: [python, pyi, jupyter]
19+
- repo: https://github.com/felixgwilliams/nbwipers-pre-commit
20+
rev: v0.6.1
21+
hooks:
22+
- id: nbwipers-check-install
23+
- id: nbwipers-large-files
24+
- repo: https://github.com/crate-ci/typos
25+
rev: v1.44.0
26+
hooks:
27+
- id: typos
28+
- repo: https://github.com/DavidAnson/markdownlint-cli2
29+
rev: v0.21.0
30+
hooks:
31+
- id: markdownlint-cli2

template/README.md.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
44
[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)
5-
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
5+
{% if use_prek %}[![prek](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json)](https://github.com/j178/prek){% else %}[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit){% endif %}
66

77
Get started by running the following with [just](https://github.com/casey/just):
88

template/justfile.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ setup: install git-setup
1111
install:
1212
{% raw %}{{if path_exists("uv.lock") != "true" {"uv sync --all-groups --all-extras --inexact"} else {"uv sync --all-groups --all-extras --locked --inexact"} }}{% endraw %}
1313

14-
# ensure code quality before git commit via pre-commit and nbwipers
14+
# ensure code quality before git commit via {% if use_prek %}prek{% else %}pre-commit{% endif %} and nbwipers
1515
git-setup: install
1616
uv run nbwipers install local
17-
uv run pre-commit install --install-hooks
17+
{% if use_prek %}uv run prek install --prepare-hooks{% else %}uv run pre-commit install --install-hooks{% endif %}
1818

1919
# run test coverage and create
2020
test-cov:

template/pyproject.toml.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ dev = [
9595
"nbwipers>=0.6.1",
9696
"pytest>=8",
9797
"pytest-cov>=7.0.0",
98-
"pre-commit>=4.3.0",
99-
"typos>=1.36.2",
98+
{% if use_prek %}"prek>=0.3.6"{% else %}"pre-commit>=4.5.1"{% endif %},
99+
"typos>=1.44.2",
100100
]
101101
lint = [
102102
"ruff>=0.13.0",

0 commit comments

Comments
 (0)