-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
495 lines (430 loc) Β· 17.6 KB
/
Makefile
File metadata and controls
495 lines (430 loc) Β· 17.6 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
491
492
493
494
495
# Makefile for GenAI Python Development
# Provides simple commands for common development tasks
.PHONY: help setup install test lint check security docs clean full update
.DEFAULT_GOAL := help
# Python command detection
PYTHON_CMD := $(shell command -v uv >/dev/null 2>&1 && echo "uv run" || echo "python -m")
PYTHON_EXEC := $(shell command -v uv >/dev/null 2>&1 && echo "uv run python" || echo "python")
# Colors for output
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
BLUE := \033[0;34m
BOLD := \033[1m
NC := \033[0m # No Color
help: ## Show this help message
@echo "$(BOLD)GenAI Python Development Commands$(NC)"
@echo "=================================="
@echo ""
@echo "$(BOLD)Setup Commands:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -E "(setup|install)" | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(BLUE)%-15s$(NC) %s\n", $$1, $$2}'
@echo ""
@echo "$(BOLD)Development Commands:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -E "(test|lint|check|format)" | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-15s$(NC) %s\n", $$1, $$2}'
@echo ""
@echo "$(BOLD)Maintenance Commands:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -E "(clean|update|security|docs)" | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(YELLOW)%-15s$(NC) %s\n", $$1, $$2}'
@echo ""
@echo "$(BOLD)Composite Commands:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -E "(full|quick)" | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(RED)%-15s$(NC) %s\n", $$1, $$2}'
@echo ""
@echo "$(BOLD)Examples:$(NC)"
@echo " make setup # Initial project setup"
@echo " make quick # Quick development check"
@echo " make test # Run tests with coverage"
@echo " make full # Complete quality check"
setup: ## Initial project setup with dependencies and hooks
@echo "$(BLUE)π Setting up development environment...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py setup
install: ## Install/sync all dependencies
@echo "$(GREEN)π¦ Installing dependencies...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py install
update: ## Update dependencies and tools
@echo "$(YELLOW)π Updating dependencies and tools...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py update
test: ## Run tests with coverage report
@echo "$(GREEN)π§ͺ Running tests with coverage...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py test
test-fast: ## Run fast tests only (no slow/LLM tests)
@echo "$(GREEN)β‘ Running fast tests only...$(NC)"
@$(PYTHON_CMD) pytest -m "not slow and not llm" --maxfail=3
test-unit: ## Run unit tests only
@echo "$(GREEN)π¬ Running unit tests...$(NC)"
@$(PYTHON_CMD) pytest tests/unit/ -v
test-integration: ## Run integration tests only
@echo "$(GREEN)π Running integration tests...$(NC)"
@$(PYTHON_CMD) pytest tests/integration/ -v
test-llm: ## Run LLM tests (requires API keys)
@echo "$(GREEN)π€ Running LLM tests...$(NC)"
@$(PYTHON_CMD) pytest -m llm --expensive
lint: ## Run linting and formatting
@echo "$(GREEN)β¨ Running linting and formatting...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py lint
format: ## Run code formatting only
@echo "$(GREEN)π¨ Formatting code...$(NC)"
@$(PYTHON_CMD) ruff format .
@$(PYTHON_CMD) isort .
check: ## Run all code quality checks
@echo "$(GREEN)π Running all quality checks...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py check
security: ## Run security scans
@echo "$(YELLOW)π Running security scans...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py security
docs: ## Check documentation coverage
@echo "$(YELLOW)π Checking documentation coverage...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py docs
dead-code: ## Check for dead code
@echo "$(YELLOW)π§Ή Scanning for dead code...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py dead-code
clean: ## Clean temporary files and caches
@echo "$(YELLOW)π§½ Cleaning temporary files...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py clean
full: ## Run complete pre-commit simulation
@echo "$(RED)π₯ Running complete quality check...$(NC)"
@$(PYTHON_EXEC) scripts/dev.py full
quick: ## Quick development check (lint + fast tests)
@echo "$(RED)β‘ Running quick development check...$(NC)"
@$(MAKE) lint
@$(MAKE) test-fast
# Git and pre-commit commands
pre-commit: ## Run pre-commit on all files
@echo "$(BLUE)π Running pre-commit on all files...$(NC)"
@$(PYTHON_CMD) pre-commit run --all-files
pre-commit-update: ## Update pre-commit hooks
@echo "$(BLUE)π Updating pre-commit hooks...$(NC)"
@$(PYTHON_CMD) pre-commit autoupdate
# CI simulation commands
ci-lint: ## Simulate CI linting checks
@echo "$(BLUE)π€ Simulating CI linting checks...$(NC)"
@$(PYTHON_CMD) ruff check . --output-format=github
@$(PYTHON_CMD) ruff format . --check
ci-test: ## Simulate CI test run
@echo "$(BLUE)π€ Simulating CI test run...$(NC)"
@$(PYTHON_CMD) pytest --cov --cov-report=xml --cov-report=term-missing --junitxml=pytest.xml
ci-security: ## Simulate CI security checks
@echo "$(BLUE)π€ Simulating CI security checks...$(NC)"
@$(PYTHON_CMD) bandit -r . -f json -o bandit-report.json -c pyproject.toml
@$(PYTHON_CMD) safety check --json --output safety-report.json
# Development server commands (if applicable)
dev-server: ## Start development server (if applicable)
@echo "$(GREEN)π Starting development server...$(NC)"
@$(PYTHON_CMD) uvicorn main:app --reload --host 0.0.0.0 --port 8000
# Docker commands (if using Docker)
docker-build: ## Build Docker image
@echo "$(BLUE)π³ Building Docker image...$(NC)"
@docker build -t genai-python:latest .
docker-run: ## Run Docker container
@echo "$(BLUE)π³ Running Docker container...$(NC)"
@docker run --rm -it -p 8000:8000 genai-python:latest
# Database commands (if applicable)
db-migrate: ## Run database migrations
@echo "$(GREEN)ποΈ Running database migrations...$(NC)"
@$(PYTHON_CMD) alembic upgrade head
db-reset: ## Reset database
@echo "$(YELLOW)ποΈ Resetting database...$(NC)"
@$(PYTHON_CMD) alembic downgrade base
@$(PYTHON_CMD) alembic upgrade head
# Jupyter notebook commands
nb-clean: ## Clean Jupyter notebook outputs
@echo "$(GREEN)π Cleaning notebook outputs...$(NC)"
@$(PYTHON_CMD) nbstripout notebooks/*.ipynb
nb-convert: ## Convert notebooks to Python scripts
@echo "$(GREEN)π Converting notebooks to Python...$(NC)"
@$(PYTHON_CMD) nbconvert --to script notebooks/*.ipynb --output-dir scripts/
# Dependency management
deps-list: ## List all dependencies
@echo "$(BLUE)π Listing dependencies...$(NC)"
@if command -v uv >/dev/null 2>&1; then \
uv pip list; \
else \
pip list; \
fi
deps-outdated: ## Check for outdated dependencies
@echo "$(YELLOW)π Checking for outdated dependencies...$(NC)"
@if command -v uv >/dev/null 2>&1; then \
echo "Use 'uv sync --upgrade' to update dependencies"; \
else \
pip list --outdated; \
fi
deps-tree: ## Show dependency tree
@echo "$(BLUE)π³ Showing dependency tree...$(NC)"
@$(PYTHON_CMD) pipdeptree
# Performance and profiling
profile: ## Profile the application (example)
@echo "$(YELLOW)β‘ Running performance profiling...$(NC)"
@$(PYTHON_CMD) cProfile -o profile.stats main.py
@$(PYTHON_CMD) -c "import pstats; pstats.Stats('profile.stats').sort_stats('cumulative').print_stats(20)"
benchmark: ## Run benchmarks
@echo "$(YELLOW)β‘ Running benchmarks...$(NC)"
@$(PYTHON_CMD) pytest -m perf --benchmark-only
# Environment and system info
env-info: ## Show environment information
@echo "$(BLUE)βΉοΈ Environment Information$(NC)"
@echo "=============================="
@echo "Python version: $$(python --version)"
@echo "Python path: $$(which python)"
@if command -v uv >/dev/null 2>&1; then \
echo "UV version: $$(uv --version)"; \
echo "UV path: $$(which uv)"; \
fi
@echo "Git version: $$(git --version)"
@echo "Current branch: $$(git rev-parse --abbrev-ref HEAD)"
@echo "Working directory: $$(pwd)"
@echo "Virtual environment: $${VIRTUAL_ENV:-Not activated}"
# Quality gate for CI/CD
quality-gate: ## Quality gate check (for CI/CD)
@echo "$(RED)πͺ Running quality gate checks...$(NC)"
@echo "$(BLUE)Step 1/5: Linting...$(NC)"
@$(MAKE) ci-lint
@echo "$(BLUE)Step 2/5: Type checking...$(NC)"
@$(PYTHON_CMD) mypy . --install-types --non-interactive
@echo "$(BLUE)Step 3/5: Security scanning...$(NC)"
@$(MAKE) ci-security
@echo "$(BLUE)Step 4/5: Testing...$(NC)"
@$(MAKE) ci-test
@echo "$(BLUE)Step 5/5: Coverage check...$(NC)"
@$(PYTHON_CMD) coverage report --fail-under=80
@echo "$(GREEN)β
All quality gate checks passed!$(NC)"
# Team workflow shortcuts
morning: ## Morning routine - update and check
@echo "$(GREEN)π
Starting morning development routine...$(NC)"
@git pull origin main
@$(MAKE) update
@$(MAKE) quick
commit-ready: ## Check if code is ready for commit
@echo "$(RED)π― Checking if code is ready for commit...$(NC)"
@$(MAKE) check
@echo "$(GREEN)β
Code is ready for commit!$(NC)"
pr-ready: ## Check if code is ready for PR
@echo "$(RED)π― Checking if code is ready for pull request...$(NC)"
@$(MAKE) full
@echo "$(GREEN)β
Code is ready for pull request!$(NC)"
# Release preparation
release-check: ## Check if code is ready for release
@echo "$(RED)π Checking release readiness...$(NC)"
@$(MAKE) quality-gate
@$(PYTHON_CMD) interrogate . --fail-under=70
@echo "$(GREEN)β
Code is ready for release!$(NC)"
# Help for specific workflows
help-dev: ## Show development workflow help
@echo "$(BOLD)Development Workflow$(NC)"
@echo "===================="
@echo ""
@echo "$(BOLD)Daily Development:$(NC)"
@echo "1. make morning # Start of day routine"
@echo "2. [write code]"
@echo "3. make quick # Quick check during development"
@echo "4. make commit-ready # Before committing"
@echo ""
@echo "$(BOLD)Before Pull Request:$(NC)"
@echo "1. make pr-ready # Complete check"
@echo "2. git push origin branch-name"
@echo ""
@echo "$(BOLD)Common Issues:$(NC)"
@echo "β’ Tests failing: make test-fast"
@echo "β’ Linting errors: make lint"
@echo "β’ Security issues: make security"
@echo "β’ Dependency issues: make update"
help-ci: ## Show CI/CD workflow help
@echo "$(BOLD)CI/CD Commands$(NC)"
@echo "==============="
@echo ""
@echo "$(BOLD)Local CI Simulation:$(NC)"
@echo "β’ make ci-lint # Simulate CI linting"
@echo "β’ make ci-test # Simulate CI testing"
@echo "β’ make ci-security # Simulate CI security"
@echo "β’ make quality-gate # Full CI simulation"
@echo ""
@echo "$(BOLD)Release Preparation:$(NC)"
@echo "β’ make release-check # Comprehensive release check"
@echo "β’ make deps-outdated # Check for updates"
@echo "β’ make docs # Verify documentation"
# Advanced debugging commands
debug-deps: ## Debug dependency issues
@echo "$(YELLOW)π Debugging dependency issues...$(NC)"
@echo "$(BOLD)Python Environment:$(NC)"
@python -c "import sys; print(f'Python: {sys.version}'); print(f'Path: {sys.path}')"
@echo ""
@echo "$(BOLD)Installed Packages:$(NC)"
@if command -v uv >/dev/null 2>&1; then \
uv pip list | head -20; \
else \
pip list | head -20; \
fi
@echo ""
@echo "$(BOLD)Virtual Environment:$(NC)"
@echo "VIRTUAL_ENV: ${VIRTUAL_ENV:-Not set}"
@echo "Which Python: $(which python)"
debug-git: ## Debug git and pre-commit issues
@echo "$(YELLOW)π Debugging git and pre-commit...$(NC)"
@echo "$(BOLD)Git Status:$(NC)"
@git status --porcelain
@echo ""
@echo "$(BOLD)Git Config:$(NC)"
@git config --list | grep -E "(user\.|core\.)" | head -10
@echo ""
@echo "$(BOLD)Pre-commit Status:$(NC)"
@$(PYTHON_CMD) pre-commit --version
@if [ -f .git/hooks/pre-commit ]; then \
echo "β
Pre-commit hook installed"; \
else \
echo "β Pre-commit hook not installed - run 'make setup'"; \
fi
debug-tools: ## Debug development tools
@echo "$(YELLOW)π Debugging development tools...$(NC)"
@echo "$(BOLD)Tool Versions:$(NC)"
@echo "Ruff: $($(PYTHON_CMD) ruff --version || echo 'Not installed')"
@echo "MyPy: $($(PYTHON_CMD) mypy --version || echo 'Not installed')"
@echo "Pytest: $($(PYTHON_CMD) pytest --version || echo 'Not installed')"
@echo "Bandit: $($(PYTHON_CMD) bandit --version || echo 'Not installed')"
@echo "Safety: $($(PYTHON_CMD) safety --version || echo 'Not installed')"
# Performance monitoring
perf-test: ## Run performance tests
@echo "$(YELLOW)β‘ Running performance tests...$(NC)"
@$(PYTHON_CMD) pytest tests/ -m perf --benchmark-sort=mean
memory-test: ## Check for memory leaks
@echo "$(YELLOW)π§ Running memory leak tests...$(NC)"
@$(PYTHON_CMD) pytest tests/ -m memory --memray
# Documentation generation
docs-build: ## Build documentation
@echo "$(GREEN)π Building documentation...$(NC)"
@if [ -d docs ]; then \
cd docs && make html; \
else \
echo "No docs directory found. Creating basic structure..."; \
mkdir -p docs; \
echo "# Project Documentation\n\nGenerated documentation goes here." > docs/README.md; \
fi
docs-serve: ## Serve documentation locally
@echo "$(GREEN)π Serving documentation...$(NC)"
@if [ -d docs/_build/html ]; then \
cd docs/_build/html && python -m http.server 8080; \
else \
echo "Documentation not built. Run 'make docs-build' first."; \
fi
# Container and deployment
container-test: ## Test in container environment
@echo "$(BLUE)π³ Testing in container...$(NC)"
@docker build -t genai-test . && docker run --rm genai-test make test
deploy-check: ## Pre-deployment checks
@echo "$(RED)π Running pre-deployment checks...$(NC)"
@$(MAKE) quality-gate
@echo "$(BLUE)Checking for secrets...$(NC)"
@$(PYTHON_CMD) detect-secrets scan --baseline .secrets.baseline
@echo "$(BLUE)Checking dependencies for vulnerabilities...$(NC)"
@$(PYTHON_CMD) safety check --json
@echo "$(GREEN)β
Deployment checks passed!$(NC)"
# Team collaboration
sync-hooks: ## Sync pre-commit hooks across team
@echo "$(BLUE)π Syncing pre-commit hooks...$(NC)"
@$(PYTHON_CMD) pre-commit install
@$(PYTHON_CMD) pre-commit autoupdate
@$(PYTHON_CMD) pre-commit run --all-files || echo "Some files were updated by hooks"
team-setup: ## Setup for new team members
@echo "$(GREEN)π₯ Setting up for new team member...$(NC)"
@$(MAKE) setup
@$(MAKE) help-dev
@echo ""
@echo "$(BOLD)$(GREEN)π Setup complete! Next steps:$(NC)"
@echo "1. Review DEVELOPMENT_GUIDE.md"
@echo "2. Run 'make morning' to start developing"
@echo "3. Ask team for access to shared resources (API keys, etc.)"
# Maintenance and cleanup
deep-clean: ## Deep clean all generated files
@echo "$(YELLOW)π§Ή Deep cleaning project...$(NC)"
@$(MAKE) clean
@echo "Removing additional cache directories..."
@find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@find . -type f -name "*.pyo" -delete 2>/dev/null || true
@rm -rf .coverage htmlcov/ .pytest_cache/ .mypy_cache/ .ruff_cache/
@echo "$(GREEN)β
Deep clean completed!$(NC)"
reset-env: ## Reset virtual environment
@echo "$(RED)π Resetting virtual environment...$(NC)"
@if [ -d .venv ]; then \
rm -rf .venv; \
echo "Removed .venv directory"; \
fi
@if command -v uv >/dev/null 2>&1; then \
uv venv; \
uv sync --dev; \
else \
python -m venv .venv; \
. .venv/bin/activate && pip install -e .[dev]; \
fi
@$(MAKE) setup
@echo "$(GREEN)β
Environment reset completed!$(NC)"
# Troubleshooting
troubleshoot: ## Run troubleshooting diagnostics
@echo "$(YELLOW)π§ Running troubleshooting diagnostics...$(NC)"
@echo ""
@$(MAKE) env-info
@echo ""
@$(MAKE) debug-deps
@echo ""
@$(MAKE) debug-git
@echo ""
@$(MAKE) debug-tools
@echo ""
@echo "$(BOLD)Common Solutions:$(NC)"
@echo "β’ Environment issues: make reset-env"
@echo "β’ Tool issues: make update"
@echo "β’ Git issues: make sync-hooks"
@echo "β’ Cache issues: make deep-clean"
# Special targets for different environments
dev-install: ## Install development dependencies only
@echo "$(GREEN)π¦ Installing development dependencies...$(NC)"
@if command -v uv >/dev/null 2>&1; then \
uv sync --dev; \
else \
pip install -e ".[dev]"; \
fi
prod-install: ## Install production dependencies only
@echo "$(GREEN)π¦ Installing production dependencies...$(NC)"
@if command -v uv >/dev/null 2>&1; then \
uv sync --no-dev; \
else \
pip install -e .; \
fi
# Version and release management
version: ## Show current version
@echo "$(BLUE)π¦ Current version information:$(NC)"
@echo "Project version: $(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])" 2>/dev/null || echo "Could not read version")"
@echo "Git tag: $(git describe --tags --abbrev=0 2>/dev/null || echo "No tags found")"
@echo "Git commit: $(git rev-parse --short HEAD)"
# IDE and editor setup
vscode-setup: ## Setup VS Code configuration
@echo "$(BLUE)π» Setting up VS Code configuration...$(NC)"
@mkdir -p .vscode
@cat > .vscode/settings.json << 'EOF'
{
"python.defaultInterpreterPath": "./.venv/bin/python",
"python.linting.enabled": true,
"python.linting.ruffEnabled": true,
"python.formatting.provider": "none",
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
}
},
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"python.testing.pytestArgs": ["tests/"],
"files.exclude": {
"**/__pycache__": true,
"**/.pytest_cache": true,
"**/.mypy_cache": true,
"**/.ruff_cache": true,
"**/htmlcov": true
}
}
EOF
@echo "$(GREEN)β
VS Code configuration created!$(NC)"
# Final catch-all for unknown targets
%:
@echo "$(RED)β Unknown target: $@$(NC)"
@echo "Run '$(BOLD)make help$(NC)' to see available commands."
@exit 1