-
-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathMakefile
More file actions
191 lines (169 loc) · 6.62 KB
/
Copy pathMakefile
File metadata and controls
191 lines (169 loc) · 6.62 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
.PHONY: help check clean build coverage lint format docs pre-commit setup test test-real test-fast tox install uninstall dev-install update-deps
# Colors for terminal output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m # No Color
# Project settings
PACKAGE := brazilcep
TESTS := tests
PYTHON := python3
PIP := pip
PYTEST := pytest
SPHINX := sphinx-autobuild
# Help target with colored output
help:
@echo "$(BLUE)BrazilCEP - Makefile Commands$(NC)"
@echo ""
@echo "$(GREEN)Setup & Installation:$(NC)"
@echo " $(YELLOW)setup$(NC) Set up the complete development environment"
@echo " $(YELLOW)install$(NC) Install package in production mode"
@echo " $(YELLOW)dev-install$(NC) Install package in development mode"
@echo " $(YELLOW)uninstall$(NC) Uninstall the package"
@echo " $(YELLOW)update-deps$(NC) Update all dependencies"
@echo ""
@echo "$(GREEN)Code Quality:$(NC)"
@echo " $(YELLOW)check$(NC) Run all checks (lint, test, docs, build)"
@echo " $(YELLOW)lint$(NC) Run all linting checks"
@echo " $(YELLOW)format$(NC) Auto-format code with black and isort"
@echo " $(YELLOW)pre-commit$(NC) Run pre-commit hooks on all files"
@echo ""
@echo "$(GREEN)Testing:$(NC)"
@echo " $(YELLOW)test$(NC) Run all tests (mocked APIs only)"
@echo " $(YELLOW)test-real$(NC) Run all tests including real API calls"
@echo " $(YELLOW)test-fast$(NC) Run tests without coverage (faster)"
@echo " $(YELLOW)coverage$(NC) Generate detailed coverage report"
@echo " $(YELLOW)tox$(NC) Run tests across multiple Python versions"
@echo ""
@echo "$(GREEN)Documentation:$(NC)"
@echo " $(YELLOW)docs$(NC) Build and serve documentation locally"
@echo " $(YELLOW)docs-build$(NC) Build documentation without serving"
@echo ""
@echo "$(GREEN)Build & Release:$(NC)"
@echo " $(YELLOW)build$(NC) Build package distribution"
@echo " $(YELLOW)clean$(NC) Clean up generated files and caches"
@echo " $(YELLOW)clean-all$(NC) Deep clean including virtual environments"
@echo ""
@echo "$(GREEN)Other:$(NC)"
@echo " $(YELLOW)help$(NC) Show this help message"
# Setup & Installation
setup:
@echo "$(BLUE)Setting up development environment...$(NC)"
$(PIP) install -e ".[dev,coverage,docs,build]"
pre-commit install --hook-type pre-commit
pre-commit install --hook-type pre-push
pre-commit autoupdate
mypy --install-types --non-interactive
@echo "$(GREEN)✓ Development environment ready!$(NC)"
install:
@echo "$(BLUE)Installing $(PACKAGE)...$(NC)"
$(PIP) install .
@echo "$(GREEN)✓ Installation complete!$(NC)"
dev-install:
@echo "$(BLUE)Installing $(PACKAGE) in development mode...$(NC)"
$(PIP) install -e ".[dev]"
@echo "$(GREEN)✓ Development installation complete!$(NC)"
uninstall:
@echo "$(RED)Uninstalling $(PACKAGE)...$(NC)"
$(PIP) uninstall -y $(PACKAGE)
@echo "$(GREEN)✓ Uninstallation complete!$(NC)"
update-deps:
@echo "$(BLUE)Updating dependencies...$(NC)"
$(PIP) install --upgrade pip setuptools wheel
$(PIP) install --upgrade -e ".[dev,coverage,docs,build]"
pre-commit autoupdate
@echo "$(GREEN)✓ Dependencies updated!$(NC)"
# Code Quality
check:
@echo "$(BLUE)Running all checks...$(NC)"
@$(MAKE) lint
@$(MAKE) test
@$(MAKE) docs-build
@$(MAKE) build
@echo "$(GREEN)✓ All checks passed!$(NC)"
lint:
@echo "$(BLUE)Running linting checks...$(NC)"
@echo " → isort..."
@isort --check $(PACKAGE) $(TESTS) || (echo "$(RED)✗ isort failed$(NC)" && exit 1)
@echo " → black..."
@black --check $(PACKAGE) $(TESTS) || (echo "$(RED)✗ black failed$(NC)" && exit 1)
@echo " → ruff..."
@ruff check $(PACKAGE) $(TESTS) || (echo "$(RED)✗ ruff failed$(NC)" && exit 1)
@echo " → mypy..."
@mypy $(PACKAGE) || (echo "$(RED)✗ mypy failed$(NC)" && exit 1)
@echo "$(GREEN)✓ All linting checks passed!$(NC)"
format:
@echo "$(BLUE)Formatting code...$(NC)"
isort $(PACKAGE) $(TESTS)
black $(PACKAGE) $(TESTS)
ruff check --fix $(PACKAGE) $(TESTS) || true
@echo "$(GREEN)✓ Code formatted!$(NC)"
pre-commit:
@echo "$(BLUE)Running pre-commit hooks...$(NC)"
pre-commit run --all-files
@echo "$(GREEN)✓ Pre-commit checks passed!$(NC)"
# Testing
test:
@echo "$(BLUE)Running tests (mocked APIs)...$(NC)"
SKIP_REAL_TEST=True $(PYTEST) -v --tb=short
@echo "$(GREEN)✓ Tests passed!$(NC)"
test-real:
@echo "$(YELLOW)Running all tests including real API calls...$(NC)"
@echo "$(YELLOW)Warning: This may take longer and depends on external APIs$(NC)"
SKIP_REAL_TEST=False $(PYTEST) -v --tb=short
@echo "$(GREEN)✓ All tests passed!$(NC)"
test-fast:
@echo "$(BLUE)Running fast tests (no coverage)...$(NC)"
SKIP_REAL_TEST=True $(PYTEST) -v -x --tb=short --no-cov
@echo "$(GREEN)✓ Fast tests passed!$(NC)"
coverage:
@echo "$(BLUE)Generating coverage report...$(NC)"
$(PYTEST) \
--cov=$(PACKAGE) \
--cov-config=pyproject.toml \
--cov-report=term-missing \
--cov-report=html \
--cov-report=xml \
--junitxml=junit.xml \
--no-cov-on-fail
@echo "$(GREEN)✓ Coverage report generated!$(NC)"
@echo "$(YELLOW)→ HTML report: htmlcov/index.html$(NC)"
tox:
@echo "$(BLUE)Running tox across multiple Python versions...$(NC)"
tox --parallel auto
@echo "$(GREEN)✓ Tox tests complete!$(NC)"
# Documentation
docs:
@echo "$(BLUE)Building and serving documentation...$(NC)"
@echo "$(YELLOW)→ Documentation will be available at http://127.0.0.1:8000$(NC)"
rm -rf docs/build/
$(SPHINX) -b html --watch $(PACKAGE)/ docs/source/ docs/build/
docs-build:
@echo "$(BLUE)Building documentation...$(NC)"
rm -rf docs/build/
sphinx-build -b html -W docs/source/ docs/build/
@echo "$(GREEN)✓ Documentation built!$(NC)"
@echo "$(YELLOW)→ Open docs/build/index.html$(NC)"
# Build & Release
build:
@echo "$(BLUE)Building package distribution...$(NC)"
rm -rf *.egg-info/ dist/
$(PYTHON) -m build
@echo "$(GREEN)✓ Package built successfully!$(NC)"
@echo "$(YELLOW)→ Distribution files in dist/$(NC)"
clean:
@echo "$(BLUE)Cleaning up generated files...$(NC)"
find . -type f -name "*.pyc" -delete
find . -type f -name "*.mo" -delete
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
rm -rf .mypy_cache/ .pytest_cache/ .ruff_cache/ .tox/ htmlcov/
rm -rf docs/build/ docs/source/_autosummary/
rm -f .coverage .coverage.* coverage.xml junit.xml
@echo "$(GREEN)✓ Cleanup complete!$(NC)"
clean-all: clean
@echo "$(RED)Deep cleaning (including build artifacts)...$(NC)"
rm -rf dist/ build/
rm -rf .venv/ venv/ env/
@echo "$(GREEN)✓ Deep cleanup complete!$(NC)"