-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
100 lines (84 loc) · 3.43 KB
/
Copy pathMakefile
File metadata and controls
100 lines (84 loc) · 3.43 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
# python-utils-rondomondo - Makefile
.DEFAULT_GOAL := help
SHELL := /bin/bash
CYAN := \033[36m
GREEN := \033[32m
RED := \033[31m
RESET := \033[0m
VENV := .venv
UV := uv
PYTEST := $(VENV)/bin/pytest
RUFF := $(VENV)/bin/ruff
MYPY := $(VENV)/bin/mypy
.PHONY: help
help: ## Show this help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " $(CYAN)%-20s$(RESET) %s\n", $$1, $$2}'
.PHONY: venv
venv: ## Create virtual environment (if absent)
@if [ ! -d "$(VENV)" ]; then \
echo " creating venv in $(VENV)..."; \
$(UV) venv $(VENV); \
echo " done - activate with: source $(VENV)/bin/activate"; \
else \
echo " venv already exists"; \
fi
.PHONY: check-venv
check-venv: venv ## Verify the virtual environment is active
@if [ -z "$${VIRTUAL_ENV:-}" ]; then \
printf "$(RED)ERROR:$(RESET) venv not active. Run: source $(VENV)/bin/activate\n"; \
exit 1; \
fi
.PHONY: install
install: venv ## Install package and dev dependencies
$(UV) pip install -e ".[dev]"
@echo " installed. activate with: source $(VENV)/bin/activate"
.PHONY: lint
lint: check-venv ## Lint (ruff + mypy)
$(RUFF) check --fix src/
$(MYPY) src/
.PHONY: test
test: check-venv ## Run tests
$(PYTEST) tests/ -v --tb=short
.PHONY: bump-patch bump-minor bump-major
bump-patch: ## Bump patch version in pyproject.toml (0.1.2 -> 0.1.3)
@old=$$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/'); \
maj=$$(echo $$old | cut -d. -f1); \
min=$$(echo $$old | cut -d. -f2); \
pat=$$(echo $$old | cut -d. -f3); \
new="$$maj.$$min.$$((pat + 1))"; \
sed -i '' "s/^version = \"$$old\"/version = \"$$new\"/" pyproject.toml; \
printf " $(GREEN)$$old$(RESET) -> $(GREEN)$$new$(RESET)\n"
bump-minor: ## Bump minor version in pyproject.toml (0.1.2 -> 0.2.0)
@old=$$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/'); \
maj=$$(echo $$old | cut -d. -f1); \
min=$$(echo $$old | cut -d. -f2); \
new="$$maj.$$((min + 1)).0"; \
sed -i '' "s/^version = \"$$old\"/version = \"$$new\"/" pyproject.toml; \
printf " $(GREEN)$$old$(RESET) -> $(GREEN)$$new$(RESET)\n"
bump-major: ## Bump major version in pyproject.toml (0.1.2 -> 1.0.0)
@old=$$(grep '^version = ' pyproject.toml | sed 's/version = "\(.*\)"/\1/'); \
maj=$$(echo $$old | cut -d. -f1); \
new="$$((maj + 1)).0.0"; \
sed -i '' "s/^version = \"$$old\"/version = \"$$new\"/" pyproject.toml; \
printf " $(GREEN)$$old$(RESET) -> $(GREEN)$$new$(RESET)\n"
.PHONY: build
build: check-venv ## Build wheel and sdist into dist/
$(UV) build
.PHONY: publish-test
publish-test: build ## Upload to TestPyPI
$(UV) publish --index testpypi dist/*.whl dist/*.tar.gz
.PHONY: publish
publish: build ## Upload to PyPI (live)
@printf "$(RED)WARNING:$(RESET) publishing to live PyPI. Ctrl-C to abort, Enter to continue.\n" && read _
$(UV) publish dist/*.whl dist/*.tar.gz
.PHONY: clean
clean: ## Remove build artifacts and caches
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type d -name .pytest_cache -exec rm -rf {} + 2>/dev/null || true
find . -type d -name .mypy_cache -exec rm -rf {} + 2>/dev/null || true
find . -type d -name .ruff_cache -exec rm -rf {} + 2>/dev/null || true
find . -type d -name dist -exec rm -rf {} + 2>/dev/null || true
find . -type d -name build -exec rm -rf {} + 2>/dev/null || true
find . -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
rm -rf .coverage htmlcov/ 2>/dev/null || true