-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
414 lines (356 loc) Β· 13.3 KB
/
Makefile
File metadata and controls
414 lines (356 loc) Β· 13.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# Cpex Plugin Framework Makefile
# =============================================================================
SHELL := /bin/bash
.SHELLFLAGS := -eu -o pipefail -c
# Project variables
PACKAGE_NAME = cpex
PROJECT_NAME = cpex
SRC_DIR = cpex
TEST_DIR = tests
TARGET ?= $(SRC_DIR)
# Virtual-environment variables
VENV_DIR ?= $(HOME)/.venv/$(PROJECT_NAME)
VENV_BIN = $(VENV_DIR)/bin
# Python
PYTHON = python3
PYTEST_ARGS ?=
# =============================================================================
# Help
# =============================================================================
.PHONY: help
help:
@echo "ContextForge Plugin Framework - Makefile"
@echo ""
@echo "Environment Setup:"
@echo " venv Create a new virtual environment"
@echo " install Install package from sources"
@echo " install-dev Install package in editable mode with dev deps"
@echo " install-docs Install package in editable mode with docs deps"
@echo " install-all Install package in editable mode all optional deps"
@echo ""
@echo "Development:"
@echo " lint Run all linters (black, ruff)"
@echo " lint-fix Auto-fix linting issues"
@echo " lint-check Check for linting issues without fixing"
@echo " format Format code with black and ruff"
@echo " type-check Run mypy type checking"
@echo ""
@echo "Testing:"
@echo " test Run all tests with pytest"
@echo " test-cov Run tests with coverage report"
@echo " test-verbose Run tests in verbose mode"
@echo " test-file FILE=path/to/test.py Run specific test file"
@echo ""
@echo "Documentation:"
@echo " docs Build docs"
@echo ""
@echo "Building & Distribution:"
@echo " dist Build wheel + sdist into ./dist"
@echo " wheel Build wheel only"
@echo " sdist Build source distribution only"
@echo " verify Build and verify package with twine"
@echo ""
@echo "Utilities:"
@echo " clean Remove all artifacts and builds"
@echo " clean-all Remove artifacts, builds, and venv"
@echo " run-main Run main.py with PYTHONPATH set"
@echo " uninstall Uninstall package"
@echo " grpc-proto Generate gRPC stubs for external plugin transport"
# =============================================================================
# Virtual Environment
# =============================================================================
.PHONY: venv
venv:
@echo "π§ Creating virtual environment..."
@rm -rf "$(VENV_DIR)"
@test -d "$(VENV_DIR)" || mkdir -p "$(VENV_DIR)"
@$(PYTHON) -m venv "$(VENV_DIR)"
@$(VENV_BIN)/python -m pip install --upgrade pip setuptools wheel
@echo "β
Virtual env created at: $(VENV_DIR)"
@echo "π‘ Activate it with:"
@echo " source $(VENV_DIR)/bin/activate"
.PHONY: install
install: venv
@echo "π¦ Installing package..."
@$(VENV_BIN)/pip install .
@echo "β
Package installed"
.PHONY: install-dev
install-dev: venv
@echo "π¦ Installing package with dev dependencies..."
@$(VENV_BIN)/pip install -e ".[dev,all]"
@echo "β
Package installed in editable mode with dev dependencies"
.PHONY: install-docs
install-docs: venv
@echo "π¦ Installing package with docs dependencies..."
@$(VENV_BIN)/pip install -e ".[docs]"
@echo "β
Package installed in editable mode with docs dependencies"
.PHONY: install-all
install-all: venv
@echo "π¦ Installing package with all optional dependencies..."
@$(VENV_BIN)/pip install -e ".[dev,docs,all]"
@echo "β
Package installed in editable mode with all optional dependencies"
.PHONY: uninstall
uninstall:
@echo "ποΈ Uninstalling package..."
@$(VENV_BIN)/pip uninstall -y $(PACKAGE_NAME) 2>/dev/null || true
@echo "β
Package uninstalled"
# =============================================================================
# Linting & Formatting
# =============================================================================
.PHONY: vulture
vulture:
@echo "β‘ Running vulture on $(TARGET)..."
@$(VENV_BIN)/vulture $(TARGET)
.PHONY: interrogate
interrogate:
@echo "β‘ Running interrogate on $(TARGET)..."
@$(VENV_BIN)/interrogate $(TARGET)
.PHONY: interrogate-verbose
interrogate-verbose:
@echo "β‘ Running interrogate on $(TARGET)..."
@$(VENV_BIN)/interrogate -vv $(TARGET)
.PHONY: radon
radon:
@echo "β‘ Running radon on $(TARGET)..."
@$(VENV_BIN)/radon cc $(TARGET) --min C --show-complexity
.PHONY: ruff
ruff:
@echo "β‘ Running ruff on $(TARGET)..."
@$(VENV_BIN)/ruff check $(TARGET) --fix
@$(VENV_BIN)/ruff format $(TARGET)
.PHONY: ruff-check
ruff-check:
@echo "β‘ Checking ruff on $(TARGET)..."
@$(VENV_BIN)/ruff check $(TARGET)
.PHONY: ruff-fix
ruff-fix:
@echo "β‘ Fixing ruff issues in $(TARGET)..."
@$(VENV_BIN)/ruff check --fix $(TARGET)
.PHONY: ruff-format
ruff-format:
@echo "β‘ Formatting with ruff on $(TARGET)..."
@$(VENV_BIN)/ruff format $(TARGET)
.PHONY: ruff-format-check
ruff-format-check:
@echo "β‘ Checking formatting with ruff on $(TARGET)..."
@$(VENV_BIN)/ruff format --check $(TARGET)
.PHONY: format
format: ruff-format
@echo "β
Code formatted"
.PHONY: lint
lint: lint-fix
.PHONY: lint-fix
lint-fix:
@# Handle file arguments
@target_file="$(word 2,$(MAKECMDGOALS))"; \
if [ -n "$$target_file" ] && [ "$$target_file" != "" ]; then \
actual_target="$$target_file"; \
else \
actual_target="$(TARGET)"; \
fi; \
for target in $$(echo $$actual_target); do \
if [ ! -e "$$target" ]; then \
echo "β File/directory not found: $$target"; \
exit 1; \
fi; \
done; \
echo "π§ Fixing lint issues in $$actual_target..."; \
$(MAKE) --no-print-directory ruff-fix TARGET="$$actual_target"; \
$(MAKE) --no-print-directory ruff-format TARGET="$$actual_target"; \
echo "β
Lint issues fixed"
.PHONY: lint-check
lint-check:
@# Handle file arguments
@target_file="$(word 2,$(MAKECMDGOALS))"; \
if [ -n "$$target_file" ] && [ "$$target_file" != "" ]; then \
actual_target="$$target_file"; \
else \
actual_target="$(TARGET)"; \
fi; \
echo "π Checking for lint issues..."; \
$(MAKE) --no-print-directory ruff-check TARGET="$$actual_target"; \
$(MAKE) --no-print-directory ruff-format-check TARGET="$$actual_target"; \
echo "β
Lint check complete"
.PHONY: type-check
type-check:
@echo "π Running mypy type checking..."
@$(VENV_BIN)/mypy $(SRC_DIR) --ignore-missing-imports
@echo "β
Type checking complete"
# =============================================================================
# Testing
# =============================================================================
.PHONY: test
test:
@echo "π§ͺ Running tests..."
@PYTHONPATH="$(SRC_DIR)" $(VENV_BIN)/pytest -n auto $(TEST_DIR) $(PYTEST_ARGS)
.PHONY: test-cov
test-cov:
@echo "π§ͺ Running tests with coverage..."
@PYTHONPATH="$(SRC_DIR)" $(VENV_BIN)/pytest -n auto $(TEST_DIR) \
--cov=$(SRC_DIR) \
--cov-report=html \
--cov-report=term-missing \
$(PYTEST_ARGS)
@echo "π Coverage report generated in htmlcov/"
.PHONY: test-verbose
test-verbose:
@$(MAKE) test PYTEST_ARGS="-vv"
.PHONY: test-file
test-file:
@if [ -z "$(FILE)" ]; then \
echo "β Please specify FILE=path/to/test.py"; \
exit 1; \
fi
@echo "π§ͺ Running test file: $(FILE)..."
@PYTHONPATH="$(SRC_DIR)" $(VENV_BIN)/pytest $(FILE) $(PYTEST_ARGS)
doctest:
@echo "π§ͺ Running doctest on all modules..."
@PYTHONPATH="$(SRC_DIR)" $(VENV_BIN)/pytest --doctest-modules cpex/ --tb=short --no-cov --disable-warnings
# =============================================================================
# Documentation
# =============================================================================
.PHONY: docs # Generate documentation site
docs:
uv run mkdocs build --strict
# =============================================================================
# Building & Distribution
# =============================================================================
.PHONY: check-manifest
check-manifest:
@echo "π¦ Verifying MANIFEST.in completeness..."
@$(VENV_BIN)/check-manifest
.PHONY: dist
dist: clean
@echo "π¦ Building distribution packages..."
@test -d "$(VENV_DIR)" || $(MAKE) --no-print-directory venv
@$(VENV_BIN)/python -m pip install --quiet --upgrade pip build
@$(VENV_BIN)/python -m build
@echo "β
Wheel & sdist written to ./dist"
.PHONY: wheel
wheel:
@echo "π¦ Building wheel..."
@test -d "$(VENV_DIR)" || $(MAKE) --no-print-directory venv
@$(VENV_BIN)/python -m pip install --quiet --upgrade pip build
@$(VENV_BIN)/python -m build -w
@echo "β
Wheel written to ./dist"
.PHONY: sdist
sdist:
@echo "π¦ Building source distribution..."
@test -d "$(VENV_DIR)" || $(MAKE) --no-print-directory venv
@$(VENV_BIN)/python -m pip install --quiet --upgrade pip build
@$(VENV_BIN)/python -m build -s
@echo "β
Source distribution written to ./dist"
.PHONY: verify
verify: dist check-manifest
@echo "π Verifying package..."
@$(VENV_BIN)/twine check dist/*
@echo "β
Package verified - ready to publish"
.PHONY: publish-test
publish-test: verify
@echo "π€ Publishing to TestPyPI..."
@$(VENV_BIN)/twine upload --repository testpypi dist/*
.PHONY: publish
publish: verify
@echo "π€ Publishing to PyPI..."
@$(VENV_BIN)/twine upload dist/*
# =============================================================================
# Utilities
# =============================================================================
.PHONY: run-main
run-main:
@echo "π Running main.py..."
@PYTHONPATH="$(SRC_DIR)" $(PYTHON) main.py
.PHONY: clean
clean:
@echo "π§Ή Cleaning build artifacts..."
@find . -type f -name '*.py[co]' -delete
@find . -type d -name __pycache__ -delete
@rm -rf *.egg-info .pytest_cache tests/.pytest_cache build dist .ruff_cache .coverage htmlcov .mypy_cache
@echo "β
Build artifacts cleaned"
.PHONY: clean-all
clean-all: clean
@echo "π§Ή Cleaning virtual environment..."
@rm -rf "$(VENV_DIR)"
@echo "β
Everything cleaned"
.PHONY: show-venv
show-venv:
@echo "Virtual environment: $(VENV_DIR)"
@if [ -d "$(VENV_DIR)" ]; then \
echo "Status: β
EXISTS"; \
echo "Python: $$($(VENV_BIN)/python --version 2>&1)"; \
echo "Pip: $$($(VENV_BIN)/pip --version 2>&1)"; \
else \
echo "Status: β NOT FOUND"; \
echo "Run 'make venv' to create it"; \
fi
.PHONY: show-deps
show-deps:
@echo "π Installed packages:"
@$(VENV_BIN)/pip list
.PHONY: grpc-proto
grpc-proto: ## Generate gRPC stubs for external plugin transport
@echo "π§ Generating gRPC protocol buffer stubs..."
@test -d "$(VENV_DIR)" || $(MAKE) venv
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
uv pip show grpcio-tools >/dev/null 2>&1 || \
uv pip install -q grpcio-tools"
@/bin/bash -c "source $(VENV_DIR)/bin/activate && \
python -m grpc_tools.protoc \
-I cpex/framework/external/grpc/proto \
--python_out=cpex/framework/external/grpc/proto \
--pyi_out=cpex/framework/external/grpc/proto \
--grpc_python_out=cpex/framework/external/grpc/proto \
cpex/framework/external/grpc/proto/plugin_service.proto"
@echo "π§ Fixing imports in generated files..."
@if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' 's/^import plugin_service_pb2/from cpex.framework.external.grpc.proto import plugin_service_pb2/' \
cpex/framework/external/grpc/proto/plugin_service_pb2_grpc.py; \
else \
sed -i 's/^import plugin_service_pb2/from cpex.framework.external.grpc.proto import plugin_service_pb2/' \
cpex/framework/external/grpc/proto/plugin_service_pb2_grpc.py; \
fi
@echo "π§ Adding noqa comments to generated files..."
@if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' '1s/^/# noqa: D100, D101, D102, D103, D104, D107, D400, D415\n# ruff: noqa\n# type: ignore\n# pylint: skip-file\n# Generated by protoc - do not edit\n/' \
cpex/framework/external/grpc/proto/plugin_service_pb2.py \
cpex/framework/external/grpc/proto/plugin_service_pb2_grpc.py \
cpex/framework/external/grpc/proto/plugin_service_pb2.pyi; \
else \
sed -i '1s/^/# noqa: D100, D101, D102, D103, D104, D107, D400, D415\n# ruff: noqa\n# type: ignore\n# pylint: skip-file\n# Generated by protoc - do not edit\n/' \
cpex/framework/external/grpc/proto/plugin_service_pb2.py \
cpex/framework/external/grpc/proto/plugin_service_pb2_grpc.py \
cpexs/framework/external/grpc/proto/plugin_service_pb2.pyi; \
fi
@echo "β
gRPC stubs generated in cpex/framework/external/grpc/proto/"
.PHONY: env-example
env-example:
@test -d "$(VENV_DIR)" || $(MAKE) --no-print-directory venv
@pip install settings-doc
@settings-doc generate --class cpex.framework.settings.PluginsSettings --output-format dotenv > .env.template
# =============================================================================
# Development shortcuts
# =============================================================================
.PHONY: dev-setup
dev-setup: install-dev
@echo "β
Development environment ready!"
@echo ""
@echo "Next steps:"
@echo " 1. Activate venv: source $(VENV_DIR)/bin/activate"
@echo " 2. Run tests: make test"
@echo " 3. Run main: make run-main"
.PHONY: quick-test
quick-test:
@echo "π Quick test (no coverage)..."
@PYTHONPATH="$(SRC_DIR)" $(VENV_BIN)/pytest $(TEST_DIR) -v --tb=short
.PHONY: watch-test
watch-test:
@echo "π Watching for changes..."
@while true; do \
$(MAKE) quick-test; \
echo ""; \
echo "Waiting for changes... (Ctrl+C to stop)"; \
sleep 2; \
done
# Prevent make from treating additional arguments as targets
%:
@: