-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
216 lines (180 loc) · 5.24 KB
/
Copy pathMakefile
File metadata and controls
216 lines (180 loc) · 5.24 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
204
205
206
207
208
209
210
211
212
213
214
215
216
VENV_DIR := .venv
PYTHON := $(VENV_DIR)/bin/python
PIP := $(VENV_DIR)/bin/pip
HATCH := $(VENV_DIR)/bin/hatch
PACKAGE_INIT := $(shell find src -mindepth 2 -maxdepth 2 -name "__init__.py" | head -n1)
.PHONY: bootstrap
bootstrap:
@if [ ! -d "$(VENV_DIR)" ]; then \
echo "Creating virtual environment..."; \
python3 -m venv $(VENV_DIR); \
fi
@echo "Ensuring Hatch is installed in virtual environment..."
@$(PIP) install --upgrade pip > /dev/null
@$(PIP) install hatch > /dev/null
@echo "Hatch installed at $(HATCH)"
.PHONY: ensure-hatch
ensure-hatch: bootstrap
.PHONY: install
install: ensure-hatch
@$(HATCH) env create
@if [ -n "$$CI" ]; then \
echo "CI detected: skipping pre-commit hook installation"; \
else \
$(MAKE) precommit-install; \
fi
.PHONY: shell
shell: ensure-hatch
@$(HATCH) shell
.PHONY: reset
reset: clean-all install
@echo "Project reset complete."
.PHONY: hatch-clean
hatch-clean: ensure-hatch
@$(HATCH) env remove || echo "No hatch environment to remove"
.PHONY: format
format: ensure-hatch
@$(HATCH) run format
.PHONY: style
style: ensure-hatch
@$(HATCH) run style
.PHONY: typecheck
typecheck: ensure-hatch
@$(HATCH) run typecheck
.PHONY: lint
lint: ensure-hatch
@$(HATCH) run lint
.PHONY: security
security: ensure-hatch
@$(HATCH) run security
.PHONY: check
check: ensure-hatch
@$(MAKE) lint
@$(MAKE) typecheck
@echo "Lint and type check passed."
.PHONY: lint-workflows
lint-workflows: ensure-hatch
@$(HATCH) run python tools/lint_release_workflows.py
@$(HATCH) run python tools/lint_workflow_pins.py
.PHONY: check-all
check-all: ensure-hatch
@$(MAKE) lint-workflows
@$(MAKE) check
@$(MAKE) test
@$(MAKE) security
@echo "All checks passed including tests and security scan."
.PHONY: precommit
precommit: ensure-hatch
@$(HATCH) run precommit
.PHONY: precommit-install
precommit-install: ensure-hatch
@$(HATCH) run precommit-install
.PHONY: test
test: ensure-hatch
@echo "Running tests..."
@$(HATCH) run test
.PHONY: cov
cov: ensure-hatch
@$(HATCH) run cov
@echo "Open htmlcov/index.html in your browser to view the coverage report."
@echo "coverage.xml generated for Codecov upload."
.PHONY: build
build: ensure-hatch
@$(HATCH) build
.PHONY: changelog
changelog: ensure-hatch
@$(HATCH) run git-cliff -o CHANGELOG.md
@echo "Changelog generated."
.PHONY: commit-changelog
commit-changelog:
@git add CHANGELOG.md
@git commit -m "docs: update changelog" || echo "No changes to commit"
.PHONY: tag-release
tag-release:
ifndef VERSION
$(error VERSION is not set. Usage: make tag-release VERSION=1.0.1)
endif
@git push origin HEAD
@git tag -a v$(VERSION) -m "Release v$(VERSION)"
@git push origin v$(VERSION)
@echo "Tagged release v$(VERSION)"
.PHONY: release
release: ensure-hatch
ifndef VERSION
$(error VERSION is not set. Usage: make release VERSION=1.0.1)
endif
@$(HATCH) version $(VERSION)
@git add "$(PACKAGE_INIT)" && \
git commit -m "build: bump version to $(VERSION)"
@$(MAKE) release-core VERSION=$(VERSION)
.PHONY: release-core
release-core:
ifndef VERSION
$(error VERSION is not set. Usage: make release-core VERSION=1.0.1)
endif
@$(MAKE) changelog
@$(MAKE) commit-changelog
@$(MAKE) tag-release VERSION=$(VERSION)
.PHONY: release-patch
release-patch: ensure-hatch
@$(HATCH) version patch
@VERSION=$$($(HATCH) version | tail -n1); \
git add "$(PACKAGE_INIT)" && \
git commit -m "build: bump version to $$VERSION" && \
$(MAKE) release-core VERSION=$$VERSION
.PHONY: release-minor
release-minor: ensure-hatch
@$(HATCH) version minor
@VERSION=$$($(HATCH) version | tail -n1); \
git add "$(PACKAGE_INIT)" && \
git commit -m "build: bump version to $$VERSION" && \
$(MAKE) release-core VERSION=$$VERSION
.PHONY: release-major
release-major: ensure-hatch
@$(HATCH) version major
@VERSION=$$($(HATCH) version | tail -n1); \
git add "$(PACKAGE_INIT)" && \
git commit -m "build: bump version to $$VERSION" && \
$(MAKE) release-core VERSION=$$VERSION
.PHONY: publish-test
publish-test: ensure-hatch
@$(HATCH) publish --repo test
.PHONY: publish-pypi
publish-pypi: ensure-hatch
@$(HATCH) publish
.PHONY: version
version: ensure-hatch
@echo "Current version:"
@$(HATCH) version
.PHONY: docs
docs:
@if [ -n "$$CI" ]; then \
echo "CI detected: running MkDocs directly"; \
python -m pip install --upgrade pip > /dev/null 2>&1 || true; \
pip install "mkdocs<2.0" "mkdocs-material<10.0" "mkdocstrings[python]<2.0" > /dev/null 2>&1; \
mkdocs build; \
else \
$(MAKE) ensure-hatch > /dev/null; \
$(HATCH) run mkdocs build; \
fi
.PHONY: docs-serve
docs-serve: ensure-hatch
@$(HATCH) run docs
.PHONY: doctor
doctor:
@echo "Python version:" && $(PYTHON) --version
@echo "Installed packages:" && $(HATCH) env run pip list || echo "No hatch environment found"
@echo "Pre-commit hook installed:"
@if [ -f .git/hooks/pre-commit ]; then echo yes; else echo no; fi
.PHONY: clean
clean:
@rm -rf *.egg-info dist build __pycache__ .pytest_cache
.PHONY: clean-all
clean-all: clean
@find . -type d -name "__pycache__" -exec rm -rf {} +
@find . -type f \( -name "*.pyc" -o -name "*.pyo" \) -delete
@rm -rf .mypy_cache .ruff_cache .pytest_cache .coverage coverage.xml htmlcov .DS_Store $(VENV_DIR) site
.PHONY: help
help:
@echo "Available commands:" && \
grep -E '^\.PHONY: ' Makefile | cut -d ':' -f2 | xargs -n1 echo " - make"