Skip to content

Commit 7c2640e

Browse files
authored
Merge pull request #78 from akhundMurad/core/33
chore(pre-commit): add pre-commit hooks and cleanup Makefile
2 parents 1fe4eac + 4724ae6 commit 7c2640e

File tree

7 files changed

+199
-25
lines changed

7 files changed

+199
-25
lines changed

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
- name: Run linters
3636
run: |
37-
make check-linting
37+
make lint
3838
3939
test:
4040
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
repos:
2+
# ---------------------------------------------------------------------------
3+
# Lint: Ruff + Black + mypy
4+
# ---------------------------------------------------------------------------
5+
- repo: local
6+
hooks:
7+
- id: lint
8+
name: lint
9+
entry: make lint
10+
language: system
11+
pass_filenames: false
12+
stages: [pre-commit]
13+
14+
# ---------------------------------------------------------------------------
15+
# Run tests: fast feedback on commits
16+
# ---------------------------------------------------------------------------
17+
- repo: local
18+
hooks:
19+
- id: test
20+
name: test
21+
entry: make test
22+
language: system
23+
pass_filenames: false
24+
stages: [pre-commit]
25+
26+
# ---------------------------------------------------------------------------
27+
# Run documentation tests: fast feedback on commits
28+
# ---------------------------------------------------------------------------
29+
- repo: local
30+
hooks:
31+
- id: test-docs
32+
name: test-docs
33+
entry: make test-docs
34+
language: system
35+
pass_filenames: false
36+
stages: [pre-commit]

CONTRIBUTING.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ uv --version
4848
Create and sync the virtual environment (including dev dependencies):
4949

5050
```bash
51-
uv sync --all-groups
51+
uv sync --all-groups --all-extras
52+
53+
uv run pre-commit install
5254
```
5355

5456
This will:
5557

5658
- create a local `.venv/`
5759
- install dependencies according to `uv.lock`
5860
- keep the environment reproducible
61+
- setup pre-commit hooks
62+
5963

6064
## Running tests
6165

@@ -141,13 +145,13 @@ We use:
141145
Run all linters:
142146

143147
```bash
144-
make check-linting
148+
make lint
145149
```
146150

147151
Auto-fix formatting where possible:
148152

149153
```bash
150-
make fix-linting
154+
make lint-fix
151155
```
152156

153157
## Building the package

Makefile

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,81 @@
1-
check-linting:
2-
uv run ruff check typeid/ tests/
3-
uv run black --check --diff typeid/ tests/ --line-length 119
4-
uv run mypy typeid/ --pretty
1+
# ==============================================================================
2+
# Project configuration
3+
# ==============================================================================
54

5+
PACKAGE := typeid
6+
TESTS := tests
7+
DIST_DIR := dist
8+
VENV_DIR := .venv
69

7-
fix-linting:
8-
uv run ruff check --fix typeid/ tests/
9-
uv run black typeid/ tests/ --line-length 119
10+
UV := uv run
11+
PYTEST := $(UV) pytest
12+
RUFF := $(UV) ruff
13+
BLACK := $(UV) black
14+
MYPY := $(UV) mypy
1015

16+
# ==============================================================================
17+
# Phony targets
18+
# ==============================================================================
1119

12-
.PHONY: build-sdist
13-
build-sdist:
14-
@rm -rf dist build *.egg-info .venv
15-
@uv build --sdist -o dist
16-
@ls -la dist
20+
.PHONY: help lint lint-fix test test-docs docs docs-build build-sdist clean
1721

22+
# ==============================================================================
23+
# Help
24+
# ==============================================================================
1825

19-
test:
20-
uv run pytest -v
26+
help:
27+
@echo "Available targets:"
28+
@echo ""
29+
@echo " lint Run all linters (ruff, black, mypy)"
30+
@echo " lint-fix Automatically fix linting issues"
31+
@echo " test Run test suite"
32+
@echo " test-docs Run documentation tests"
33+
@echo " docs Serve documentation locally"
34+
@echo " docs-build Build documentation"
35+
@echo " build-sdist Build source distribution"
36+
@echo " clean Remove build artifacts"
37+
@echo ""
38+
39+
# ==============================================================================
40+
# Linting
41+
# ==============================================================================
42+
43+
lint:
44+
$(RUFF) check $(PACKAGE)/ $(TESTS)/
45+
$(BLACK) --check --diff $(PACKAGE)/ $(TESTS)/
46+
$(MYPY) $(PACKAGE)/
47+
48+
lint-fix:
49+
$(RUFF) check --fix $(PACKAGE)/ $(TESTS)/
50+
$(BLACK) $(PACKAGE)/ $(TESTS)/
51+
52+
# ==============================================================================
53+
# Testing
54+
# ==============================================================================
2155

56+
test:
57+
$(PYTEST) -v $(TESTS)
2258

2359
test-docs:
24-
uv run pytest README.md docs/ --markdown-docs
60+
$(PYTEST) README.md docs/ --markdown-docs
2561

62+
# ==============================================================================
63+
# Documentation
64+
# ==============================================================================
2665

2766
docs:
2867
mkdocs serve
2968

30-
31-
docs-build:
69+
docs-build:
3270
mkdocs build
71+
72+
# ==============================================================================
73+
# Build & cleanup
74+
# ==============================================================================
75+
76+
build-sdist: clean
77+
@uv build --sdist -o $(DIST_DIR)
78+
@ls -la $(DIST_DIR)
79+
80+
clean:
81+
@rm -rf $(DIST_DIR) build *.egg-info $(VENV_DIR)

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,19 @@ dev = [
4949
"pytest-markdown-docs>=0.9.0",
5050
"pytest-benchmark>=5.0.1",
5151
"maturin>=1.5; platform_system != 'Windows'",
52+
"pre-commit>=4.5.1",
5253
]
5354

55+
[tool.black]
56+
line-length = 119
57+
58+
[tool.ruff]
59+
line-length = 119
60+
target-version = "py311"
61+
62+
[tool.mypy]
63+
pretty = true
64+
5465
[build-system]
5566
requires = ["maturin>=1.5"]
5667
build-backend = "maturin"

pytest.ini

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

uv.lock

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)