-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
447 lines (418 loc) · 14.3 KB
/
Makefile
File metadata and controls
447 lines (418 loc) · 14.3 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
.PHONY: clean clean-pyc clean-build clean-test clean-all test build publish publish-test publish-manual help install dev-install dev-install-all version bump-patch bump-minor bump-major release
# Default target
help:
@echo "Available targets:"
@echo " clean - Remove Python bytecode and basic artifacts"
@echo " clean-all - Deep clean everything (pyc, build, test, cache)"
@echo " clean-pyc - Remove Python bytecode files"
@echo " clean-build - Remove build artifacts"
@echo " clean-test - Remove test artifacts"
@echo " install - Install package in current environment"
@echo " dev-install - Install package in development mode"
@echo " dev-install-all - Install with all optional dependencies"
@echo " test - Run tests"
@echo " test-cov - Run tests with coverage report"
@echo " coverage-report - Show current coverage report"
@echo " lint - Run code linters"
@echo " format - Auto-format code"
@echo " typecheck - Run type checking"
@echo " security - Run security checks"
@echo " check - Run all checks (lint, typecheck, security, test)"
@echo " build - Build the project"
@echo ""
@echo "Release targets:"
@echo " version - Show current version"
@echo " bump-patch - Bump patch version (0.0.X)"
@echo " bump-minor - Bump minor version (0.X.0)"
@echo " bump-major - Bump major version (X.0.0)"
@echo " publish - Create tag and trigger automated release"
@echo " publish-test - Upload to TestPyPI for testing"
@echo " publish-manual - Manually upload to PyPI (requires PYPI_TOKEN)"
@echo " release - Alias for publish"
# Basic clean - Python bytecode and common artifacts
clean: clean-pyc clean-build
@echo "Basic clean complete."
# Remove Python bytecode files and __pycache__ directories
clean-pyc:
@echo "Cleaning Python bytecode files..."
@find . -type f -name '*.pyc' -delete 2>/dev/null || true
@find . -type f -name '*.pyo' -delete 2>/dev/null || true
@find . -type d -name '__pycache__' -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name '*.egg-info' -exec rm -rf {} + 2>/dev/null || true
# Remove build artifacts
clean-build:
@echo "Cleaning build artifacts..."
@rm -rf build/ dist/ *.egg-info 2>/dev/null || true
@rm -rf .eggs/ 2>/dev/null || true
@find . -name '*.egg' -exec rm -f {} + 2>/dev/null || true
# Remove test artifacts
clean-test:
@echo "Cleaning test artifacts..."
@rm -rf .pytest_cache/ 2>/dev/null || true
@rm -rf .coverage 2>/dev/null || true
@rm -rf htmlcov/ 2>/dev/null || true
@rm -rf .tox/ 2>/dev/null || true
@rm -rf .cache/ 2>/dev/null || true
@find . -name '.coverage.*' -delete 2>/dev/null || true
# Deep clean - everything
clean-all: clean-pyc clean-build clean-test
@echo "Deep cleaning..."
@rm -rf .mypy_cache/ 2>/dev/null || true
@rm -rf .ruff_cache/ 2>/dev/null || true
@rm -rf .uv/ 2>/dev/null || true
@rm -rf node_modules/ 2>/dev/null || true
@find . -name '.DS_Store' -delete 2>/dev/null || true
@find . -name 'Thumbs.db' -delete 2>/dev/null || true
@find . -name '*.log' -delete 2>/dev/null || true
@find . -name '*.tmp' -delete 2>/dev/null || true
@find . -name '*~' -delete 2>/dev/null || true
@echo "Deep clean complete."
# Install package
install:
@echo "Installing package..."
pip install .
# Install package in development mode with all dependencies
dev-install:
@echo "Installing package in development mode..."
@if command -v uv >/dev/null 2>&1; then \
uv pip install -e ".[dev]"; \
else \
pip install -e ".[dev]"; \
fi
@echo ""
@echo "✓ Development environment ready!"
@echo ""
@echo "Available commands:"
@echo " make test - Run tests"
@echo " make test-cov - Run tests with coverage"
@echo " make check - Run all checks (lint, typecheck, security, test)"
# Install package in development mode with ALL optional dependencies
dev-install-all:
@echo "Installing package in development mode with all optional dependencies..."
@if command -v uv >/dev/null 2>&1; then \
uv pip install -e ".[dev]"; \
else \
pip install -e ".[dev]"; \
fi
@echo ""
@echo "✓ Development environment ready with all features!"
# Run tests
test:
@echo "Running tests..."
@if command -v uv >/dev/null 2>&1; then \
uv run pytest; \
elif command -v pytest >/dev/null 2>&1; then \
pytest; \
else \
python -m pytest; \
fi
# Show current coverage report
coverage-report:
@echo "Coverage Report:"
@echo "================"
@if command -v uv >/dev/null 2>&1; then \
uv run coverage report --omit="tests/*" || echo "No coverage data found. Run 'make test-cov' first."; \
else \
coverage report --omit="tests/*" || echo "No coverage data found. Run 'make test-cov' first."; \
fi
# Run tests with coverage
test-cov coverage:
@echo "Running tests with coverage..."
@if command -v uv >/dev/null 2>&1; then \
uv run pytest --cov=src --cov-report=html --cov-report=term --cov-report=term-missing:skip-covered; \
exit_code=$$?; \
echo ""; \
echo "=========================="; \
echo "Coverage Summary:"; \
echo "=========================="; \
uv run coverage report --omit="tests/*" | tail -5; \
echo ""; \
echo "HTML coverage report saved to: htmlcov/index.html"; \
exit $$exit_code; \
else \
pytest --cov=src --cov-report=html --cov-report=term --cov-report=term-missing:skip-covered; \
exit_code=$$?; \
echo ""; \
echo "=========================="; \
echo "Coverage Summary:"; \
echo "=========================="; \
coverage report --omit="tests/*" | tail -5; \
echo ""; \
echo "HTML coverage report saved to: htmlcov/index.html"; \
exit $$exit_code; \
fi
# Build the project using the pyproject.toml configuration
build: clean-build
@echo "Building project..."
@if command -v uv >/dev/null 2>&1; then \
uv build; \
else \
python3 -m build; \
fi
@echo "Build complete. Distributions are in the 'dist' folder."
# ============================================================================
# Version Management and Release Targets
# ============================================================================
# Show current version
version:
@version=$$(grep '^version = ' pyproject.toml | cut -d'"' -f2); \
echo "Current version: $$version"
# Bump patch version (0.0.X)
bump-patch:
@echo "Bumping patch version..."
@current=$$(grep '^version = ' pyproject.toml | cut -d'"' -f2); \
major=$$(echo $$current | cut -d. -f1); \
minor=$$(echo $$current | cut -d. -f2); \
patch=$$(echo $$current | cut -d. -f3 | sed 's/[^0-9].*//'); \
new_patch=$$(($$patch + 1)); \
new_version="$$major.$$minor.$$new_patch"; \
sed -i.bak "s/^version = \"$$current\"/version = \"$$new_version\"/" pyproject.toml && rm pyproject.toml.bak; \
echo "Version bumped: $$current -> $$new_version"; \
echo "Review the change, then run 'make publish' to release"
# Bump minor version (0.X.0)
bump-minor:
@echo "Bumping minor version..."
@current=$$(grep '^version = ' pyproject.toml | cut -d'"' -f2); \
major=$$(echo $$current | cut -d. -f1); \
minor=$$(echo $$current | cut -d. -f2 | sed 's/[^0-9].*//'); \
new_minor=$$(($$minor + 1)); \
new_version="$$major.$$new_minor.0"; \
sed -i.bak "s/^version = \"$$current\"/version = \"$$new_version\"/" pyproject.toml && rm pyproject.toml.bak; \
echo "Version bumped: $$current -> $$new_version"; \
echo "Review the change, then run 'make publish' to release"
# Bump major version (X.0.0)
bump-major:
@echo "Bumping major version..."
@current=$$(grep '^version = ' pyproject.toml | cut -d'"' -f2); \
major=$$(echo $$current | cut -d. -f1 | sed 's/[^0-9].*//'); \
new_major=$$(($$major + 1)); \
new_version="$$new_major.0.0"; \
sed -i.bak "s/^version = \"$$current\"/version = \"$$new_version\"/" pyproject.toml && rm pyproject.toml.bak; \
echo "Version bumped: $$current -> $$new_version"; \
echo "Review the change, then run 'make publish' to release"
# Automated release - creates tag and pushes to trigger GitHub Actions
publish:
@echo "Starting automated release process..."
@echo ""
@# Get current version
@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 pushed successfully!" && \
echo "" && \
repo_path=$$(git config --get remote.origin.url | sed 's|^https://github.com/||;s|^git@github.com:||;s|\.git$$||'); \
echo "GitHub Actions workflows triggered:" && \
echo " - Release creation: https://github.com/$$repo_path/actions/workflows/release.yml" && \
echo " - PyPI publishing: https://github.com/$$repo_path/actions/workflows/publish.yml" && \
echo "" && \
echo "Monitor progress at: https://github.com/$$repo_path/actions"
# Alias for publish
release: publish
# ============================================================================
# PyPI Publishing Targets
# ============================================================================
# Upload to TestPyPI for testing
publish-test: build
@echo "Publishing to TestPyPI..."
@echo ""
@version=$$(grep '^version = ' pyproject.toml | cut -d'"' -f2); \
echo "Version: $$version"; \
echo ""; \
if command -v uv >/dev/null 2>&1; then \
uv run twine upload --repository testpypi dist/*; \
else \
python3 -m twine upload --repository testpypi dist/*; \
fi; \
echo ""; \
echo "✓ Uploaded to TestPyPI!"; \
echo ""; \
echo "Install with:"; \
echo " pip install --index-url https://test.pypi.org/simple/ chuk-artifacts==$$version"
# Manual publish to PyPI (requires PYPI_TOKEN environment variable)
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 \
python3 -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 \
python3 -m twine upload dist/*; \
fi; \
fi; \
echo ""; \
echo "✓ Published to PyPI!"; \
echo ""; \
if git tag -l | grep -q "^$$tag$$"; then \
echo "Push tag with: git push origin $$tag"; \
fi; \
echo "Install with: pip install chuk-artifacts==$$version"
# Check code quality
lint:
@echo "Running linters..."
@if command -v uv >/dev/null 2>&1; then \
uv run ruff check .; \
uv run ruff format --check .; \
elif command -v ruff >/dev/null 2>&1; then \
ruff check .; \
ruff format --check .; \
else \
echo "Ruff not found. Install with: pip install ruff"; \
fi
# Fix code formatting
format:
@echo "Formatting code..."
@if command -v uv >/dev/null 2>&1; then \
uv run ruff format .; \
uv run ruff check --fix .; \
elif command -v ruff >/dev/null 2>&1; then \
ruff format .; \
ruff check --fix .; \
else \
echo "Ruff not found. Install with: pip install ruff"; \
fi
# Type checking
typecheck:
@echo "Running type checker..."
@if command -v uv >/dev/null 2>&1; then \
uv run mypy src; \
elif command -v mypy >/dev/null 2>&1; then \
mypy src; \
else \
echo "MyPy not found. Install with: pip install mypy"; \
fi
# Security checks
security:
@echo "Running security checks..."
@if command -v uv >/dev/null 2>&1; then \
uv run bandit -r src -ll; \
elif command -v bandit >/dev/null 2>&1; then \
bandit -r src -ll; \
else \
echo "Bandit not found. Install with: pip install bandit"; \
fi
# Run all checks
check: lint typecheck security test
@echo "All checks completed."
# Show project info
info:
@echo "Project Information:"
@echo "==================="
@if [ -f "pyproject.toml" ]; then \
echo "pyproject.toml found"; \
if command -v uv >/dev/null 2>&1; then \
echo "UV version: $$(uv --version)"; \
fi; \
if command -v python >/dev/null 2>&1; then \
echo "Python version: $$(python --version)"; \
fi; \
else \
echo "No pyproject.toml found"; \
fi
@echo "Current directory: $$(pwd)"
@echo "Git status:"
@git status --porcelain 2>/dev/null || echo "Not a git repository"