-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
210 lines (173 loc) · 7.55 KB
/
Copy pathMakefile
File metadata and controls
210 lines (173 loc) · 7.55 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
.PHONY: help install test test-cov test-fast test-unit test-integration test-performance test-contracts test-e2e clean lint lint-all lint-submodules lint-stat format type-check type-check-l1 security-scan docs analyze-coverage optimized-test quality-ratchet quality-ratchet-update format-ratchet format-ratchet-update public-api-quality tech-debt-report
# 质量门禁范围(迭代07)。与 scripts/ci/check_quality_ratchet.py 的 default_scope()
# 必须保持一致;tests/scripts/test_check_quality_ratchet.py 会断言两者相等。
SUB_SRC := $(wildcard bt_api/bt_api_*/src)
SUB_TESTS := $(wildcard bt_api/bt_api_*/tests)
CORE_SCOPE := bt_api_py tests
QUALITY_SCOPE := $(CORE_SCOPE) scripts examples $(SUB_SRC) $(SUB_TESTS)
# Default target
help:
@echo "bt_api_py - Makefile Commands"
@echo ""
@echo "Installation:"
@echo " make install Install package in development mode"
@echo " make install-dev Install with all dev dependencies"
@echo ""
@echo "Testing:"
@echo " make test Run all tests (excluding CTP)"
@echo " make test-cov Run tests with coverage report"
@echo " make test-fast Run only fast tests (exclude slow/network)"
@echo " make test-unit Run only unit tests"
@echo " make test-integration Run only integration tests"
@echo " make test-performance Run performance tests"
@echo " make test-contracts Run property-based tests"
@echo " make test-e2e Run end-to-end tests"
@echo " make test-ctp Run CTP tests"
@echo " make test-html Run tests and generate HTML report"
@echo " make optimized-test Run optimized test suite"
@echo " make analyze-coverage Analyze test coverage gaps"
@echo ""
@echo "Code Quality:"
@echo " make lint Run ruff linter (core scope: bt_api_py + tests)"
@echo " make lint-submodules Run ruff linter on bt_api/*/src + bt_api/*/tests"
@echo " make lint-all Run ruff linter on the full gated scope"
@echo " make lint-stat Ruff statistics for the full gated scope"
@echo " make quality-ratchet Verify lint debt did not increase (CI gate)"
@echo " make quality-ratchet-update Refresh the ratchet snapshot when debt decreased"
@echo " make format-ratchet Verify submodule format debt did not increase (CI gate)"
@echo " make format-ratchet-update Refresh the format ratchet when debt decreased"
@echo " make tech-debt-report Render read-only Ruff gradual-ignore debt report"
@echo " make public-api-quality Measure public callable docstrings and parameter annotations"
@echo " make format Format code with ruff"
@echo " make type-check Run mypy type checking"
@echo " make check Run all checks (lint + type-check)"
@echo " make security-scan Run bandit security scan"
@echo " make pre-commit Install pre-commit hooks"
@echo " make pre-commit-run Run pre-commit on all files"
@echo ""
@echo "Cleanup:"
@echo " make clean Remove build artifacts and cache"
@echo " make clean-test Remove test artifacts"
@echo " make clean-all Remove all generated files"
# Installation
install:
pip install -e .
install-dev:
pip install -e ".[dev]"
# Testing
test:
./scripts/run_tests.sh
test-cov:
./scripts/run_tests.sh --cov
test-fast:
./scripts/run_tests.sh -m "not slow and not network"
test-unit:
./scripts/run_tests.sh -m "unit"
test-integration:
./scripts/run_tests.sh -m "integration"
test-ctp:
./scripts/run_tests.sh --ctp -m "ctp"
test-html:
./scripts/run_tests.sh --html --cov
test-performance:
@set -eu; \
benchmark_dir=$$(mktemp -d "$${TMPDIR:-/tmp}/bt-api-py-benchmark.XXXXXX"); \
trap 'rm -rf "$$benchmark_dir"' EXIT; \
test -f tests/performance/test_event_normalization_performance.py; \
echo "Running performance tests..."; \
python -m pytest tests/performance/test_event_normalization_performance.py::test_normalize_event_orderbook_dict_hot_path --tb=short -v -n 8 --benchmark-json="$$benchmark_dir/benchmark.json"; \
python scripts/ci/check_performance_baseline.py --baseline docs/acceptance/2026-09-21-performance-baseline.json --report "$$benchmark_dir/benchmark.json"
test-contracts:
@echo "Running property-based tests..."
pytest tests/contracts/ --tb=short -v
test-e2e:
@echo "Running end-to-end tests..."
pytest tests/e2e/ --tb=short -v
optimized-test:
@echo "Running optimized test suite..."
chmod +x scripts/run_optimized_tests.sh
./scripts/run_optimized_tests.sh
analyze-coverage:
@echo "Analyzing test coverage..."
python scripts/analyze_coverage.py
# Code Quality
# `lint` 保持"主包范围",当前为绿,供日常快速自查;
# 子仓与 examples/scripts 的存量债由 `lint-all` / `make quality-ratchet` 呈现,
# 并由 CI 的棘轮保证"只降不升"(见 docs/迭代计划/迭代07-代码质量提升/)。
lint:
@echo "Running ruff linter (core scope)..."
ruff check $(CORE_SCOPE)
lint-submodules:
@echo "Running ruff linter (submodules)..."
ruff check $(SUB_SRC) $(SUB_TESTS)
lint-all:
@echo "Running ruff linter (full scope: core + submodules + scripts + examples)..."
ruff check $(QUALITY_SCOPE)
lint-stat:
@echo "Ruff statistics (full scope)..."
ruff check $(QUALITY_SCOPE) --statistics
quality-ratchet:
@echo "Checking the quality ratchet (lint debt may only decrease)..."
python scripts/ci/check_quality_ratchet.py
quality-ratchet-update:
@echo "Refreshing the quality ratchet snapshot (only when the debt decreased)..."
python scripts/ci/check_quality_ratchet.py --update
format-ratchet:
@echo "Checking the submodule format ratchet (per-module debt may only decrease)..."
python scripts/ci/check_format_ratchet.py
format-ratchet-update:
@echo "Refreshing the format ratchet snapshot (only when debt decreased)..."
python scripts/ci/check_format_ratchet.py --update
tech-debt-report:
@echo "Rendering read-only Ruff gradual-ignore debt report..."
python scripts/ci/render_tech_debt.py
public-api-quality:
@echo "Measuring public API docstring and parameter-annotation coverage..."
python scripts/measure_public_api_quality.py
format:
@echo "Formatting code with ruff..."
ruff format bt_api_py/ tests/
ruff check --fix bt_api_py/ tests/
type-check:
@echo "Running mypy type checking..."
mypy bt_api_py/
@echo "NOTE: submodule mypy scope is tracked as 迭代07 Task 13 (M4)."
# L1 子仓的 mypy 门禁(迭代07 M4-Task13)。
MYPY_L1_SUBMODULES := bt_api/bt_api_binance/src bt_api/bt_api_okx/src bt_api/bt_api_bybit/src bt_api/bt_api_gateio/src bt_api/bt_api_hyperliquid/src
type-check-l1:
@echo "Running mypy on L1 submodules (binance/okx/bybit/gateio/hyperliquid)..."
@for d in $(MYPY_L1_SUBMODULES); do \
printf " %-34s " "$$d"; \
PYTHONPATH="$$d:bt_api/bt_api_base/src" mypy "$$d" --ignore-missing-imports || exit 1; \
done
check: lint type-check
@echo "All checks passed!"
security-scan:
@echo "Running bandit security scan..."
bandit -r bt_api_py/ -c pyproject.toml
pre-commit:
@echo "Installing pre-commit hooks..."
pre-commit install
@echo "Pre-commit hooks installed! They will run automatically on git commit."
pre-commit-run:
@echo "Running pre-commit on all files..."
pre-commit run --all-files
# Cleanup
clean:
@echo "Cleaning build artifacts..."
rm -rf build/
rm -rf dist/
rm -rf *.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
find . -type f -name "*.so" -delete
clean-test:
@echo "Cleaning test artifacts..."
rm -rf .pytest_cache/
rm -rf htmlcov/
rm -rf .coverage
rm -rf logs/*.log
rm -rf logs/*.html
clean-all: clean clean-test
@echo "All cleaned!"