-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
490 lines (412 loc) · 14.9 KB
/
Makefile
File metadata and controls
490 lines (412 loc) · 14.9 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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# ==============================================================================
# TelemetryFlow Python MCP Server Makefile - Python Implementation
# Version: 1.1.2
# ==============================================================================
# Build variables
PACKAGE_NAME := tfo-mcp
VERSION := 1.1.2
COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
PYTHON_VERSION := $(shell python --version 2>&1 | cut -d ' ' -f 2)
# Directories
BUILD_DIR := build
DIST_DIR := dist
SRC_DIR := src
TESTS_DIR := tests
# Python tooling
PYTHON := python
PIP := pip
PYTEST := pytest
RUFF := ruff
MYPY := mypy
BLACK := black
# Default target
.DEFAULT_GOAL := help
# ==============================================================================
# DEVELOPMENT
# ==============================================================================
.PHONY: build
build: ## Build wheel package
@echo "Building $(PACKAGE_NAME)..."
@mkdir -p $(BUILD_DIR)
$(PIP) install build
$(PYTHON) -m build
@echo "Build complete: $(DIST_DIR)/"
.PHONY: build-release
build-release: clean ## Build optimized release package
@echo "Building release $(PACKAGE_NAME)..."
$(PIP) install build
$(PYTHON) -m build
@echo "Release build complete: $(DIST_DIR)/"
.PHONY: run
run: ## Run the MCP server
@echo "Running $(PACKAGE_NAME)..."
tfo-mcp serve
.PHONY: run-debug
run-debug: ## Run the server in debug mode
@echo "Running $(PACKAGE_NAME) in debug mode..."
tfo-mcp serve --debug
.PHONY: install
install: ## Install the package
@echo "Installing $(PACKAGE_NAME)..."
$(PIP) install -e .
@echo "Installation complete"
.PHONY: clean
clean: ## Clean build artifacts
@echo "Cleaning..."
@rm -rf $(BUILD_DIR) $(DIST_DIR)
@rm -rf *.egg-info/ src/*.egg-info/
@rm -rf .pytest_cache/ .mypy_cache/ .ruff_cache/
@rm -rf htmlcov/ .coverage coverage.xml
@rm -rf coverage-*.out coverage-*.html coverage-summary.txt
@find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@echo "Clean complete"
# ==============================================================================
# DEPENDENCIES
# ==============================================================================
.PHONY: deps
deps: ## Download dependencies
@echo "Downloading dependencies..."
$(PIP) install -e .
@echo "Dependencies downloaded"
.PHONY: deps-dev
deps-dev: ## Install development dependencies
@echo "Installing development dependencies..."
$(PIP) install -e ".[dev]"
pre-commit install
@echo "Development dependencies installed"
.PHONY: deps-all
deps-all: ## Install all optional dependencies
@echo "Installing all dependencies..."
$(PIP) install -e ".[all]"
pre-commit install
@echo "All dependencies installed"
.PHONY: deps-update
deps-update: ## Update dependencies
@echo "Updating dependencies..."
$(PIP) install --upgrade pip
$(PIP) install --upgrade -e ".[all]"
@echo "Dependencies updated"
.PHONY: deps-refresh
deps-refresh: ## Refresh all dependencies (clean and re-download)
@echo "Refreshing dependencies..."
$(PIP) cache purge
$(PIP) install --upgrade pip
$(PIP) install --force-reinstall -e ".[all]"
@echo "Dependencies refreshed"
.PHONY: deps-check
deps-check: ## Check for dependency vulnerabilities
@echo "Checking dependencies for vulnerabilities..."
@if command -v pip-audit >/dev/null 2>&1; then \
pip-audit; \
else \
echo "pip-audit not installed. Run: pip install pip-audit"; \
fi
.PHONY: deps-lock
deps-lock: ## Generate requirements lock file
@echo "Generating requirements lock..."
$(PIP) freeze > requirements.lock
@echo "Lock file generated: requirements.lock"
.PHONY: deps-tree
deps-tree: ## Show dependency tree
@echo "Dependency tree..."
@if command -v pipdeptree >/dev/null 2>&1; then \
pipdeptree; \
else \
echo "pipdeptree not installed. Run: pip install pipdeptree"; \
fi
# ==============================================================================
# CODE QUALITY
# ==============================================================================
.PHONY: fmt
fmt: ## Format code
@echo "Formatting code..."
$(BLACK) $(SRC_DIR) $(TESTS_DIR)
$(RUFF) check --fix $(SRC_DIR) $(TESTS_DIR)
@echo "Code formatted"
.PHONY: fmt-check
fmt-check: ## Check code formatting
@echo "Checking code format..."
$(BLACK) --check $(SRC_DIR) $(TESTS_DIR)
@echo "Code format check passed"
.PHONY: lint
lint: ## Run linters
@echo "Running linter..."
$(RUFF) check $(SRC_DIR) $(TESTS_DIR)
@echo "Lint complete"
.PHONY: lint-fix
lint-fix: ## Run linters with auto-fix
@echo "Running linter with auto-fix..."
$(RUFF) check --fix $(SRC_DIR) $(TESTS_DIR)
@echo "Lint fix complete"
.PHONY: typecheck
typecheck: ## Run type checking
@echo "Running type check..."
$(MYPY) $(SRC_DIR)
@echo "Type check complete"
.PHONY: check
check: fmt-check lint typecheck ## Run all code quality checks
@echo "All checks passed"
# ==============================================================================
# TESTING
# ==============================================================================
.PHONY: test
test: ## Run tests
@echo "Running tests..."
$(PYTEST) $(TESTS_DIR) -v
@echo "Tests complete"
.PHONY: test-cov
test-cov: ## Run tests with coverage
@echo "Running tests with coverage..."
@mkdir -p $(BUILD_DIR)
$(PYTEST) $(TESTS_DIR) -v --cov=$(SRC_DIR)/tfo_mcp --cov-report=html:$(BUILD_DIR)/htmlcov --cov-report=xml:$(BUILD_DIR)/coverage.xml --cov-report=term
@echo "Coverage report: $(BUILD_DIR)/htmlcov/index.html"
.PHONY: test-unit
test-unit: ## Run unit tests only
@echo "Running unit tests..."
$(PYTEST) $(TESTS_DIR)/unit -v
@echo "Unit tests complete"
.PHONY: test-integration
test-integration: ## Run integration tests only
@echo "Running integration tests..."
$(PYTEST) $(TESTS_DIR)/integration -v
@echo "Integration tests complete"
.PHONY: test-e2e
test-e2e: ## Run E2E tests only
@echo "Running E2E tests..."
$(PYTEST) $(TESTS_DIR)/e2e -v
@echo "E2E tests complete"
.PHONY: test-all
test-all: ## Run all tests (unit, integration, e2e)
@echo "Running all tests..."
$(PYTEST) $(TESTS_DIR) -v --tb=short
@echo "All tests complete"
.PHONY: test-fast
test-fast: ## Run tests without slow markers
@echo "Running fast tests..."
$(PYTEST) $(TESTS_DIR) -v -m "not slow"
@echo "Fast tests complete"
# ==============================================================================
# CI-SPECIFIC TARGETS (GitHub Actions)
# ==============================================================================
# These targets are optimized for CI environments with coverage output
# and proper exit codes for CI systems.
.PHONY: ci-deps
ci-deps: ## Install dependencies for CI (no pre-commit hooks)
@echo "Installing CI dependencies..."
$(PIP) install --upgrade pip
$(PIP) install -e ".[dev]"
@echo "CI dependencies installed"
.PHONY: ci-lint
ci-lint: fmt-check lint typecheck ## Run full lint suite for CI
@echo "CI lint suite complete"
.PHONY: ci-test-unit
ci-test-unit: ## Run unit tests for CI with coverage output
@echo "Running unit tests (CI mode)..."
$(PYTEST) $(TESTS_DIR)/unit -v --tb=short --cov=$(SRC_DIR)/tfo_mcp --cov-report=xml:coverage-unit.xml --cov-report=term-missing --junitxml=junit-unit.xml
@echo "Unit tests complete"
.PHONY: ci-test-integration
ci-test-integration: ## Run integration tests for CI with coverage output
@echo "Running integration tests (CI mode)..."
$(PYTEST) $(TESTS_DIR)/integration -v --tb=short --cov=$(SRC_DIR)/tfo_mcp --cov-append --cov-report=xml:coverage-integration.xml --cov-report=term-missing --junitxml=junit-integration.xml || true
@echo "Integration tests complete"
.PHONY: ci-test-e2e
ci-test-e2e: ## Run E2E tests for CI
@echo "Running E2E tests (CI mode)..."
$(PYTEST) $(TESTS_DIR)/e2e -v --tb=short --junitxml=junit-e2e.xml || true
@echo "E2E tests complete"
.PHONY: ci-test
ci-test: ci-test-unit ci-test-integration ## Run all tests for CI
@echo "CI test suite complete"
.PHONY: ci-build
ci-build: clean ## Build package for CI
@echo "Building packages (CI mode)..."
$(PIP) install build
$(PYTHON) -m build
@echo "CI build complete"
@ls -la $(DIST_DIR)/
.PHONY: ci-security
ci-security: ## Run security scan for CI
@echo "Running security scan (CI mode)..."
@$(PIP) install bandit bandit-sarif-formatter safety 2>/dev/null || true
@bandit -r $(SRC_DIR)/ --format sarif --output bandit-results.sarif -ll || true
@safety check --json > safety-results.json 2>/dev/null || true
@echo "Security scan complete"
.PHONY: ci-coverage
ci-coverage: ## Generate coverage reports for CI
@echo "Generating coverage reports (CI mode)..."
$(PYTEST) $(TESTS_DIR)/ --cov=$(SRC_DIR)/tfo_mcp --cov-report=xml:coverage.xml --cov-report=html:$(BUILD_DIR)/htmlcov --cov-report=term-missing -q
@echo "Coverage reports generated"
.PHONY: ci-validate
ci-validate: ## Validate CI configuration
@echo "Validating CI configuration..."
$(PIP) check
@echo "CI configuration valid"
.PHONY: deps-verify
deps-verify: ## Verify dependencies
@echo "Verifying dependencies..."
$(PIP) check
@echo "Dependencies verified"
.PHONY: coverage-report
coverage-report: ## Generate merged coverage report
@echo "Generating coverage report..."
@if command -v coverage >/dev/null 2>&1; then \
coverage combine coverage-unit.xml coverage-integration.xml 2>/dev/null || true; \
coverage report; \
coverage html -d coverage-html; \
echo "Coverage report generated: coverage-html/index.html"; \
else \
echo "coverage not installed"; \
fi
# ==============================================================================
# DOCKER
# ==============================================================================
DOCKER_IMAGE := telemetryflow-python-mcp-python
DOCKER_TAG := $(VERSION)
.PHONY: docker-build
docker-build: ## Build Docker image
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(DOCKER_TAG) -t $(DOCKER_IMAGE):latest .
@echo "Docker image built"
.PHONY: docker-run
docker-run: ## Run Docker container
@echo "Running Docker container..."
docker run --rm -it \
-e ANTHROPIC_API_KEY \
$(DOCKER_IMAGE):latest
.PHONY: docker-push
docker-push: ## Push Docker image
@echo "Pushing Docker image..."
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
docker push $(DOCKER_IMAGE):latest
.PHONY: docker
docker: docker-build docker-run ## Build and run Docker container
.PHONY: docker-compose-up
docker-compose-up: ## Start docker-compose services
docker compose up -d
.PHONY: docker-compose-down
docker-compose-down: ## Stop docker-compose services
docker compose down
.PHONY: docker-compose-full
docker-compose-full: ## Start all docker-compose services (including optional)
docker compose --profile full up -d
.PHONY: docker-compose-logs
docker-compose-logs: ## Show docker-compose logs
docker compose logs -f
# ==============================================================================
# CI/CD
# ==============================================================================
.PHONY: ci
ci: deps-dev fmt-check lint typecheck test ## Run CI pipeline
@echo "CI pipeline complete"
# ==============================================================================
# RELEASE
# ==============================================================================
.PHONY: release
release: clean build-release ## Create release artifacts
@echo "Creating release $(VERSION)..."
@mkdir -p $(DIST_DIR)/release
@cp $(DIST_DIR)/*.whl $(DIST_DIR)/release/ 2>/dev/null || true
@cp $(DIST_DIR)/*.tar.gz $(DIST_DIR)/release/ 2>/dev/null || true
@echo "Release artifacts created in $(DIST_DIR)/release"
@ls -la $(DIST_DIR)/release/
.PHONY: publish
publish: ## Publish to PyPI
@echo "Publishing to PyPI..."
@if command -v twine >/dev/null 2>&1; then \
twine upload $(DIST_DIR)/*; \
else \
echo "twine not installed. Run: pip install twine"; \
fi
.PHONY: publish-test
publish-test: ## Publish to Test PyPI
@echo "Publishing to Test PyPI..."
@if command -v twine >/dev/null 2>&1; then \
twine upload --repository testpypi $(DIST_DIR)/*; \
else \
echo "twine not installed. Run: pip install twine"; \
fi
# ==============================================================================
# UTILITIES
# ==============================================================================
.PHONY: version
version: ## Show version information
@echo "TelemetryFlow Python MCP Server (Python)"
@echo "Version: $(VERSION)"
@echo "Commit: $(COMMIT)"
@echo "Build Date: $(BUILD_DATE)"
@echo "Python Version: $(PYTHON_VERSION)"
.PHONY: validate-config
validate-config: ## Validate configuration file
@echo "Validating configuration..."
tfo-mcp validate
@echo "Configuration valid"
.PHONY: init-config
init-config: ## Generate default configuration file
@echo "Generating configuration..."
tfo-mcp init-config
@echo "Configuration generated"
.PHONY: info
info: ## Show server information
tfo-mcp info
.PHONY: docs
docs: ## Generate documentation
@echo "Generating documentation..."
@if command -v pdoc >/dev/null 2>&1; then \
pdoc --html --output-dir docs/api $(SRC_DIR)/tfo_mcp; \
echo "Documentation generated in docs/api/"; \
else \
echo "pdoc not installed. Run: pip install pdoc"; \
fi
.PHONY: docs-serve
docs-serve: ## Serve documentation locally
@echo "Starting documentation server..."
@if command -v pdoc >/dev/null 2>&1; then \
pdoc --http localhost:8080 $(SRC_DIR)/tfo_mcp; \
else \
echo "pdoc not installed. Run: pip install pdoc"; \
fi
.PHONY: pre-commit
pre-commit: ## Run pre-commit hooks on all files
@echo "Running pre-commit..."
pre-commit run --all-files
.PHONY: pre-commit-update
pre-commit-update: ## Update pre-commit hooks
@echo "Updating pre-commit hooks..."
pre-commit autoupdate
# ==============================================================================
# SECURITY
# ==============================================================================
.PHONY: security-check
security-check: ## Run security checks
@echo "Running security checks..."
@if command -v bandit >/dev/null 2>&1; then \
bandit -r $(SRC_DIR) -ll; \
else \
echo "bandit not installed. Run: pip install bandit"; \
fi
@if command -v safety >/dev/null 2>&1; then \
safety check; \
else \
echo "safety not installed. Run: pip install safety"; \
fi
.PHONY: audit
audit: deps-check security-check ## Run full security audit
@echo "Security audit complete"
# ==============================================================================
# HELP
# ==============================================================================
.PHONY: help
help: ## Show this help message
@echo "TelemetryFlow Python MCP Server - Python Makefile"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Environment Variables:"
@echo " ANTHROPIC_API_KEY - Claude API key (required for running)"
@echo " TELEMETRYFLOW_MCP_DEBUG - Enable debug mode"
@echo " TELEMETRYFLOW_MCP_LOG_LEVEL - Log level (debug, info, warning, error)"