File size: 10,017 Bytes
2469150
 
832348e
2469150
 
 
832348e
2469150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
832348e
 
2469150
 
10d71ba
2469150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
832348e
2469150
 
 
 
832348e
2469150
 
 
 
 
832348e
2469150
 
 
832348e
2469150
 
 
 
832348e
2469150
 
 
 
 
832348e
2469150
 
 
 
832348e
2469150
 
 
 
 
10d71ba
2469150
 
 
 
832348e
2469150
 
 
 
 
 
10d71ba
2469150
 
 
832348e
2469150
 
 
 
832348e
2469150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
832348e
2469150
 
 
 
832348e
2469150
 
 
832348e
2469150
 
10d71ba
2469150
 
 
 
 
10d71ba
2469150
 
 
 
 
 
10d71ba
2469150
 
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
# Enterprise-Grade Makefile for FRED ML
# Comprehensive build, test, and deployment automation

.PHONY: help install test clean build deploy lint format docs setup dev prod

# Default target
help: ## Show this help message
	@echo "FRED ML - Enterprise Economic Analytics Platform"
	@echo "================================================"
	@echo ""
	@echo "Available 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 "  FRED_API_KEY     - Your FRED API key"
	@echo "  AWS_ACCESS_KEY_ID - AWS access key for cloud features"
	@echo "  AWS_SECRET_ACCESS_KEY - AWS secret key"
	@echo "  ENVIRONMENT      - Set to 'production' for production mode"

# Development setup
setup: ## Initial project setup
	@echo "πŸš€ Setting up FRED ML development environment..."
	python scripts/setup_venv.py
	@echo "βœ… Development environment setup complete!"

venv-create: ## Create virtual environment
	@echo "πŸ—οΈ Creating virtual environment..."
	python scripts/setup_venv.py
	@echo "βœ… Virtual environment created!"

venv-activate: ## Activate virtual environment
	@echo "πŸ”Œ Activating virtual environment..."
	@if [ -d ".venv" ]; then \
		echo "Virtual environment found at .venv/"; \
		echo "To activate, run: source .venv/bin/activate"; \
		echo "Or on Windows: .venv\\Scripts\\activate"; \
	else \
		echo "❌ Virtual environment not found. Run 'make venv-create' first."; \
	fi

install: ## Install dependencies
	@echo "πŸ“¦ Installing dependencies..."
	pip install -r requirements.txt
	pip install -e .
	@echo "βœ… Dependencies installed!"

# Testing targets
test: ## Run all tests
	@echo "πŸ§ͺ Running comprehensive test suite..."
	python tests/run_tests.py
	@echo "βœ… All tests completed!"

test-unit: ## Run unit tests only
	@echo "πŸ§ͺ Running unit tests..."
	python -m pytest tests/unit/ -v --tb=short
	@echo "βœ… Unit tests completed!"

test-integration: ## Run integration tests only
	@echo "πŸ”— Running integration tests..."
	python -m pytest tests/integration/ -v --tb=short
	@echo "βœ… Integration tests completed!"

test-e2e: ## Run end-to-end tests only
	@echo "πŸš€ Running end-to-end tests..."
	python -m pytest tests/e2e/ -v --tb=short
	@echo "βœ… End-to-end tests completed!"

test-coverage: ## Run tests with coverage report
	@echo "πŸ“Š Running tests with coverage..."
	python -m pytest tests/ --cov=src --cov-report=html --cov-report=term
	@echo "βœ… Coverage report generated!"

# Code quality targets
lint: ## Run linting checks
	@echo "πŸ” Running code linting..."
	flake8 src/ tests/ scripts/ --max-line-length=88 --extend-ignore=E203,W503
	@echo "βœ… Linting completed!"

format: ## Format code with black and isort
	@echo "🎨 Formatting code..."
	black src/ tests/ scripts/ --line-length=88
	isort src/ tests/ scripts/ --profile=black
	@echo "βœ… Code formatting completed!"

type-check: ## Run type checking with mypy
	@echo "πŸ” Running type checks..."
	mypy src/ --ignore-missing-imports --disallow-untyped-defs
	@echo "βœ… Type checking completed!"

# Cleanup targets
clean: ## Clean up build artifacts and cache
	@echo "🧹 Cleaning up build artifacts..."
	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 d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
	find . -type d -name "htmlcov" -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 build/ dist/ *.egg-info/ .coverage htmlcov/
	@echo "βœ… Cleanup completed!"

clean-redundant: ## Clean up redundant test files
	@echo "πŸ—‘οΈ Cleaning up redundant files..."
	python scripts/cleanup_redundant_files.py --live
	@echo "βœ… Redundant files cleaned up!"

# Build targets
build: clean ## Build the project
	@echo "πŸ”¨ Building FRED ML..."
	python setup.py sdist bdist_wheel
	@echo "βœ… Build completed!"

build-docker: ## Build Docker image
	@echo "🐳 Building Docker image..."
	docker build -t fred-ml:latest .
	@echo "βœ… Docker image built!"

# Development targets
dev: ## Start development environment
	@echo "πŸš€ Starting development environment..."
	@echo "Make sure you have set FRED_API_KEY environment variable"
	streamlit run streamlit_app.py --server.port=8501 --server.address=0.0.0.0

dev-local: ## Start local development server
	@echo "🏠 Starting local development server..."
	streamlit run frontend/app.py --server.port=8501

# Production targets
prod: ## Start production environment
	@echo "🏭 Starting production environment..."
	ENVIRONMENT=production streamlit run streamlit_app.py --server.port=8501 --server.address=0.0.0.0

# Documentation targets
docs: ## Generate documentation
	@echo "πŸ“š Generating documentation..."
	python scripts/generate_docs.py
	@echo "βœ… Documentation generated!"

