python-detector-worker/Makefile
2025-09-12 21:44:09 +07:00

187 lines
No EOL
5.6 KiB
Makefile

# Detector Worker Makefile
# Provides convenient commands for development, testing, and deployment
# Cross-platform Python command detection
PYTHON := $(shell command -v python3 2> /dev/null || command -v python 2> /dev/null || echo "python")
PIP := $(shell command -v pip3 2> /dev/null || command -v pip 2> /dev/null || echo "pip")
# Environment configuration
PORT_PROD := 8000
PORT_STAGING := 8001
.PHONY: help install install-dev test test-unit test-integration test-performance test-all test-fast test-coverage lint format clean run run-staging run-prod docker-build docker-run
# Default target
help:
@echo "Detector Worker - Available Commands:"
@echo ""
@echo "Development Setup:"
@echo " make install Install production dependencies"
@echo " make install-dev Install development dependencies"
@echo ""
@echo "Testing:"
@echo " make test Run all tests"
@echo " make test-unit Run unit tests only"
@echo " make test-integration Run integration tests"
@echo " make test-performance Run performance benchmarks"
@echo " make test-fast Run fast tests only"
@echo " make test-coverage Generate coverage report"
@echo ""
@echo "Code Quality:"
@echo " make lint Run code linting"
@echo " make format Format code with black and isort"
@echo " make quality Run all quality checks"
@echo ""
@echo "Development:"
@echo " make run Run the detector worker (production - port 8000)"
@echo " make run-staging Run the detector worker (staging - port 8001)"
@echo " make run-prod Run the detector worker (production - port 8000)"
@echo " make clean Clean build artifacts"
@echo ""
@echo "Docker:"
@echo " make docker-build Build Docker image"
@echo " make docker-run Run Docker container"
# Installation targets
install:
$(PIP) install -r requirements.txt
install-dev: install
$(PIP) install -r requirements-dev.txt
# Testing targets
test:
$(PYTHON) scripts/run_tests.py --all
test-unit:
$(PYTHON) scripts/run_tests.py --unit --verbose
test-integration:
$(PYTHON) scripts/run_tests.py --integration --verbose
test-performance:
$(PYTHON) scripts/run_tests.py --performance --verbose
test-fast:
$(PYTHON) scripts/run_tests.py --fast --verbose
test-coverage:
$(PYTHON) scripts/run_tests.py --coverage --open-browser
test-failed:
$(PYTHON) scripts/run_tests.py --failed --verbose
# Code quality targets
lint:
@echo "Running flake8..."
-flake8 detector_worker --max-line-length=120 --extend-ignore=E203,W503
@echo "Running mypy..."
-mypy detector_worker --ignore-missing-imports --no-strict-optional
format:
@echo "Formatting with black..."
black detector_worker tests scripts
@echo "Sorting imports with isort..."
isort detector_worker tests scripts
quality: lint
$(PYTHON) scripts/run_tests.py --quality
# Development targets
run:
@echo "Running Detector Worker on production port $(PORT_PROD)..."
$(PYTHON) -m uvicorn app:app --host 0.0.0.0 --port $(PORT_PROD) --reload
run-staging:
@echo "Running Detector Worker on staging port $(PORT_STAGING)..."
$(PYTHON) -m uvicorn app:app --host 0.0.0.0 --port $(PORT_STAGING) --reload
run-prod:
@echo "Running Detector Worker on production port $(PORT_PROD)..."
$(PYTHON) -m uvicorn app:app --host 0.0.0.0 --port $(PORT_PROD)
run-debug:
@echo "Running Detector Worker in debug mode on port $(PORT_STAGING)..."
$(PYTHON) -m uvicorn app:app --host 0.0.0.0 --port $(PORT_STAGING) --reload --log-level debug
clean:
@echo "Cleaning build artifacts..."
rm -rf build/
rm -rf dist/
rm -rf *.egg-info/
rm -rf htmlcov/
rm -rf .coverage
rm -rf coverage.xml
rm -rf test-results.xml
rm -rf .pytest_cache/
find . -type d -name __pycache__ -delete
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
# Docker targets
docker-build:
docker build -t detector-worker .
docker-run:
docker run -p $(PORT_PROD):$(PORT_PROD) detector-worker
docker-run-staging:
docker run -p $(PORT_STAGING):$(PORT_STAGING) -e DETECTOR_WORKER_PORT=$(PORT_STAGING) detector-worker
docker-dev:
docker run -it -v $(PWD):/app -p $(PORT_PROD):$(PORT_PROD) detector-worker bash
# CI/CD targets
ci-test:
$(PYTHON) scripts/run_tests.py --all --skip-slow
ci-quality:
$(PYTHON) scripts/run_tests.py --quality
# Documentation targets
docs:
@echo "Documentation generation not yet implemented"
# Development utilities
check-deps:
$(PIP) check
update-deps:
$(PIP) list --outdated
freeze:
$(PIP) freeze > requirements-frozen.txt
# Performance profiling
profile:
$(PYTHON) -m cProfile -o profile_output.prof app.py
@echo "Profile saved to profile_output.prof"
@echo "View with: $(PYTHON) -m pstats profile_output.prof"
# Database utilities (if needed)
db-migrate:
@echo "Database migration not yet implemented"
db-reset:
@echo "Database reset not yet implemented"
# Monitor and debug
monitor:
@echo "Starting system monitor..."
$(PYTHON) -c "import psutil; import time; [print(f'CPU: {psutil.cpu_percent()}%, Memory: {psutil.virtual_memory().percent}%') or time.sleep(1) for _ in range(60)]"
# Utility targets
version:
$(PYTHON) -c "import detector_worker; print(f'Detector Worker Version: {getattr(detector_worker, \"__version__\", \"unknown\")}')"
env-info:
@echo "Environment Information:"
@echo "Python: $(shell $(PYTHON) --version)"
@echo "Pip: $(shell $(PIP) --version)"
@echo "Python Command: $(PYTHON)"
@echo "Pip Command: $(PIP)"
@echo "Working Directory: $(PWD)"
@echo "Production Port: $(PORT_PROD)"
@echo "Staging Port: $(PORT_STAGING)"
@echo "Git Branch: $(shell git branch --show-current 2>/dev/null || echo 'Not a git repository')"
@echo "Git Commit: $(shell git rev-parse --short HEAD 2>/dev/null || echo 'Not a git repository')"