Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
203 lines (147 loc) · 6.96 KB
/
Copy pathMakefile
File metadata and controls
203 lines (147 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
.DEFAULT_GOAL := help
SHELL := /bin/bash
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
.PHONY: lock-install install install-dev update update-deps hooks
lock-install: ## Lock and install project dependencies
poetry lock
poetry install
install: ## Install project with all dependencies
poetry install
install-dev: ## Install with dev dependencies
poetry install --with dev
update: ## Update dependencies
poetry update
update-deps: ## Update dependencies, verify build, and run tests
poetry update
poetry build
poetry run pytest -q --maxfail=1 --disable-warnings --no-cov
hooks: ## Install pre-commit hooks
poetry run pre-commit install
# ---------------------------------------------------------------------------
# Code Quality
# ---------------------------------------------------------------------------
.PHONY: lint lint-fix format format-check fix typecheck codespell codespell-fix precommit
lint: ## Run ruff linter
poetry run ruff check src/ tests/
lint-fix: ## Run ruff linter with auto-fix
poetry run ruff check src/ tests/ --fix --unsafe-fixes
format: ## Format code with black
poetry run black src/ tests/
format-check: ## Check formatting without changes
poetry run black --check src/ tests/
fix: ## Run all auto-fixes (ruff + black)
poetry run ruff check src/ tests/ --fix --unsafe-fixes
poetry run black src/ tests/
typecheck: ## Run MyPy type checks
poetry run mypy src/
codespell: ## Run codespell
poetry run codespell src/ tests/
codespell-fix: ## Run codespell with auto-fix
poetry run codespell src/ tests/ --write-changes
precommit: ## Run all pre-commit hooks
poetry run pre-commit run -a
# ---------------------------------------------------------------------------
# Tests
# ---------------------------------------------------------------------------
.PHONY: test test-v test-fast test-cov test-xml
test: ## Run all tests
poetry run pytest
test-v: ## Run all tests (verbose)
poetry run pytest -v
test-fast: ## Run tests without coverage (faster)
poetry run pytest -q --maxfail=1 --disable-warnings --no-cov
test-cov: ## Run tests with coverage report
poetry run pytest --cov=manuscripta --cov-report=term-missing
test-xml: ## Run tests with XML coverage (for CI)
poetry run pytest -q --maxfail=1 --disable-warnings --cov=manuscripta --cov-report=xml
# ---------------------------------------------------------------------------
# Mutation testing (Phase 4b)
# ---------------------------------------------------------------------------
# Runs nightly in CI, not per-PR (~10+ min). Not a merge gate; a quality
# signal. Scope and thresholds live in pyproject.toml; policy in
# docs/decisions/0002-mutation-testing.md; response workflow in TESTING.md §14.
.PHONY: mutation mutation-check mutation-report mutation-fast
mutation: ## Run mutation tests on the configured scope (no threshold enforcement; needs `poetry install --with mutation`)
poetry run mutmut run
mutation-check: mutation ## Run mutation tests + enforce per-module thresholds (CI gate)
poetry run python scripts/check_mutation_thresholds.py
mutation-report: ## Print a human-readable report of surviving mutants
poetry run mutmut results
# mutmut 3.x filters by fnmatch glob over MUTANT NAMES (manuscripta.a.b.*),
# not file paths, so each changed in-scope file is mapped to its pattern
# (src/manuscripta/a/b.py -> manuscripta.a.b.*; a package's __init__.py ->
# manuscripta.a.*). Any filtered run resets every other in-scope module to
# "not checked", which check_mutation_thresholds.py fails on by design.
mutation-fast: ## Dev loop — mutate only the in-scope modules changed since main (resets the other modules' results; run `make mutation` before `make mutation-check`)
@CHANGED=$$(git diff --name-only origin/main...HEAD -- 'src/manuscripta/**/*.py'); \
PATTERNS=""; \
for f in $$CHANGED; do \
if grep -q "\"$$f\"" pyproject.toml; then \
PATTERNS="$$PATTERNS $$(echo "$$f" | sed -e 's#^src/##' -e 's#/__init__\.py$$##' -e 's#\.py$$##' -e 's#/#.#g' -e 's#$$#.*#')"; \
else \
echo "Skipping $$f: not in [tool.mutmut] paths_to_mutate."; \
fi; \
done; \
if [ -z "$$PATTERNS" ]; then \
echo "No in-scope Python sources changed vs origin/main; nothing to mutate."; \
exit 0; \
fi; \
echo "Mutating only:$$PATTERNS"; \
echo "NOTICE: a filtered run resets every other in-scope module's results to 'not checked';"; \
echo " run 'make mutation' before 'make mutation-check' (the threshold check fails on unchecked mutants)."; \
set -f; poetry run mutmut run $$PATTERNS
# ---------------------------------------------------------------------------
# CI
# ---------------------------------------------------------------------------
.PHONY: ci
ci: lint format-check test ## Full CI pipeline (lint + format-check + test)
# ---------------------------------------------------------------------------
# Version Management
# ---------------------------------------------------------------------------
.PHONY: bump-patch bump-minor bump-major tag-message
bump-patch: ## Bump patch version (0.1.0 -> 0.1.1)
poetry version patch
bump-minor: ## Bump minor version (0.1.0 -> 0.2.0)
poetry version minor
bump-major: ## Bump major version (0.1.0 -> 1.0.0)
poetry version major
tag-message: ## Interactive: generate tag message and (optionally) create tag
poetry run make-tag-message
# ---------------------------------------------------------------------------
# Build & Publish
# ---------------------------------------------------------------------------
.PHONY: build publish publish-test
build: ## Build distribution package
poetry build
publish: ci build ## Run CI, build and publish to PyPI
poetry publish
publish-test: ci build ## Run CI, build and publish to TestPyPI
poetry publish -r testpypi
# ---------------------------------------------------------------------------
# Git
# ---------------------------------------------------------------------------
.PHONY: git-setup
git-setup: ## Configure git hooks and commit template
git config core.hooksPath .githooks
git config commit.template .gitmessage
chmod +x .githooks/*
@echo "Git hooks and commit template activated."
# ---------------------------------------------------------------------------
# Cleanup
# ---------------------------------------------------------------------------
.PHONY: clean clean-venv
clean: ## Remove build artifacts and caches
rm -rf dist/ build/ .pytest_cache/ .ruff_cache/ .mypy_cache/ .coverage coverage.xml
find src/ tests/ -type d -name __pycache__ -exec rm -rf {} +
find . -name '*.pyc' -delete
clean-venv: ## Remove Poetry virtualenv
poetry env remove --all || true
# ---------------------------------------------------------------------------
# Help
# ---------------------------------------------------------------------------
.PHONY: help
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}'