Chore: update md and make command

This commit is contained in:
ziesorx 2025-09-12 21:44:09 +07:00
parent f617025e01
commit ea31261bff
3 changed files with 256 additions and 47 deletions

View file

@ -1,7 +1,15 @@
# Detector Worker Makefile
# Provides convenient commands for development, testing, and deployment
.PHONY: help install install-dev test test-unit test-integration test-performance test-all test-fast test-coverage lint format clean run docker-build docker-run
# 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:
@ -25,7 +33,9 @@ help:
@echo " make quality Run all quality checks"
@echo ""
@echo "Development:"
@echo " make run Run the detector worker"
@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:"
@ -34,32 +44,32 @@ help:
# Installation targets
install:
pip install -r requirements.txt
$(PIP) install -r requirements.txt
install-dev: install
pip install -r requirements-dev.txt
$(PIP) install -r requirements-dev.txt
# Testing targets
test:
python scripts/run_tests.py --all
$(PYTHON) scripts/run_tests.py --all
test-unit:
python scripts/run_tests.py --unit --verbose
$(PYTHON) scripts/run_tests.py --unit --verbose
test-integration:
python scripts/run_tests.py --integration --verbose
$(PYTHON) scripts/run_tests.py --integration --verbose
test-performance:
python scripts/run_tests.py --performance --verbose
$(PYTHON) scripts/run_tests.py --performance --verbose
test-fast:
python scripts/run_tests.py --fast --verbose
$(PYTHON) scripts/run_tests.py --fast --verbose
test-coverage:
python scripts/run_tests.py --coverage --open-browser
$(PYTHON) scripts/run_tests.py --coverage --open-browser
test-failed:
python scripts/run_tests.py --failed --verbose
$(PYTHON) scripts/run_tests.py --failed --verbose
# Code quality targets
lint:
@ -75,14 +85,24 @@ format:
isort detector_worker tests scripts
quality: lint
python scripts/run_tests.py --quality
$(PYTHON) scripts/run_tests.py --quality
# Development targets
run:
python app.py
@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:
python app.py --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..."
@ -103,17 +123,20 @@ docker-build:
docker build -t detector-worker .
docker-run:
docker run -p 8000:8000 detector-worker
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 8000:8000 detector-worker bash
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
$(PYTHON) scripts/run_tests.py --all --skip-slow
ci-quality:
python scripts/run_tests.py --quality
$(PYTHON) scripts/run_tests.py --quality
# Documentation targets
docs:
@ -121,19 +144,19 @@ docs:
# Development utilities
check-deps:
pip check
$(PIP) check
update-deps:
pip list --outdated
$(PIP) list --outdated
freeze:
pip freeze > requirements-frozen.txt
$(PIP) freeze > requirements-frozen.txt
# Performance profiling
profile:
python -m cProfile -o profile_output.prof app.py
$(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"
@echo "View with: $(PYTHON) -m pstats profile_output.prof"
# Database utilities (if needed)
db-migrate:
@ -145,16 +168,20 @@ db-reset:
# 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)]"
$(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\")}')"
$(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: $(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')"