-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
196 lines (159 loc) · 6.92 KB
/
Makefile
File metadata and controls
196 lines (159 loc) · 6.92 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
#
# Makefile for Portuguese Parliament API project
#
#
# Frederico Muñoz <fsmunoz@gmail.com>
#
.PHONY: help test test-unit test-integration test-property test-contract test-coverage test-quick test-all test-parallel test-endpoint test-clean install dev-install run etl-fetch etl-transform etl-all clean lint format
# Default target
.DEFAULT_GOAL := help
# Help
# (Needs to be kept updated)
# ==============================================================================
help:
@echo "=========================================================================="
@echo " Portuguese Parliament API - Make Targets"
@echo "=========================================================================="
@echo ""
@echo "Testing:"
@echo " make test - Run standard test suite (unit + integration + contract)"
@echo " make test-quick - Fast "smoke test" (unit + health check)"
@echo " make test-all - Full test suite (including property-based tests)"
@echo " make test-unit - Unit tests only"
@echo " make test-integration - Integration tests only"
@echo " make test-property - Property-based tests only (Hypothesis)"
@echo " make test-contract - OpenAPI contract tests only"
@echo " make test-coverage - Generate HTML coverage report"
@echo " make test-parallel - Run tests in parallel (faster)"
@echo " make test-endpoint - Test specific endpoint (e.g., ENDPOINT=votacoes)"
@echo " make test-clean - Clean test artifacts"
@echo ""
@echo "Development:"
@echo " make install - Install dependencies"
@echo " make dev-install - Install dev dependencies"
@echo " make run - Run API server locally"
@echo " make lint - Lint code with ruff"
@echo " make format - Format code with ruff"
@echo ""
@echo "ETL Pipeline:"
@echo " make etl-fetch - Fetch JSON from parlamento.pt"
@echo " make etl-transform - Transform JSON to Parquet"
@echo " make etl-all - Run full ETL pipeline"
@echo ""
@echo "Cleanup:"
@echo " make clean - Clean all artifacts"
@echo ""
@echo "=========================================================================="
# ==============================================================================
# Testing targets
# ==============================================================================
# We always source .venv/bin/activate
# We us https://docs.pytest.org/en/stable/ as the testing framework
# Quick smoke test (unit + basic integration)
test-quick:
@echo "==> Running quick tests..."
. .venv/bin/activate && pytest tests/test_api.py::test_health_check -v --tb=short
# Unit tests only (fast)
test-unit:
@echo "==> Running unit tests..."
. .venv/bin/activate && pytest tests/unit/ -v --tb=short -m unit
# Integration tests (endpoint tests)
test-integration:
@echo "==> Running integration tests..."
. .venv/bin/activate && pytest tests/integration/ tests/test_api.py -v --tb=short -m "not slow"
# Property-based tests (comprehensive, but slower)
test-property:
@echo "==> Running property-based tests..."
. .venv/bin/activate && pytest tests/property/ -v --tb=short -m property
# OpenAPI contract tests
test-contract:
@echo "==> Running contract tests..."
. .venv/bin/activate && pytest tests/contract/ -v --tb=short -m contract
# All tests (default, excludes property tests for speed)
test:
@echo "==> Running all tests (excluding property)..."
. .venv/bin/activate && pytest tests/test_api.py tests/test_regressions.py -v --tb=short
# Full test suite (includes property tests)
test-all:
@echo "==> Running FULL test suite..."
. .venv/bin/activate && pytest tests/ -v --tb=short
# Coverage report
test-coverage:
@echo "==> Running tests with coverage..."
. .venv/bin/activate && pytest tests/ --cov=app --cov-report=term-missing --cov-report=html
@echo ""
@echo "==> Coverage report: htmlcov/index.html"
@echo ""
# Parallel execution (fastest, perhaps it should be the default?)
test-parallel:
@echo "==> Running tests in parallel..."
. .venv/bin/activate && pytest tests/ -n auto -v --tb=short
# Specific endpoint (example: make test-endpoint ENDPOINT=votacoes)
test-endpoint:
ifndef ENDPOINT
@echo "ERROR: Please specify ENDPOINT variable"
@echo "Example: make test-endpoint ENDPOINT=votacoes"
@exit 1
endif
@echo "==> Running tests for $(ENDPOINT)..."
. .venv/bin/activate && pytest tests/integration/test_$(ENDPOINT).py tests/test_api.py -k $(ENDPOINT) -v --tb=short
# Clean test artifacts
test-clean:
@echo "==> Cleaning test artifacts..."
rm -rf .pytest_cache htmlcov .coverage .hypothesis
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@echo "==> Test artifacts cleaned"
# Development targets
# ==============================================================================
# We use pip; perhaps we should consider uv in the near future...
install:
@echo "==> Installing dependencies..."
. .venv/bin/activate && pip install -e .
dev-install:
@echo "==> Installing dev dependencies..."
. .venv/bin/activate && pip install -e ".[dev]"
run:
@echo "==> Starting API server..."
. .venv/bin/activate && uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
lint:
@echo "==> Linting code..."
. .venv/bin/activate && ruff check app/ etl/ tests/
format:
@echo "==> Formatting code..."
. .venv/bin/activate && ruff format app/ etl/ tests/
# ETL Pipeline targets
# ==============================================================================
etl-fetch:
@echo "==> Fetching data from parlamento.pt..."
. .venv/bin/activate && python -m etl
etl-transform:
@echo "==> Transforming JSON to Parquet..."
. .venv/bin/activate && python -m etl.transform
etl-all: etl-fetch etl-transform
@echo "==> ETL pipeline complete"
# ETL targets for latest legislature only (L17)
etl-fetch-latest:
@echo "==> Fetching latest legislature (L17) only..."
. .venv/bin/activate && python -m etl -l L17
etl-transform-latest:
@echo "==> Transforming latest legislature (L17) only..."
. .venv/bin/activate && python -m etl.transform -l L17
etl-latest: etl-fetch-latest etl-transform-latest
@echo "==> ETL pipeline complete (L17 only)"
# Parameterized ETL targets (usage: make etl-fetch-leg LEG=L17)
etl-fetch-leg:
@test -n "$(LEG)" || (echo "Error: LEG variable required. Usage: make etl-fetch-leg LEG=L17" && exit 1)
@echo "==> Fetching legislature $(LEG)..."
. .venv/bin/activate && python -m etl -l $(LEG)
etl-transform-leg:
@test -n "$(LEG)" || (echo "Error: LEG variable required. Usage: make etl-transform-leg LEG=L17" && exit 1)
@echo "==> Transforming legislature $(LEG)..."
. .venv/bin/activate && python -m etl.transform -l $(LEG)
# Cleanup targets
# ==============================================================================
clean: test-clean
@echo "==> Cleaning all artifacts..."
rm -rf build/ dist/ *.egg-info/
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
@echo "==> All artifacts cleaned"