docs-serve: ## Serve documentation locally
	@echo "πŸ“– Serving documentation..."
	python -m http.server 8000 --directory docs/
	@echo "πŸ“– Documentation available at http://localhost:8000"

# Deployment targets
deploy-local: ## Deploy locally
	@echo "πŸš€ Deploying locally..."
	python scripts/deploy_local.py
	@echo "βœ… Local deployment completed!"

deploy-aws: ## Deploy to AWS
	@echo "☁️ Deploying to AWS..."
	python scripts/deploy_aws.py
	@echo "βœ… AWS deployment completed!"

deploy-streamlit: ## Deploy to Streamlit Cloud
	@echo "☁️ Deploying to Streamlit Cloud..."
	@echo "Make sure your repository is connected to Streamlit Cloud"
	@echo "Set the main file path to: streamlit_app.py"
	@echo "Add environment variables for FRED_API_KEY and AWS credentials"
	@echo "βœ… Streamlit Cloud deployment instructions provided!"

# Quality assurance targets
qa: lint format type-check test ## Run full quality assurance suite
	@echo "βœ… Quality assurance completed!"

pre-commit: format lint type-check test ## Run pre-commit checks
	@echo "βœ… Pre-commit checks completed!"

# Monitoring and logging targets
logs: ## View application logs
	@echo "πŸ“‹ Viewing application logs..."
	tail -f logs/fred_ml.log

logs-clear: ## Clear application logs
	@echo "πŸ—‘οΈ Clearing application logs..."
	rm -f logs/*.log
	@echo "βœ… Logs cleared!"

# Backup and restore targets
backup: ## Create backup of current state
	@echo "πŸ’Ύ Creating backup..."
	tar -czf backup/fred_ml_backup_$(shell date +%Y%m%d_%H%M%S).tar.gz \
		--exclude='.git' --exclude='.venv' --exclude='__pycache__' \
		--exclude='*.pyc' --exclude='.pytest_cache' --exclude='htmlcov' .
	@echo "βœ… Backup created!"

restore: ## Restore from backup (specify BACKUP_FILE)
	@if [ -z "$(BACKUP_FILE)" ]; then \
		echo "❌ Please specify BACKUP_FILE=path/to/backup.tar.gz"; \
		exit 1; \
	fi
	@echo "πŸ”„ Restoring from backup: $(BACKUP_FILE)"
	tar -xzf $(BACKUP_FILE)
	@echo "βœ… Restore completed!"

# Health check targets
health: ## Check system health
	@echo "πŸ₯ Checking system health..."
	python scripts/health_check.py
	@echo "βœ… Health check completed!"

# Configuration targets
config-validate: ## Validate configuration
	@echo "πŸ” Validating configuration..."
	python -c "from config.settings import get_config; config = get_config(); print('βœ… Configuration valid!')"
	@echo "βœ… Configuration validation completed!"

config-show: ## Show current configuration
	@echo "πŸ“‹ Current configuration:"
	python -c "from config.settings import get_config; import json; config = get_config(); print(json.dumps(config.to_dict(), indent=2))"

# Database targets
db-migrate: ## Run database migrations
	@echo "πŸ—„οΈ Running database migrations..."
	python scripts/db_migrate.py
	@echo "βœ… Database migrations completed!"

db-seed: ## Seed database with initial data
	@echo "🌱 Seeding database..."
	python scripts/db_seed.py
	@echo "βœ… Database seeding completed!"

# Analytics targets
analytics-run: ## Run analytics pipeline
	@echo "πŸ“Š Running analytics pipeline..."
	python scripts/run_analytics.py
	@echo "βœ… Analytics pipeline completed!"

analytics-cache-clear: ## Clear analytics cache
	@echo "πŸ—‘οΈ Clearing analytics cache..."
	rm -rf data/cache/*
	@echo "βœ… Analytics cache cleared!"

# Security targets
security-scan: ## Run security scan
	@echo "πŸ”’ Running security scan..."
	bandit -r src/ -f json -o security_report.json || true
	@echo "βœ… Security scan completed!"

security-audit: ## Run security audit
	@echo "πŸ” Running security audit..."
	safety check
	@echo "βœ… Security audit completed!"

# Performance targets
performance-test: ## Run performance tests
	@echo "⚑ Running performance tests..."
	python scripts/performance_test.py
	@echo "βœ… Performance tests completed!"

performance-profile: ## Profile application performance
	@echo "πŸ“Š Profiling application performance..."
	python -m cProfile -o profile_output.prof scripts/profile_app.py
	@echo "βœ… Performance profiling completed!"

# All-in-one targets
all: setup install qa test build ## Complete setup and testing
	@echo "πŸŽ‰ Complete setup and testing completed!"

production-ready: clean qa test-coverage security-scan performance-test ## Prepare for production
	@echo "🏭 Production readiness check completed!"

# Helpers
version: ## Show version information
	@echo "FRED ML Version: $(shell python -c "import src; print(src.__version__)" 2>/dev/null || echo "Unknown")"
	@echo "Python Version: $(shell python --version)"
	@echo "Pip Version: $(shell pip --version)"

status: ## Show project status
	@echo "πŸ“Š Project Status:"
	@echo "  - Python files: $(shell find src/ -name '*.py' | wc -l)"
	@echo "  - Test files: $(shell find tests/ -name '*.py' | wc -l)"
	@echo "  - Lines of code: $(shell find src/ -name '*.py' -exec wc -l {} + | tail -1 | awk '{print $$1}')"
	@echo "  - Test coverage: $(shell python -m pytest tests/ --cov=src --cov-report=term-missing | tail -1 || echo "Not available")"

# Default target
.DEFAULT_GOAL := help