-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
293 lines (243 loc) Β· 11.4 KB
/
Makefile
File metadata and controls
293 lines (243 loc) Β· 11.4 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
287
288
289
290
291
292
293
.PHONY: venv install dev-install test test-fast test-slow test-integration test-unit test-cov lint format typecheck check clean help analyze run analyze-all docker mermaid-png mermaid-png-% install-mermaid check-mermaid clean-png test-toon validate-toon test-all-formats toon-demo toon-compare toon-validate test-comprehensive build publish publish-test bump-patch bump-minor bump-major
VENV := .venv
PYTHON := $(VENV)/bin/python
PIP := $(VENV)/bin/pip
# Default target
help:
@echo "code2llm - Python Code Flow Analysis Tool with LLM Integration and TOON Format"
@echo ""
@echo "π Installation:"
@echo " make install - Install package"
@echo " make dev-install - Install with development dependencies"
@echo ""
@echo "π§ͺ Testing:"
@echo " make test - Run test suite"
@echo " make test-toon - Test TOON format only"
@echo " make validate-toon - Validate TOON format output"
@echo " make test-all-formats - Test all output formats"
@echo ""
@echo "π§ Code Quality:"
@echo " make lint - Run linters (flake8, black --check)"
@echo " make format - Format code with black"
@echo " make typecheck - Run mypy type checking"
@echo " make check - Run all quality checks"
@echo ""
@echo "π Analysis:"
@echo " make analyze - Run analysis on current project (TOON format)"
@echo " make run - Run with example arguments"
@echo " make analyze-all - Run analysis with all formats"
@echo ""
@echo "π― TOON Format:"
@echo " make toon-demo - Quick TOON format demo"
@echo " make toon-compare - Compare TOON vs YAML formats"
@echo " make toon-validate - Validate TOON format structure"
@echo ""
@echo "π¦ Building & Release:"
@echo " make build - Build distribution packages"
@echo " make publish - Publish to PyPI (with version bump)"
@echo " make publish-test - Publish to TestPyPI"
@echo " make bump-patch - Bump patch version"
@echo " make bump-minor - Bump minor version"
@echo " make bump-major - Bump major version"
@echo ""
@echo "π¨ Visualization:"
@echo " make mermaid-png - Generate PNG from all Mermaid files"
@echo " make install-mermaid - Install Mermaid CLI renderer"
@echo " make check-mermaid - Check available Mermaid renderers"
@echo ""
@echo "π§Ή Maintenance:"
@echo " make clean - Remove build artifacts"
@echo " make clean-png - Clean PNG files"
@echo ""
venv:
@if [ ! -x "$(PYTHON)" ]; then \
echo "Creating virtual environment in $(VENV)..."; \
python3 -m venv "$(VENV)"; \
fi
VENV_TARGETS := install dev-install test test-fast test-slow test-integration test-unit test-cov lint format typecheck check run analyze analyze-all toon-demo toon-compare toon-validate test-toon validate-toon test-all-formats build publish-test bump-patch bump-minor bump-major publish mermaid-png test-comprehensive
$(VENV_TARGETS): venv
mermaid-png-%: venv
# =============================================================================
# Installation
# =============================================================================
install:
$(PIP) install -e .
@echo "β code2llm installed with TOON format support"
dev-install:
$(PIP) install -e ".[dev]"
@echo "β code2llm installed with dev dependencies"
# =============================================================================
# Testing
# =============================================================================
test:
$(PYTHON) -m pytest tests/ -v --tb=short
# Fast tests - exclude slow and integration tests
test-fast:
$(PYTHON) -m pytest -m "not slow and not integration" -v --tb=short -n auto
# Slow tests only
test-slow:
$(PYTHON) -m pytest -m "slow" -v --tb=short
# Integration tests only
test-integration:
$(PYTHON) -m pytest -m "integration" -v --tb=short
# Unit tests only
test-unit:
$(PYTHON) -m pytest -m "unit" -v --tb=short
test-cov:
$(PYTHON) -m pytest tests/ --cov=code2llm --cov-report=html --cov-report=term 2>/dev/null || echo "No tests yet"
test-toon:
@echo "π― Testing TOON format..."
$(PYTHON) -m code2llm ./ -v -o ./test_toon -m hybrid -f toon
$(PYTHON) validate_toon.py test_toon/analysis.toon
@echo "β TOON format test complete"
validate-toon: test-toon
test-all-formats:
@echo "π Testing all output formats..."
$(PYTHON) -m code2llm ./ -v -o ./test_all -m hybrid -f all
$(PYTHON) validate_toon.py test_all/analysis.toon
@echo "β All formats test complete"
test-comprehensive:
@echo "π Running comprehensive test suite..."
bash project.sh
@echo "β Comprehensive tests complete"
# =============================================================================
# Code Quality
# =============================================================================
lint:
$(PYTHON) -m flake8 code2llm/ --max-line-length=100 --ignore=E203,W503 2>/dev/null || echo "flake8 not installed"
$(PYTHON) -m black --check code2llm/ 2>/dev/null || echo "black not installed"
@echo "β Linting complete"
format:
$(PYTHON) -m black code2llm/ --line-length=100 2>/dev/null || echo "black not installed, run: pip install black"
@echo "β Code formatted"
typecheck:
$(PYTHON) -m mypy code2llm/ --ignore-missing-imports 2>/dev/null || echo "mypy not installed"
check: lint typecheck test
@echo "β All checks passed"
# =============================================================================
# Analysis
# =============================================================================
run:
$(PYTHON) -m code2llm ../python/stts_core -v -o ./output
analyze:
@echo "π― Running TOON format analysis on current project..."
$(PYTHON) -m code2llm ./ -v -o ./analysis -m hybrid -f toon
$(PYTHON) validate_toon.py analysis/analysis.toon
@echo "β TOON analysis complete - check analysis/analysis.toon"
analyze-all:
@echo "π Running analysis with all formats..."
$(PYTHON) -m code2llm ./ -v -o ./analysis_all -m hybrid -f all
$(PYTHON) validate_toon.py analysis_all/analysis.toon
@echo "β All formats analysis complete - check analysis_all/"
# =============================================================================
# TOON Format Specific
# =============================================================================
toon-demo:
@echo "π― Quick TOON format demo..."
$(PYTHON) -m code2llm ./ -v -o ./demo -m hybrid -f toon
@echo "π Generated: demo/analysis.toon"
@echo "π Size: $$(du -h demo/analysis.toon | cut -f1)"
@echo "π Preview:"
@head -20 demo/analysis.toon
toon-compare:
@echo "π Comparing TOON vs YAML formats..."
$(PYTHON) -m code2llm ./ -v -o ./compare -m hybrid -f toon,yaml
@echo "π Files generated:"
@echo " - TOON: compare/analysis.toon ($$(du -h compare/analysis.toon | cut -f1))"
@echo " - YAML: compare/analysis.yaml ($$(du -h compare/analysis.yaml | cut -f1))"
@echo " - Ratio: $$(echo "scale=1; $$(du -k compare/analysis.yaml | cut -f1) / $$(du -k compare/analysis.toon | cut -f1)" | bc)x smaller"
$(PYTHON) validate_toon.py compare/analysis.yaml compare/analysis.toon
toon-validate:
@echo "π Validating TOON format structure..."
$(PYTHON) validate_toon.py analysis/analysis.toon 2>/dev/null || $(PYTHON) validate_toon.py test_toon/analysis.toon 2>/dev/null || echo "Run 'make test-toon' first"
# =============================================================================
# Building
# =============================================================================
build:
rm -rf build/ dist/ *.egg-info
$(PYTHON) -m build
@echo "β Build complete - check dist/"
# =============================================================================
# Release
# =============================================================================
publish-test: build
@echo "π Publishing to TestPyPI..."
@bash -c 'if [ -z "$${TWINE_USERNAME}" ] && [ -z "$${TWINE_PASSWORD}" ] && [ -z "$${PYPI_API_TOKEN}" ]; then \
echo "β οΈ No PyPI credentials found. Set TWINE_USERNAME and TWINE_PASSWORD or PYPI_API_TOKEN"; \
echo " Example: TWINE_USERNAME=__token__ TWINE_PASSWORD=pypi-xxx make publish-test"; \
echo " Skipping publish-test."; \
else \
$(PYTHON) -m venv publish-test-env && \
publish-test-env/bin/pip install twine && \
publish-test-env/bin/python -m twine upload --repository testpypi dist/* && \
rm -rf publish-test-env && \
echo "β Published to TestPyPI"; \
fi'
bump-patch:
@echo "π’ Bumping patch version..."
$(PYTHON) scripts/bump_version.py patch 2>/dev/null || echo "Create scripts/bump_version.py or edit pyproject.toml manually"
bump-minor:
@echo "π’ Bumping minor version..."
$(PYTHON) scripts/bump_version.py minor 2>/dev/null || echo "Create scripts/bump_version.py or edit pyproject.toml manually"
bump-major:
@echo "π’ Bumping major version..."
$(PYTHON) scripts/bump_version.py major 2>/dev/null || echo "Create scripts/bump_version.py or edit pyproject.toml manually"
publish: build
@echo "π Publishing to PyPI..."
@bash -c 'if [ -z "$${TWINE_USERNAME}" ] && [ -z "$${TWINE_PASSWORD}" ] && [ -z "$${PYPI_API_TOKEN}" ]; then \
echo "β οΈ No PyPI credentials found. Set TWINE_USERNAME and TWINE_PASSWORD or PYPI_API_TOKEN"; \
echo " Example: TWINE_USERNAME=__token__ TWINE_PASSWORD=pypi-xxx make publish"; \
echo " Skipping publish."; \
else \
echo "π’ Bumping patch version..."; \
$(MAKE) bump-patch; \
echo "π¨ Rebuilding package with new version..."; \
$(MAKE) build; \
echo "π¦ Publishing to PyPI..."; \
$(PYTHON) -m venv publish-env; \
publish-env/bin/pip install twine; \
publish-env/bin/python -m twine upload dist/*; \
rm -rf publish-env; \
echo "β Published to PyPI"; \
fi'
# =============================================================================
# Visualization
# =============================================================================
mermaid-png:
$(PYTHON) mermaid_to_png.py --batch output output
mermaid-png-%:
$(PYTHON) mermaid_to_png.py output/$*.mmd output/$*.png
install-mermaid:
npm install -g @mermaid-js/mermaid-cli
check-mermaid:
@echo "Checking available Mermaid renderers..."
@which mmdc > /dev/null && echo "β mmdc (mermaid-cli)" || echo "β mmdc (run: npm install -g @mermaid-js/mermaid-cli)"
@which npx > /dev/null && echo "β npx (for @mermaid-js/mermaid-cli)" || echo "β npx (install Node.js)"
@which puppeteer > /dev/null && echo "β puppeteer" || echo "β puppeteer (run: npm install -g puppeteer)"
# =============================================================================
# Maintenance
# =============================================================================
clean:
rm -rf build/ dist/ *.egg-info
rm -rf .pytest_cache .coverage htmlcov/
rm -rf code2llm/__pycache__ code2llm/*/__pycache__
rm -rf test_* demo compare analysis analysis_all output_* 2>/dev/null || true
find . -name "*.pyc" -delete 2>/dev/null || true
find . -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
@echo "β Cleaned build artifacts and test outputs"
clean-png:
rm -f output/*.png
@echo "β Cleaned PNG files"
# =============================================================================
# Quick Start
# =============================================================================
quickstart:
@echo "π Quick Start with code2llm TOON format:"
@echo ""
@echo "1. Install: make install"
@echo "2. Test TOON: make test-toon"
@echo "3. Analyze: make analyze"
@echo "4. Compare: make toon-compare"
@echo "5. All formats: make test-all-formats"
@echo ""
@echo "π For more: make help"