File size: 7,591 Bytes
b9c68d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Makefile for Hugging Face Spaces Project
# Provides convenient commands for development, testing, and deployment

.PHONY: help install test test-unit test-integration test-coverage test-fast test-slow clean lint format type-check security-check build run dev docs

# Default target
help:
	@echo "Available commands:"
	@echo "  install          - Install all dependencies"
	@echo "  test             - Run all tests"
	@echo "  test-unit        - Run unit tests only"
	@echo "  test-integration - Run integration tests only"
	@echo "  test-coverage    - Run tests with coverage report"
	@echo "  test-fast        - Run fast tests only (exclude slow tests)"
	@echo "  test-slow        - Run slow tests only"
	@echo "  test-parallel    - Run tests in parallel"
	@echo "  lint             - Run code linting"
	@echo "  format           - Format code with black"
	@echo "  type-check       - Run type checking with mypy"
	@echo "  security-check   - Run security checks"
	@echo "  clean            - Clean up generated files"
	@echo "  build            - Build the project"
	@echo "  run              - Run the application"
	@echo "  dev              - Run in development mode"
	@echo "  docs             - Generate documentation"

# Installation
install:
	@echo "Installing dependencies..."
	pip install -r requirements.txt
	pip install -e .

# Testing commands
test:
	@echo "Running all tests..."
	pytest -v

test-unit:
	@echo "Running unit tests..."
	pytest tests/unit/ -v -m "unit or not integration"

test-integration:
	@echo "Running integration tests..."
	pytest tests/integration/ -v -m integration --runintegration

test-coverage:
	@echo "Running tests with coverage..."
	pytest --cov=src --cov=. --cov-report=html --cov-report=term-missing --cov-report=xml

test-fast:
	@echo "Running fast tests..."
	pytest -v -m "not slow"

test-slow:
	@echo "Running slow tests..."
	pytest -v -m slow --runslow

test-parallel:
	@echo "Running tests in parallel..."
	pytest -n auto -v

test-watch:
	@echo "Running tests in watch mode..."
	pytest-watch -- -v

test-debug:
	@echo "Running tests in debug mode..."
	pytest -v -s --pdb

# Code quality commands
lint:
	@echo "Running linting..."
	flake8 src/ tests/ --max-line-length=88 --extend-ignore=E203,W503
	pylint src/ --rcfile=.pylintrc || true

format:
	@echo "Formatting code..."
	black src/ tests/ --line-length=88
	isort src/ tests/ --profile black

format-check:
	@echo "Checking code formatting..."
	black src/ tests/ --check --line-length=88
	isort src/ tests/ --check-only --profile black

type-check:
	@echo "Running type checking..."
	mypy src/ --ignore-missing-imports --no-strict-optional

security-check:
	@echo "Running security checks..."
	bandit -r src/ -f json -o reports/security-report.json || true
	safety check --json --output reports/safety-report.json || true

