-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
320 lines (271 loc) · 10.3 KB
/
Makefile
File metadata and controls
320 lines (271 loc) · 10.3 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# PE Packer Project Makefile
# Common commands for development, testing, and building
# Configuration
PROJECT_NAME := pe-packer
RUST_PACKAGE_NAME := pe_packer
PYTHON_PACKAGE_NAME := pe_packer
CARGO := cargo
UV := uv
MATURIN := maturin
PYTEST := pytest
PYTHON := python
# Colors for output
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
BLUE := \033[0;34m
NC := \033[0m # No Color
# Default target
.DEFAULT_GOAL := help
.PHONY: help
help: ## Display this help message
@echo "PE Packer Project - Available commands:"
@echo ""
@echo "$(GREEN)Development:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " $(YELLOW)%-20s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Python:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^py-[a-zA-Z_-]+:.*?## / {printf " $(YELLOW)%-20s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Rust:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^rust-[a-zA-Z_-]+:.*?## / {printf " $(YELLOW)%-20s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Testing:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^test-[a-zA-Z_-]+:.*?## / {printf " $(YELLOW)%-20s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "$(GREEN)Build & Release:$(NC)"
@awk 'BEGIN {FS = ":.*?## "} /^(build|release|dist)-[a-zA-Z_-]+:.*?## / {printf " $(YELLOW)%-20s$(NC) %s\n", $$1, $$2}' $(MAKEFILE_LIST)
# Development
.PHONY: setup
setup: venv rust-deps ## Setup development environment
.PHONY: clean
clean: clean-rust clean-python ## Clean all build artifacts
.PHONY: venv
venv: ## Create Python virtual environment with uv
@echo "$(BLUE)Creating virtual environment...$(NC)"
$(UV) venv
@echo "$(GREEN)Virtual environment created$(NC)"
.PHONY: install
install: venv ## Install all dependencies
@echo "$(BLUE)Installing dependencies...$(NC)"
$(UV) sync --extra dev --extra training
@echo "$(GREEN)Dependencies installed$(NC)"
.PHONY: update
update: ## Update all dependencies
@echo "$(BLUE)Updating dependencies...$(NC)"
$(UV) pip compile --upgrade pyproject.toml
$(UV) sync --extra dev --extra training
@echo "$(GREEN)Dependencies updated$(NC)"
# Python Commands
.PHONY: py-dev
py-dev: ## Install Python package in development mode
@echo "$(BLUE)Installing Python package in development mode...$(NC)"
$(MATURIN) develop
@echo "$(GREEN)Python package installed$(NC)"
.PHONY: py-build
py-build: ## Build Python package
@echo "$(BLUE)Building Python package...$(NC)"
$(MATURIN) build
@echo "$(GREEN)Python package built$(NC)"
.PHONY: py-clean
py-clean: ## Clean Python build artifacts
@echo "$(BLUE)Cleaning Python build artifacts...$(NC)"
rm -rf build/ dist/ *.egg-info/ .mypy_cache/ .pytest_cache/ .coverage htmlcov/
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
@echo "$(GREEN)Python build artifacts cleaned$(NC)"
.PHONY: py-lint
py-lint: ## Run Python linters
@echo "$(BLUE)Running Python linters...$(NC)"
$(UV) run black --check python/ tests/ examples/
$(UV) run ruff check python/ tests/ examples/
$(UV) run mypy python/ tests/ examples/
@echo "$(GREEN)Python linting completed$(NC)"
.PHONY: py-format
py-format: ## Format Python code
@echo "$(BLUE)Formatting Python code...$(NC)"
$(UV) run black python/ tests/ examples/
$(UV) run ruff check --fix python/ tests/ examples/
@echo "$(GREEN)Python code formatted$(NC)"
.PHONY: py-shell
py-shell: ## Start Python shell with package loaded
@echo "$(BLUE)Starting Python shell...$(NC)"
$(UV) run ipython
# Rust Commands
.PHONY: rust-deps
rust-deps: ## Install Rust dependencies
@echo "$(BLUE)Installing Rust dependencies...$(NC)"
$(CARGO) fetch
@echo "$(GREEN)Rust dependencies installed$(NC)"
.PHONY: rust-build
rust-build: ## Build Rust project
@echo "$(BLUE)Building Rust project...$(NC)"
$(CARGO) build
@echo "$(GREEN)Rust project built$(NC)"
.PHONY: rust-build-release
rust-build-release: ## Build Rust project in release mode
@echo "$(BLUE)Building Rust project (release)...$(NC)"
$(CARGO) build --release
@echo "$(GREEN)Rust release build completed$(NC)"
.PHONY: rust-clean
rust-clean: ## Clean Rust build artifacts
@echo "$(BLUE)Cleaning Rust build artifacts...$(NC)"
$(CARGO) clean
@echo "$(GREEN)Rust build artifacts cleaned$(NC)"
.PHONY: rust-doc
rust-doc: ## Generate Rust documentation
@echo "$(BLUE)Generating Rust documentation...$(NC)"
$(CARGO) doc --no-deps --open
@echo "$(GREEN)Rust documentation generated$(NC)"
.PHONY: rust-clippy
rust-clippy: ## Run Rust clippy linter
@echo "$(BLUE)Running Rust clippy...$(NC)"
$(CARGO) clippy -- -D warnings
@echo "$(GREEN)Rust clippy completed$(NC)"
.PHONY: rust-fmt
rust-fmt: ## Format Rust code
@echo "$(BLUE)Formatting Rust code...$(NC)"
$(CARGO) fmt
@echo "$(GREEN)Rust code formatted$(NC)"
.PHONY: rust-fmt-check
rust-fmt-check: ## Check Rust code formatting
@echo "$(BLUE)Checking Rust code formatting...$(NC)"
$(CARGO) fmt -- --check
@echo "$(GREEN)Rust formatting check completed$(NC)"
# Testing
.PHONY: test
test: test-rust test-python ## Run all tests
.PHONY: test-rust
test-rust: ## Run Rust tests
@echo "$(BLUE)Running Rust tests...$(NC)"
$(CARGO) test
@echo "$(GREEN)Rust tests completed$(NC)"
.PHONY: test-python
test-python: ## Run Python tests
@echo "$(BLUE)Running Python tests...$(NC)"
$(UV) run pytest tests/ -v --cov=$(PYTHON_PACKAGE_NAME) --cov-report=html
@echo "$(GREEN)Python tests completed$(NC)"
.PHONY: test-python-fast
test-python-fast: ## Run Python tests without coverage
@echo "$(BLUE)Running Python tests (fast)...$(NC)"
$(UV) run pytest tests/ -v
@echo "$(GREEN)Python tests completed$(NC)"
.PHONY: test-examples
test-examples: ## Test example code
@echo "$(BLUE)Testing examples...$(NC)"
$(UV) run python examples/training_data_generation.py --dry-run
@echo "$(GREEN)Example tests completed$(NC)"
.PHONY: test-benchmarks
test-benchmarks: ## Run benchmarks
@echo "$(BLUE)Running benchmarks...$(NC)"
$(CARGO) bench
$(UV) run python benchmarks/python_performance.py
@echo "$(GREEN)Benchmarks completed$(NC)"
# Build & Distribution
.PHONY: build
build: rust-build-release py-build ## Build both Rust and Python packages
.PHONY: dist
dist: ## Build distribution packages
@echo "$(BLUE)Building distribution packages...$(NC)"
$(MATURIN) build --release
@echo "$(GREEN)Distribution packages built$(NC)"
.PHONY: dist-rust
dist-rust: ## Build Rust distribution
@echo "$(BLUE)Building Rust distribution...$(NC)"
$(CARGO) build --release
@echo "$(GREEN)Rust distribution built$(NC)"
.PHONY: dist-python
dist-python: ## Build Python wheels
@echo "$(BLUE)Building Python wheels...$(NC)"
$(MATURIN) build --release
@echo "$(GREEN)Python wheels built$(NC)"
.PHONY: release
release: test build ## Prepare release (run tests and build)
@echo "$(GREEN)Release preparation completed$(NC)"
.PHONY: release-dry-run
release-dry-run: ## Dry run release process
@echo "$(BLUE)Running release dry run...$(NC)"
$(MAKE) test
$(MAKE) rust-fmt-check
$(MAKE) rust-clippy
$(MAKE) py-lint
$(MAKE) build
@echo "$(GREEN)Release dry run completed$(NC)"
# Utility Commands
.PHONY: generate-training-data
generate-training-data: ## Generate training data samples
@echo "$(BLUE)Generating training data...$(NC)"
$(UV) run python examples/training_data_generation.py
@echo "$(GREEN)Training data generated$(NC)"
.PHONY: run-example
run-example: ## Run basic packing example
@echo "$(BLUE)Running packing example...$(NC)"
$(UV) run python examples/basic_packing.py
@echo "$(GREEN)Example completed$(NC)"
.PHONY: docker-build
docker-build: ## Build Docker image
@echo "$(BLUE)Building Docker image...$(NC)"
docker build -t $(PROJECT_NAME) .
@echo "$(GREEN)Docker image built$(NC)"
.PHONY: docker-run
docker-run: ## Run project in Docker
@echo "$(BLUE)Running in Docker...$(NC)"
docker run -it --rm $(PROJECT_NAME)
@echo "$(GREEN)Docker run completed$(NC)"
# Quality Assurance
.PHONY: qa
qa: rust-fmt-check rust-clippy py-lint test ## Run all quality checks
@echo "$(GREEN)All quality checks passed$(NC)"
.PHONY: pre-commit
pre-commit: rust-fmt py-format test ## Run pre-commit checks
@echo "$(GREEN)Pre-commit checks completed$(NC)"
# Monitoring
.PHONY: watch-rust
watch-rust: ## Watch Rust files and run tests on change
@echo "$(BLUE)Watching Rust files...$(NC)"
$(CARGO) watch -x test
.PHONY: watch-python
watch-python: ## Watch Python files and run tests on change
@echo "$(BLUE)Watching Python files...$(NC)"
$(UV) run ptw --now .
.PHONY: size
size: ## Check binary sizes
@echo "$(BLUE)Binary sizes:$(NC)"
@ls -lh target/release/$(RUST_PACKAGE_NAME)* 2>/dev/null || echo "No Rust binaries found"
@ls -lh dist/*.whl 2>/dev/null || echo "No Python wheels found"
# Install development tools
.PHONY: install-tools
install-tools: ## Install development tools
@echo "$(BLUE)Installing development tools...$(NC)"
cargo install cargo-watch
cargo install cargo-bloat
$(UV) pip install pre-commit
@echo "$(GREEN)Development tools installed$(NC)"
# PyPI Educational Stub (safe wheel)
.PHONY: stub-build
stub-build: ## Build educational stub wheel (PyPI-safe)
@echo "$(BLUE)Building educational stub wheel...$(NC)"
@test -d pypi-stub || { echo "missing pypi-stub/"; exit 1; }
@test -f pypi-stub/pyproject.toml || { echo "missing pypi-stub/pyproject.toml"; exit 1; }
$(UV) run $(PYTHON) -m pip install --upgrade build
cd pypi-stub && $(UV) run $(PYTHON) -m build
@echo "$(GREEN)Stub wheel built in pypi-stub/dist$(NC)"
.PHONY: stub-publish
stub-publish: ## Publish educational stub to PyPI (requires ALLOW_PYPI_RELEASE=1 and PYPI_TOKEN configured in environment)
@echo "$(BLUE)Publishing educational stub to PyPI...$(NC)"
test "$(ALLOW_PYPI_RELEASE)" = "1" || (echo "Set ALLOW_PYPI_RELEASE=1 to enable publishing" && false)
$(UV) run $(PYTHON) -m pip install --upgrade twine
cd pypi-stub && $(UV) run $(PYTHON) -m twine upload --non-interactive dist/*
@echo "$(GREEN)Stub published to PyPI$(NC)"
# MkDocs Documentation
.PHONY: docs-serve
docs-serve: ## Serve MkDocs locally at http://127.0.0.1:8000
@echo "$(BLUE)Starting MkDocs dev server...$(NC)"
$(UV) run $(PYTHON) -m pip install -q mkdocs-material
$(UV) run mkdocs serve --watch .
.PHONY: docs-build
docs-build: ## Build MkDocs site into ./site
@echo "$(BLUE)Building MkDocs site...$(NC)"
$(UV) run $(PYTHON) -m pip install -q mkdocs-material
$(UV) run mkdocs build --strict
@echo "$(GREEN)Docs built in ./site$(NC)"