-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
286 lines (247 loc) · 9.53 KB
/
Makefile
File metadata and controls
286 lines (247 loc) · 9.53 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
# AlgoTree Makefile
# Variables
PYTHON := python3
PIP := pip
PACKAGE_NAME := AlgoTree
VERSION_FILE := setup.py
CURRENT_VERSION := $(shell grep -oP "version=\"\K[^\"]*" $(VERSION_FILE))
VENV := .venv
VENV_PYTHON := $(VENV)/bin/python
VENV_PIP := $(VENV)/bin/pip
# Use virtual environment if it exists
ifneq ($(wildcard $(VENV)/bin/activate),)
PYTHON := $(VENV_PYTHON)
PIP := $(VENV_PIP)
endif
# Color output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
# Find source files
SOURCES := $(shell find $(PACKAGE_NAME) -name "*.py")
TESTS := $(shell find test -name "*.py")
# Default target
.DEFAULT_GOAL := help
# Phony targets
.PHONY: help install install-dev test test-verbose lint format clean clean-all docs coverage build release-pypi
.PHONY: version-patch version-minor version-major tag push-tag release-check release release-minor release-major
.PHONY: venv venv-clean venv-activate dev check all setup
.PHONY: docs-serve docs-open docs-deploy-gh-pages docs-clean
## Help
help:
@echo "$(BLUE)AlgoTree Development Commands$(NC)"
@echo ""
@echo "$(GREEN)Environment:$(NC)"
@echo " make venv Create virtual environment"
@echo " make venv-clean Remove virtual environment"
@echo " make venv-activate Show activation command"
@echo ""
@echo "$(GREEN)Development:$(NC)"
@echo " make install Install runtime dependencies"
@echo " make install-dev Install development dependencies"
@echo " make test Run unit tests"
@echo " make test-verbose Run tests with verbose output"
@echo " make lint Run code linting"
@echo " make format Format code with black (if installed)"
@echo " make coverage Run tests with coverage report"
@echo " make clean Clean build artifacts"
@echo ""
@echo "$(GREEN)Documentation:$(NC)"
@echo " make docs Generate documentation"
@echo " make docs-serve Serve docs locally on port 8000"
@echo " make docs-open Open docs in browser"
@echo " make docs-deploy-gh-pages Deploy to GitHub Pages"
@echo " make docs-clean Clean documentation build"
@echo ""
@echo "$(GREEN)Release Management:$(NC)"
@echo " make version-patch Bump patch version (0.0.X)"
@echo " make version-minor Bump minor version (0.X.0)"
@echo " make version-major Bump major version (X.0.0)"
@echo " make release Full release: test, bump patch, tag, and upload to PyPI"
@echo " make release-minor Full release with minor version bump"
@echo " make release-major Full release with major version bump"
@echo ""
@echo "$(YELLOW)Current version: $(CURRENT_VERSION)$(NC)"
@if [ -d "$(VENV)" ]; then \
echo "$(GREEN)Virtual environment: Active ($(VENV))$(NC)"; \
else \
echo "$(YELLOW)Virtual environment: Not created (run 'make venv')$(NC)"; \
fi
## Virtual Environment Management
venv:
@echo "$(BLUE)Creating virtual environment...$(NC)"
@if [ ! -d "$(VENV)" ]; then \
python3 -m venv $(VENV); \
$(VENV_PIP) install --upgrade pip setuptools wheel; \
echo "$(GREEN)Virtual environment created at $(VENV)$(NC)"; \
echo "$(YELLOW)Run 'source $(VENV)/bin/activate' or 'make venv-activate' to activate$(NC)"; \
else \
echo "$(YELLOW)Virtual environment already exists at $(VENV)$(NC)"; \
fi
venv-clean:
@echo "$(BLUE)Removing virtual environment...$(NC)"
@if [ -d "$(VENV)" ]; then \
rm -rf $(VENV); \
echo "$(GREEN)Virtual environment removed$(NC)"; \
else \
echo "$(YELLOW)No virtual environment found$(NC)"; \
fi
venv-activate:
@echo "$(BLUE)To activate the virtual environment, run:$(NC)"
@echo "$(GREEN)source $(VENV)/bin/activate$(NC)"
## Installation
install: venv
@echo "$(BLUE)Installing runtime dependencies...$(NC)"
$(PIP) install -r requirements.txt
$(PIP) install -e .
@echo "$(GREEN)Dependencies installed$(NC)"
install-dev: venv install
@echo "$(BLUE)Installing development dependencies...$(NC)"
$(PIP) install black flake8 pytest pytest-cov wheel twine
@echo "$(GREEN)Development dependencies installed$(NC)"
## Testing
test:
@echo "$(BLUE)Running tests...$(NC)"
$(PYTHON) -m unittest discover -s test
test-verbose:
@echo "$(BLUE)Running tests (verbose)...$(NC)"
$(PYTHON) -m unittest discover -s test -v
## Code Quality
lint:
@echo "$(BLUE)Running linter...$(NC)"
$(PYTHON) -m flake8 $(SOURCES) $(TESTS)
format:
@echo "$(BLUE)Formatting code...$(NC)"
@if command -v black >/dev/null 2>&1; then \
black $(SOURCES) $(TESTS); \
else \
echo "$(RED)black not installed. Run 'make install-dev' first.$(NC)"; \
fi
## Documentation (MkDocs)
docs:
@echo "$(BLUE)Generating documentation...$(NC)"
$(PIP) install mkdocs mkdocs-material mkdocstrings mkdocstrings-python --quiet
$(PIP) install -e . --quiet
mkdocs build
@echo "$(GREEN)Documentation generated in site/$(NC)"
docs-serve:
@echo "$(BLUE)Starting documentation server...$(NC)"
@echo "$(GREEN)Documentation available at http://localhost:8000$(NC)"
@echo "$(YELLOW)Press Ctrl+C to stop the server$(NC)"
$(PIP) install mkdocs mkdocs-material mkdocstrings mkdocstrings-python --quiet
$(PIP) install -e . --quiet
mkdocs serve
docs-open: docs
@echo "$(BLUE)Opening documentation in browser...$(NC)"
@if command -v xdg-open >/dev/null 2>&1; then \
xdg-open site/index.html; \
elif command -v open >/dev/null 2>&1; then \
open site/index.html; \
else \
echo "$(YELLOW)Please open site/index.html in your browser$(NC)"; \
fi
docs-deploy-gh-pages:
@echo "$(BLUE)Deploying documentation to GitHub Pages...$(NC)"
$(PIP) install mkdocs mkdocs-material mkdocstrings mkdocstrings-python --quiet
$(PIP) install -e . --quiet
mkdocs gh-deploy --force
@echo "$(GREEN)Documentation deployed to GitHub Pages$(NC)"
@echo "$(GREEN)Visit: https://queelius.github.io/AlgoTree/$(NC)"
docs-clean:
@echo "$(BLUE)Cleaning documentation...$(NC)"
rm -rf site/
@echo "$(GREEN)Documentation cleaned$(NC)"
## Coverage
coverage:
@echo "$(BLUE)Running coverage analysis...$(NC)"
coverage run -m unittest discover -s test
coverage report
coverage html
coverage json
@echo "$(GREEN)Coverage report generated$(NC)"
## Build
build: clean
@echo "$(BLUE)Building distribution packages...$(NC)"
$(PYTHON) setup.py sdist bdist_wheel
@echo "$(GREEN)Build complete$(NC)"
## Cleaning
clean:
@echo "$(BLUE)Cleaning build artifacts...$(NC)"
rm -rf build dist *.egg-info
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
rm -rf .coverage htmlcov coverage.json
@echo "$(GREEN)Clean complete$(NC)"
clean-all: clean venv-clean
@echo "$(GREEN)Full clean complete (including virtual environment)$(NC)"
## Version Management
version-patch:
@echo "$(BLUE)Bumping patch version...$(NC)"
@NEW_VERSION=$$(echo $(CURRENT_VERSION) | awk -F. '{$$NF = $$NF + 1;} 1' | sed 's/ /./g'); \
sed -i "s/version=\"$(CURRENT_VERSION)\"/version=\"$$NEW_VERSION\"/" $(VERSION_FILE); \
echo "$(GREEN)Version bumped from $(CURRENT_VERSION) to $$NEW_VERSION$(NC)"
version-minor:
@echo "$(BLUE)Bumping minor version...$(NC)"
@NEW_VERSION=$$(echo $(CURRENT_VERSION) | awk -F. '{$$2 = $$2 + 1; $$3 = 0;} 1' | sed 's/ /./g'); \
sed -i "s/version=\"$(CURRENT_VERSION)\"/version=\"$$NEW_VERSION\"/" $(VERSION_FILE); \
echo "$(GREEN)Version bumped from $(CURRENT_VERSION) to $$NEW_VERSION$(NC)"
version-major:
@echo "$(BLUE)Bumping major version...$(NC)"
@NEW_VERSION=$$(echo $(CURRENT_VERSION) | awk -F. '{$$1 = $$1 + 1; $$2 = 0; $$3 = 0;} 1' | sed 's/ /./g'); \
sed -i "s/version=\"$(CURRENT_VERSION)\"/version=\"$$NEW_VERSION\"/" $(VERSION_FILE); \
echo "$(GREEN)Version bumped from $(CURRENT_VERSION) to $$NEW_VERSION$(NC)"
## Git/GitHub Management
tag:
@echo "$(BLUE)Creating git tag...$(NC)"
@NEW_VERSION=$$(grep -oP "version=\"\K[^\"]*" $(VERSION_FILE)); \
git add $(VERSION_FILE); \
git commit -m "Bump version to $$NEW_VERSION" || true; \
git tag -a "v$$NEW_VERSION" -m "Release version $$NEW_VERSION"; \
echo "$(GREEN)Tagged version $$NEW_VERSION$(NC)"
push-tag:
@echo "$(BLUE)Pushing to GitHub...$(NC)"
git push origin main
git push origin --tags
@echo "$(GREEN)Pushed to GitHub$(NC)"
## PyPI Release
release-pypi: build
@echo "$(BLUE)Uploading to PyPI...$(NC)"
$(PYTHON) -m twine upload dist/*
@echo "$(GREEN)Released to PyPI$(NC)"
## Release Checks
release-check:
@echo "$(BLUE)Running release checks...$(NC)"
@if [ -n "$$(git status --porcelain)" ]; then \
echo "$(RED)Error: Working directory is not clean. Commit or stash changes.$(NC)"; \
exit 1; \
fi
@if ! git diff-index --quiet HEAD --; then \
echo "$(RED)Error: There are uncommitted changes.$(NC)"; \
exit 1; \
fi
@echo "$(GREEN)Release checks passed$(NC)"
## Full Release Process
release: release-check test lint version-patch tag push-tag release-pypi clean
@echo "$(GREEN)Release complete!$(NC)"
release-minor: release-check test lint version-minor tag push-tag release-pypi clean
@echo "$(GREEN)Minor release complete!$(NC)"
release-major: release-check test lint version-major tag push-tag release-pypi clean
@echo "$(GREEN)Major release complete!$(NC)"
## Development Shortcuts
dev: venv install-dev
@echo "$(GREEN)Development environment ready$(NC)"
@echo "$(YELLOW)Activate with: source $(VENV)/bin/activate$(NC)"
check: test lint
@echo "$(GREEN)All checks passed$(NC)"
all: clean install test lint docs build
@echo "$(GREEN)Full build complete$(NC)"
# Quick setup for new developers
setup: venv install-dev
@echo "$(GREEN)Project setup complete!$(NC)"
@echo "$(YELLOW)Next steps:$(NC)"
@echo " 1. Activate virtual environment: source $(VENV)/bin/activate"
@echo " 2. Run tests: make test"
@echo " 3. Start developing!"