Skip to content

Commit 47cb797

Browse files
Update pre-commit configuration to use prek
- Remove custom git hooks and related scripts. - Create `.pre-commit-config.yaml` with standard hooks and `black`. - Update `Makefile` to use `prek` for checking and installing hooks. - Replace `linter_require_black.yaml` workflow with `prek.yaml`. - Update `README.md` with instructions for `prek`. - Ensure `git config core.hooksPath` is unset during hook installation. Co-authored-by: Miyamura80 <38335479+Miyamura80@users.noreply.github.com>
1 parent 63016d0 commit 47cb797

5 files changed

Lines changed: 44 additions & 22 deletions

File tree

.githooks/post-commit

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/workflows/linter_require_black.yaml renamed to .github/workflows/prek.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint
1+
name: Prek Checks
22

33
on:
44
pull_request:
@@ -10,9 +10,11 @@ on:
1010
- '.github/workflows/**'
1111

1212
jobs:
13-
lint:
13+
prek:
1414
if: github.event_name == 'pull_request' || github.event.pull_request == null
1515
runs-on: ubuntu-latest
1616
steps:
1717
- uses: actions/checkout@v4
18-
- uses: psf/black@stable
18+
with:
19+
submodules: 'recursive'
20+
- uses: j178/prek-action@v1

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
10+
- repo: https://github.com/psf/black
11+
rev: 24.8.0
12+
hooks:
13+
- id: black

Makefile

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,23 @@ check_jq:
4242
jq --version; \
4343
fi
4444

45+
check_prek:
46+
@echo "$(YELLOW)🔍Checking prek version...$(RESET)"
47+
@if ! command -v prek > /dev/null 2>&1; then \
48+
echo "$(RED)prek is not installed. Please install prek before proceeding.$(RESET)"; \
49+
echo "$(RED)curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/download/v0.3.3/prek-installer.sh | sh$(RESET)"; \
50+
exit 1; \
51+
else \
52+
prek --version; \
53+
fi
54+
4555
########################################################
4656
# Setup githooks for linting
4757
########################################################
48-
setup_githooks:
49-
@echo "$(YELLOW)🔨Setting up githooks on post-commit...$(RESET)"
50-
chmod +x .githooks/post-commit
51-
git config core.hooksPath .githooks
58+
install_hooks: check_prek
59+
@echo "$(YELLOW)🔨Installing pre-commit hooks with prek...$(RESET)"
60+
@git config --unset core.hooksPath || true
61+
@prek install
5262

5363

5464
########################################################
@@ -75,7 +85,7 @@ view_python_venv_size_by_libraries:
7585
# Run Main Application
7686
########################################################
7787

78-
all: update_python_dep setup_githooks
88+
all: update_python_dep install_hooks
7989
@echo "$(GREEN)🏁Running main application...$(RESET)"
8090
@$(PYTHON) main.py
8191
@echo "$(GREEN)✅ Main application run completed.$(RESET)"
@@ -102,6 +112,11 @@ test: check_rye
102112
IGNORE_LINT_DIRS = .venv|venv
103113
LINE_LENGTH = 88
104114

115+
lint: check_prek
116+
@echo "$(YELLOW)🔍Running pre-commit hooks...$(RESET)"
117+
@prek run --all-files
118+
@echo "$(GREEN)✅Pre-commit hooks passed.$(RESET)"
119+
105120
fmt: check_rye check_jq
106121
@echo "$(YELLOW)✨Formatting project with Black...$(RESET)"
107122
@rye run black --exclude '/($(IGNORE_LINT_DIRS))/' . --line-length $(LINE_LENGTH)

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@
5252
```
5353
curl -sSf https://rye.astral.sh/get | bash
5454
```
55+
- [prek](https://github.com/j178/prek)
56+
```
57+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/download/v0.3.3/prek-installer.sh | sh
58+
```
5559

5660
## Quick Start
5761

5862
- `make all` - runs `main.py`
5963
- `make fmt` - runs `black` linter, an opinionated linter
64+
- `make lint` - runs `prek` hooks (linting, formatting, checks)
6065
- `make banner` - create a new banner that makes the README nice 😊
6166
- `make test` - runs all tests defined by `TEST_TARGETS = tests/folder1 tests/folder2`
6267

@@ -83,6 +88,7 @@
8388
This software uses the following tools:
8489
- [Cursor: The AI Code Editor](cursor.com)
8590
- [Rye: a Hassle-Free Python Experience](https://rye.astral.sh/)
91+
- [prek: Better pre-commit, re-engineered in Rust](https://github.com/j178/prek)
8692
- [DSPY: Pytorch for LLM Inference](https://dspy.ai/)
8793
- [LangFuse: LLM Observability Tool](https://langfuse.com/)
8894

0 commit comments

Comments
 (0)