-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
233 lines (199 loc) · 7.99 KB
/
Makefile
File metadata and controls
233 lines (199 loc) · 7.99 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
.PHONY: help install install-dev setup clean clean-all test test-cov lint format type-check docs serve-docs pre-commit run-all
# Variables
PYTHON := python3
PIP := pip
PYTEST := pytest
BLACK := black
FLAKE8 := flake8
MYPY := mypy
PYDOCSTYLE := pydocstyle
PRE_COMMIT := pre-commit
SRC_DIR := src
TESTS_DIR := tests
NOTEBOOKS_DIR := notebooks
DOCS_DIR := docs
# Colors
BLUE := \033[0;34m
GREEN := \033[0;32m
RED := \033[0;31m
YELLOW := \033[0;33m
NC := \033[0m # No Color
help:
@echo "$(BLUE)Practical MLOps - Makefile Commands$(NC)"
@echo "$(BLUE)===================================$(NC)"
@echo ""
@echo "$(GREEN)Installation$(NC)"
@echo " make install Install production dependencies"
@echo " make install-dev Install development dependencies"
@echo " make setup Complete project setup (install + hooks)"
@echo ""
@echo "$(GREEN)Code Quality$(NC)"
@echo " make lint Run flake8 linting"
@echo " make format Format code with black"
@echo " make type-check Run mypy type checking"
@echo " make docs-check Check docstrings with pydocstyle"
@echo " make pre-commit Run pre-commit hooks on all files"
@echo " make check-all Run all quality checks"
@echo ""
@echo "$(GREEN)Testing$(NC)"
@echo " make test Run tests"
@echo " make test-cov Run tests with coverage report"
@echo " make test-html Generate HTML coverage report"
@echo ""
@echo "$(GREEN)Cleanup$(NC)"
@echo " make clean Clean cache and build files"
@echo " make clean-all Clean everything (cache, venv, models)"
@echo ""
@echo "$(GREEN)Workflows$(NC)"
@echo " make run-all Run all checks + tests"
@echo " make dev Setup + watch mode for development"
@echo ""
@echo "$(GREEN)Documentation$(NC)"
@echo " make docs Generate documentation"
@echo " make serve-docs Serve docs locally (requires sphinx)"
@echo ""
# ============================================================================
# Installation
# ============================================================================
install:
@echo "$(BLUE)Installing production dependencies...$(NC)"
@if [ -f "requirements.txt" ]; then \
$(PIP) install -r requirements.txt; \
echo "$(GREEN)✅ Dependencies installed$(NC)"; \
else \
echo "$(YELLOW)⚠️ requirements.txt not found$(NC)"; \
fi
install-dev: install
@echo "$(BLUE)Installing development dependencies...$(NC)"
@if [ -f "requirements-dev.txt" ]; then \
$(PIP) install -r requirements-dev.txt; \
echo "$(GREEN)✅ Dev dependencies installed$(NC)"; \
else \
echo "$(YELLOW)⚠️ requirements-dev.txt not found$(NC)"; \
fi
setup: install-dev
@echo "$(BLUE)Setting up pre-commit hooks...$(NC)"
@$(PRE_COMMIT) install
@echo "$(GREEN)✅ Pre-commit installed$(NC)"
@echo "$(BLUE)Running pre-commit on all files...$(NC)"
@$(PRE_COMMIT) run --all-files || true
@echo "$(GREEN)✅ Setup completed!$(NC)"
# ============================================================================
# Code Quality
# ============================================================================
format:
@echo "$(BLUE)Formatting code with black...$(NC)"
@$(BLACK) $(SRC_DIR) $(TESTS_DIR) || true
@echo "$(GREEN)✅ Code formatted$(NC)"
lint:
@echo "$(BLUE)Running flake8 linting...$(NC)"
@$(FLAKE8) $(SRC_DIR) $(TESTS_DIR) && \
echo "$(GREEN)✅ Flake8 passed$(NC)" || \
(echo "$(RED)❌ Flake8 failed$(NC)"; exit 1)
type-check:
@echo "$(BLUE)Running mypy type checking...$(NC)"
@$(MYPY) $(SRC_DIR) && \
echo "$(GREEN)✅ mypy passed$(NC)" || \
(echo "$(RED)❌ mypy failed$(NC)"; exit 1)
docs-check:
@echo "$(BLUE)Checking docstrings with pydocstyle...$(NC)"
@$(PYDOCSTYLE) $(SRC_DIR) && \
echo "$(GREEN)✅ pydocstyle passed$(NC)" || \
(echo "$(RED)❌ pydocstyle failed$(NC)"; exit 1)
pre-commit:
@echo "$(BLUE)Running pre-commit hooks...$(NC)"
@$(PRE_COMMIT) run --all-files && \
echo "$(GREEN)✅ Pre-commit passed$(NC)" || \
(echo "$(RED)❌ Pre-commit failed$(NC)"; exit 1)
check-all: format lint type-check docs-check
@echo "$(GREEN)✅ All checks passed!$(NC)"
# ============================================================================
# Testing
# ============================================================================
test:
@echo "$(BLUE)Running tests...$(NC)"
@$(PYTEST) $(TESTS_DIR) -v && \
echo "$(GREEN)✅ Tests passed$(NC)" || \
(echo "$(RED)❌ Tests failed$(NC)"; exit 1)
test-cov:
@echo "$(BLUE)Running tests with coverage...$(NC)"
@$(PYTEST) $(TESTS_DIR) --cov=$(SRC_DIR) --cov-report=term-missing && \
echo "$(GREEN)✅ Tests passed$(NC)" || \
(echo "$(RED)❌ Tests failed$(NC)"; exit 1)
test-html:
@echo "$(BLUE)Generating HTML coverage report...$(NC)"
@$(PYTEST) $(TESTS_DIR) --cov=$(SRC_DIR) --cov-report=html
@echo "$(GREEN)✅ Coverage report generated: htmlcov/index.html$(NC)"
# ============================================================================
# Cleanup
# ============================================================================
clean:
@echo "$(BLUE)Cleaning cache and build files...$(NC)"
@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 "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@find . -type f -name ".coverage" -delete 2>/dev/null || true
@rm -rf build/ dist/ .eggs/ htmlcov/ 2>/dev/null || true
@echo "$(GREEN)✅ Cleaned$(NC)"
clean-all: clean
@echo "$(BLUE)Cleaning everything...$(NC)"
@rm -rf venv/ 2>/dev/null || true
@rm -rf .venv/ 2>/dev/null || true
@rm -rf models/ 2>/dev/null || true
@rm -rf data/processed/ 2>/dev/null || true
@echo "$(GREEN)✅ Full cleanup completed$(NC)"
# ============================================================================
# Workflows
# ============================================================================
run-all: pre-commit lint type-check docs-check test-cov
@echo "$(GREEN)✅ All checks and tests passed!$(NC)"
dev: setup
@echo "$(BLUE)Development environment ready!$(NC)"
@echo "$(YELLOW)Start coding and commit with confidence!$(NC)"
# ============================================================================
# Git
# ============================================================================
commit-check: run-all
@echo "$(GREEN)✅ Ready to commit!$(NC)"
# ============================================================================
# Documentation
# ============================================================================
docs:
@echo "$(BLUE)Generating documentation...$(NC)"
@if [ -d "$(DOCS_DIR)" ]; then \
cd $(DOCS_DIR) && make html; \
echo "$(GREEN)✅ Documentation generated: $(DOCS_DIR)/_build/html/index.html$(NC)"; \
else \
echo "$(YELLOW)⚠️ $(DOCS_DIR) directory not found$(NC)"; \
fi
serve-docs:
@echo "$(BLUE)Serving documentation...$(NC)"
@if [ -f "$(DOCS_DIR)/_build/html/index.html" ]; then \
$(PYTHON) -m http.server 8000 --directory $(DOCS_DIR)/_build/html; \
else \
echo "$(YELLOW)⚠️ Documentation not found. Run 'make docs' first$(NC)"; \
fi
# ============================================================================
# Info
# ============================================================================
info:
@echo "$(BLUE)Project Information$(NC)"
@echo "$(BLUE)====================$(NC)"
@echo "Python version:"
@$(PYTHON) --version
@echo ""
@echo "Source code:"
@find $(SRC_DIR) -name "*.py" -type f | wc -l | xargs echo " Files:"
@echo ""
@echo "Tests:"
@find $(TESTS_DIR) -name "test_*.py" -type f | wc -l | xargs echo " Files:"
@echo ""
@echo "Lines of code:"
@find $(SRC_DIR) -name "*.py" -type f -exec wc -l {} + | tail -1 | awk '{print " " $$1}'
@echo ""
# ============================================================================
# Default
# ============================================================================
.DEFAULT_GOAL := help