# Cleanup commands
clean:
	@echo "Cleaning up..."
	find . -type f -name "*.pyc" -delete
	find . -type d -name "__pycache__" -delete
	find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
	rm -rf build/ dist/ .coverage htmlcov/ .pytest_cache/ .mypy_cache/
	rm -rf reports/*.xml reports/*.json reports/*.html

clean-cache:
	@echo "Cleaning cache..."
	rm -rf cache/ai_cache/*
	rm -rf .pytest_cache/
	rm -rf __pycache__/

# Build and run commands
build:
	@echo "Building project..."
	python setup.py build

run:
	@echo "Running application..."
	python app.py

dev:
	@echo "Running in development mode..."
	GRADIO_SERVER_NAME=0.0.0.0 GRADIO_SERVER_PORT=7860 python app.py

# Development tools
shell:
	@echo "Starting Python shell with project context..."
	python -i -c "import sys; sys.path.insert(0, 'src')"

jupyter:
	@echo "Starting Jupyter notebook..."
	jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser

# Documentation
docs:
	@echo "Generating documentation..."
	sphinx-build -b html docs/ docs/_build/html/

docs-serve:
	@echo "Serving documentation..."
	python -m http.server 8000 --directory docs/_build/html/

# Database commands
db-init:
	@echo "Initializing database..."
	python -c "from src.core.database_logger import DatabaseLogger; DatabaseLogger.init_database()"

db-migrate:
	@echo "Running database migrations..."
	python scripts/migrate_database.py

db-reset:
	@echo "Resetting database..."
	rm -f logs/application.db
	make db-init

# Log analysis commands
logs-analyze:
	@echo "Analyzing logs..."
	python scripts/log_analysis/advanced_log_analyzer.py

logs-monitor:
	@echo "Starting log monitoring..."
	python scripts/log_analysis/realtime_monitor.py

logs-demo:
	@echo "Running log analysis demo..."
	python scripts/log_analysis/demo.py

# Performance commands
profile:
	@echo "Running performance profiling..."
	python -m cProfile -o profile_results.prof app.py

profile-view:
	@echo "Viewing profile results..."
	python -c "import pstats; p = pstats.Stats('profile_results.prof'); p.sort_stats('cumulative'); p.print_stats(20)"

benchmark:
	@echo "Running benchmarks..."
	pytest tests/ -m performance --benchmark-only

# Git hooks
pre-commit:
	@echo "Running pre-commit checks..."
	make format-check
	make lint
	make type-check
	make test-fast

pre-push:
	@echo "Running pre-push checks..."
	make test
	make security-check

# CI/CD commands
ci-test:
	@echo "Running CI tests..."
	pytest --junitxml=reports/junit.xml --cov=src --cov-report=xml --cov-report=term

ci-quality:
	@echo "Running CI quality checks..."
	make lint
	make type-check
	make security-check

ci-build:
	@echo "Running CI build..."
	make clean
	make install
	make ci-quality
	make ci-test

# Docker commands (if using Docker)
docker-build:
	@echo "Building Docker image..."
	docker build -t huggingface-spaces .

docker-run:
	@echo "Running Docker container..."
	docker run -p 7860:7860 huggingface-spaces

docker-test:
	@echo "Running tests in Docker..."
	docker run --rm huggingface-spaces make test

# Utility commands
check-deps:
	@echo "Checking for outdated dependencies..."
	pip list --outdated

update-deps:
	@echo "Updating dependencies..."
	pip-review --local --interactive

freeze-deps:
	@echo "Freezing current dependencies..."
	pip freeze > requirements-frozen.txt

# Environment setup
setup-dev:
	@echo "Setting up development environment..."
	python -m venv venv
	@echo "Activate virtual environment with: source venv/bin/activate (Linux/Mac) or venv\\Scripts\\activate (Windows)"
	@echo "Then run: make install"

setup-hooks:
	@echo "Setting up git hooks..."
	echo "#!/bin/bash\nmake pre-commit" > .git/hooks/pre-commit
	echo "#!/bin/bash\nmake pre-push" > .git/hooks/pre-push
	chmod +x .git/hooks/pre-commit .git/hooks/pre-push

# Release commands
version-patch:
	@echo "Bumping patch version..."
	bump2version patch

version-minor:
	@echo "Bumping minor version..."
	bump2version minor

version-major:
	@echo "Bumping major version..."
	bump2version major

release:
	@echo "Creating release..."
	make ci-build
	make version-patch
	git push origin main --tags

# Health check
health-check:
	@echo "Running health checks..."
	@echo "Python version: $$(python --version)"
	@echo "Pip version: $$(pip --version)"
	@echo "Project structure:"
	@find . -name "*.py" -path "./src/*" | head -10
	@echo "Database status:"
	@ls -la logs/ 2>/dev/null || echo "No logs directory found"
	@echo "Cache status:"
	@ls -la cache/ 2>/dev/null || echo "No cache directory found"

# All-in-one commands
full-check:
	@echo "Running full project check..."
	make clean
	make install
	make format-check
	make lint
	make type-check
	make test-coverage
	make security-check

quick-check:
	@echo "Running quick project check..."
	make format-check
	make test-fast