-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
397 lines (367 loc) · 11.7 KB
/
Makefile
File metadata and controls
397 lines (367 loc) · 11.7 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
.PHONY: help install dev-install test test-cov test-watch check lint format format-check typecheck security clean clean-build clean-all build publish publish-manual publish-test example-basic example-demo generate-samples serve-coverage dev quick-check ci version
# Variables
PYTHON := python3
PIP := $(PYTHON) -m pip
PYTEST := $(PYTHON) -m pytest
RUFF := ruff
MYPY := mypy
# Directories
SRC_DIR := src
TEST_DIR := tests
EXAMPLES_DIR := examples
SCRIPTS_DIR := scripts
# Default target
help:
@echo "Chuk Math Gym - Available Commands"
@echo "==================================="
@echo ""
@echo "Setup & Installation:"
@echo " make install - Install production dependencies"
@echo " make dev-install - Install development dependencies"
@echo ""
@echo "Testing:"
@echo " make test - Run tests"
@echo " make test-cov - Run tests with coverage report"
@echo " make test-watch - Run tests in watch mode"
@echo " make serve-coverage - Serve HTML coverage report on localhost:8000"
@echo ""
@echo "Code Quality:"
@echo " make check - Run all checks (lint + type check + test)"
@echo " make lint - Run linter (ruff)"
@echo " make format - Format code with ruff"
@echo " make format-check - Check code formatting"
@echo " make typecheck - Run type checker (mypy)"
@echo " make security - Run security checks (bandit)"
@echo ""
@echo "Examples:"
@echo " make example-basic - Run basic usage example"
@echo " make example-demo - Run full system demo"
@echo ""
@echo "Data Generation:"
@echo " make generate-samples - Generate verifier training samples"
@echo ""
@echo "Build & Publishing:"
@echo " make build - Build distribution packages"
@echo " make publish - Build and publish to PyPI (via GitHub trusted publishing)"
@echo " make publish-manual - Build and publish to PyPI (manual with twine)"
@echo " make publish-test - Build and publish to TestPyPI"
@echo ""
@echo "Cleanup:"
@echo " make clean - Remove generated files"
@echo " make clean-all - Remove all generated files and caches"
# Setup & Installation
install:
@echo "Installing production dependencies..."
@if command -v uv >/dev/null 2>&1; then \
uv pip install -e .; \
else \
$(PIP) install -e .; \
fi
dev-install:
@echo "Installing development dependencies..."
@if command -v uv >/dev/null 2>&1; then \
uv pip install -e ".[dev]"; \
else \
$(PIP) install -e ".[dev]"; \
fi
# Testing
test:
@echo "Running tests..."
@if command -v uv >/dev/null 2>&1; then \
PYTHONPATH=$(SRC_DIR) uv run pytest $(TEST_DIR) -v; \
else \
PYTHONPATH=$(SRC_DIR) $(PYTEST) $(TEST_DIR) -v; \
fi
test-cov coverage:
@echo "Running tests with coverage..."
@if command -v uv >/dev/null 2>&1; then \
PYTHONPATH=$(SRC_DIR) uv run pytest $(TEST_DIR) --cov=$(SRC_DIR)/chuk_math_gym --cov-report=term-missing --cov-report=html --cov-report=xml; \
else \
PYTHONPATH=$(SRC_DIR) $(PYTEST) $(TEST_DIR) --cov=$(SRC_DIR)/chuk_math_gym --cov-report=term-missing --cov-report=html --cov-report=xml; \
fi
@echo ""
@echo "Coverage report generated in htmlcov/index.html"
test-watch:
@echo "Running tests in watch mode..."
@if command -v uv >/dev/null 2>&1; then \
PYTHONPATH=$(SRC_DIR) uv run pytest-watch $(TEST_DIR); \
else \
PYTHONPATH=$(SRC_DIR) $(PYTHON) -m pytest_watch $(TEST_DIR); \
fi
# Code Quality
check: lint typecheck test
@echo ""
@echo "✓ All checks passed!"
lint:
@echo "Running linter..."
@if command -v uv >/dev/null 2>&1; then \
uv run ruff check $(SRC_DIR) $(TEST_DIR); \
uv run ruff format --check $(SRC_DIR) $(TEST_DIR); \
elif command -v $(RUFF) >/dev/null 2>&1; then \
$(RUFF) check $(SRC_DIR) $(TEST_DIR); \
$(RUFF) format --check $(SRC_DIR) $(TEST_DIR); \
else \
echo "Ruff not found. Install with: pip install ruff"; \
exit 1; \
fi
format:
@echo "Formatting code..."
@if command -v uv >/dev/null 2>&1; then \
uv run ruff format $(SRC_DIR) $(TEST_DIR); \
uv run ruff check --fix $(SRC_DIR) $(TEST_DIR); \
elif command -v $(RUFF) >/dev/null 2>&1; then \
$(RUFF) format $(SRC_DIR) $(TEST_DIR); \
$(RUFF) check --fix $(SRC_DIR) $(TEST_DIR); \
else \
echo "Ruff not found. Install with: pip install ruff"; \
exit 1; \
fi
format-check:
@echo "Checking code formatting..."
@if command -v uv >/dev/null 2>&1; then \
uv run ruff format --check $(SRC_DIR) $(TEST_DIR); \
elif command -v $(RUFF) >/dev/null 2>&1; then \
$(RUFF) format --check $(SRC_DIR) $(TEST_DIR); \
else \
echo "Ruff not found. Install with: pip install ruff"; \
exit 1; \
fi
typecheck:
@echo "Running type checker..."
@if command -v uv >/dev/null 2>&1; then \
uv run mypy $(SRC_DIR) || echo "Type check found issues (non-blocking)"; \
elif command -v $(MYPY) >/dev/null 2>&1; then \
$(MYPY) $(SRC_DIR) || echo "Type check found issues (non-blocking)"; \
else \
echo "MyPy not found. Install with: pip install mypy"; \
exit 1; \
fi
# Alias for typecheck
type-check: typecheck
# Security
security:
@echo "Running security checks..."
@if command -v uv >/dev/null 2>&1; then \
uv run bandit -r $(SRC_DIR) -f txt || echo "Security issues found (non-blocking)"; \
elif command -v bandit >/dev/null 2>&1; then \
bandit -r $(SRC_DIR) -f txt || echo "Security issues found (non-blocking)"; \
else \
echo "Bandit not found. Install with: pip install bandit"; \
exit 1; \
fi
# Examples
example-basic:
@echo "Running basic usage example..."
@if command -v uv >/dev/null 2>&1; then \
PYTHONPATH=$(SRC_DIR) uv run python $(EXAMPLES_DIR)/basic_usage.py; \
else \
PYTHONPATH=$(SRC_DIR) $(PYTHON) $(EXAMPLES_DIR)/basic_usage.py; \
fi
example-demo:
@echo "Running full system demo..."
@if command -v uv >/dev/null 2>&1; then \
PYTHONPATH=$(SRC_DIR) uv run python $(EXAMPLES_DIR)/demo_full_system.py; \
else \
PYTHONPATH=$(SRC_DIR) $(PYTHON) $(EXAMPLES_DIR)/demo_full_system.py; \
fi
# Data Generation
generate-samples:
@echo "Generating verifier training samples..."
@if command -v uv >/dev/null 2>&1; then \
PYTHONPATH=$(SRC_DIR) uv run python $(SCRIPTS_DIR)/generate_verifier_samples.py; \
else \
PYTHONPATH=$(SRC_DIR) $(PYTHON) $(SCRIPTS_DIR)/generate_verifier_samples.py; \
fi
# Build & Publishing
build: clean-build
@echo "Building distribution packages..."
@if command -v uv >/dev/null 2>&1; then \
uv build; \
else \
$(PYTHON) -m build; \
fi
@echo ""
@echo "Build complete. Distributions are in the 'dist' folder."
@ls -lh dist/
publish:
@echo "Starting automated release process..."
@echo ""
@version=$$(grep '^version = ' pyproject.toml | cut -d'"' -f2); \
tag="v$$version"; \
echo "Version: $$version"; \
echo "Tag: $$tag"; \
echo ""; \
\
echo "Pre-flight checks:"; \
echo "=================="; \
\
if git diff --quiet && git diff --cached --quiet; then \
echo "✓ Working directory is clean"; \
else \
echo "✗ Working directory has uncommitted changes"; \
echo ""; \
git status --short; \
echo ""; \
echo "Please commit or stash your changes before releasing."; \
exit 1; \
fi; \
\
if git tag -l | grep -q "^$$tag$$"; then \
echo "✗ Tag $$tag already exists"; \
echo ""; \
echo "To delete and recreate:"; \
echo " git tag -d $$tag"; \
echo " git push origin :refs/tags/$$tag"; \
exit 1; \
else \
echo "✓ Tag $$tag does not exist yet"; \
fi; \
\
current_branch=$$(git rev-parse --abbrev-ref HEAD); \
echo "✓ Current branch: $$current_branch"; \
echo ""; \
\
echo "This will:"; \
echo " 1. Create and push tag $$tag"; \
echo " 2. Trigger GitHub Actions to:"; \
echo " - Create a GitHub release with changelog"; \
echo " - Run tests on all platforms"; \
echo " - Build and publish to PyPI"; \
echo ""; \
read -p "Continue? (y/N) " -n 1 -r; \
echo ""; \
if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then \
echo "Aborted."; \
exit 1; \
fi; \
\
echo ""; \
echo "Creating and pushing tag..."; \
git tag -a "$$tag" -m "Release $$tag"; \
git push origin "$$tag"; \
echo ""; \
echo "✓ Tag $$tag created and pushed"; \
echo ""; \
echo "GitHub Actions will now:"; \
echo " - Run tests"; \
echo " - Create GitHub release"; \
echo " - Publish to PyPI"; \
echo ""; \
echo "Monitor progress at:"; \
echo " https://github.com/chrishayuk/chuk-math/actions"
publish-manual: build
@echo "Manual PyPI Publishing"
@echo "======================"
@echo ""
@version=$$(grep '^version = ' pyproject.toml | cut -d'"' -f2); \
tag="v$$version"; \
echo "Version: $$version"; \
echo "Tag: $$tag"; \
echo ""; \
\
echo "Pre-flight checks:"; \
echo "=================="; \
\
if git diff --quiet && git diff --cached --quiet; then \
echo "✓ Working directory is clean"; \
else \
echo "✗ Working directory has uncommitted changes"; \
echo ""; \
git status --short; \
echo ""; \
echo "Please commit or stash your changes before publishing."; \
exit 1; \
fi; \
\
if git tag -l | grep -q "^$$tag$$"; then \
echo "✓ Tag $$tag exists"; \
else \
echo "⚠ Tag $$tag does not exist yet"; \
echo ""; \
read -p "Create tag now? (y/N) " -n 1 -r; \
echo ""; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
git tag -a "$$tag" -m "Release $$tag"; \
echo "✓ Tag created locally"; \
else \
echo "Continuing without creating tag..."; \
fi; \
fi; \
\
echo ""; \
echo "This will upload version $$version to PyPI"; \
echo ""; \
read -p "Continue? (y/N) " -n 1 -r; \
echo ""; \
if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then \
echo "Aborted."; \
exit 1; \
fi; \
\
echo ""; \
echo "Uploading to PyPI..."; \
if [ -n "$$PYPI_TOKEN" ]; then \
if command -v uv >/dev/null 2>&1; then \
uv run twine upload --username __token__ --password "$$PYPI_TOKEN" dist/*; \
else \
$(PYTHON) -m twine upload --username __token__ --password "$$PYPI_TOKEN" dist/*; \
fi; \
else \
if command -v uv >/dev/null 2>&1; then \
uv run twine upload dist/*; \
else \
$(PYTHON) -m twine upload dist/*; \
fi; \
fi
publish-test: build
@echo "Publishing to TestPyPI..."
@echo ""
@if [ -n "$$PYPI_TOKEN" ]; then \
if command -v uv >/dev/null 2>&1; then \
uv run twine upload --repository testpypi --username __token__ --password "$$PYPI_TOKEN" dist/*; \
else \
$(PYTHON) -m twine upload --repository testpypi --username __token__ --password "$$PYPI_TOKEN" dist/*; \
fi; \
else \
if command -v uv >/dev/null 2>&1; then \
uv run twine upload --repository testpypi dist/*; \
else \
$(PYTHON) -m twine upload --repository testpypi dist/*; \
fi; \
fi
# Cleanup
clean:
@echo "Cleaning generated files..."
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete 2>/dev/null || true
find . -type f -name "*.pyo" -delete 2>/dev/null || true
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
rm -rf .pytest_cache .mypy_cache .ruff_cache .coverage htmlcov coverage.xml 2>/dev/null || true
clean-build:
@echo "Cleaning build artifacts..."
@rm -rf build/ dist/ *.egg-info $(SRC_DIR)/*.egg-info 2>/dev/null || true
@rm -rf .eggs/ 2>/dev/null || true
@find . -name '*.egg' -exec rm -f {} + 2>/dev/null || true
clean-all: clean clean-build
@echo "Cleaning all files..."
rm -rf output/*.jsonl 2>/dev/null || true
find . -name '.DS_Store' -delete 2>/dev/null || true
# Development helpers
serve-coverage:
@echo "Serving coverage report on http://localhost:8000..."
cd htmlcov && $(PYTHON) -m http.server 8000
dev: dev-install
@echo "Development environment ready!"
@echo "Run 'make test' to run tests"
quick-check: format lint
@echo "Quick check complete!"
# CI/CD helpers
ci: dev-install check
@echo "CI pipeline complete!"
# Version info
version:
@echo "Python version:"
@$(PYTHON) --version
@echo ""
@echo "Package version:"
@grep '^version = ' pyproject.toml