diff --git a/Makefile b/Makefile index ff729f34..a73dc2b9 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,82 @@ -# Makefile -.PHONY: install dev test lint format docker-build docker-up docker-down migrate +# Comprehensive Makefile for LetzShop API +.PHONY: install install-test install-dev install-all dev test test-unit test-integration test-coverage test-fast test-slow test-auth test-products test-stock lint format check docker-build docker-up docker-down migrate clean check-tools setup setup-test -# Development setup +# Check if required tools are installed +check-tools: + @command -v black >/dev/null 2>&1 || { echo >&2 "black is required but not installed. Run 'make install-dev' first."; exit 1; } + @command -v isort >/dev/null 2>&1 || { echo >&2 "isort is required but not installed. Run 'make install-dev' first."; exit 1; } + @command -v flake8 >/dev/null 2>&1 || { echo >&2 "flake8 is required but not installed. Run 'make install-dev' first."; exit 1; } + @command -v mypy >/dev/null 2>&1 || { echo >&2 "mypy is required but not installed. Run 'make install-dev' first."; exit 1; } + +# Production setup install: pip install -r requirements.txt +# Development setup +install-dev-deps: + pip install -r requirements-dev.txt + +# Testing setup +install-test-deps: + pip install -r tests/requirements-test.txt + +# Development server dev: uvicorn main:app --reload --host 0.0.0.0 --port 8000 +# Testing commands test: - pytest -v + pytest tests/ -v -lint: - flake8 . --max-line-length=88 --extend-ignore=E203 - mypy . +test-unit: + pytest tests/ -v -m unit -format: - black . - isort . +test-integration: + pytest tests/ -v -m integration + +test-coverage: + pytest tests/ --cov=app --cov=models --cov=utils --cov=middleware --cov-report=html --cov-report=term-missing + +test-fast: + pytest tests/ -v -m "not slow" + +test-slow: + pytest tests/ -v -m slow + +# Specific test files +test-auth: + pytest tests/test_auth.py -v + +test-products: + pytest tests/test_products.py -v + +test-stock: + pytest tests/test_stock.py -v + +test-marketplace: + pytest tests/test_marketplace.py -v + +test-admin: + pytest tests/test_admin.py -v + +# Code quality +lint: check-tools + @echo "Running flake8..." + flake8 . --max-line-length=88 --extend-ignore=E203,W503 --exclude=venv,__pycache__,.git + @echo "Running mypy..." + mypy . --ignore-missing-imports --exclude venv + +format: check-tools + @echo "Running black..." + black . --exclude venv + @echo "Running isort..." + isort . --skip venv + +# Combined format and lint +check: format lint + +# Combined test with coverage and linting +ci: format lint test-coverage # Database migrations migrate-create: @@ -29,6 +88,10 @@ migrate-up: migrate-down: alembic downgrade -1 +migrate-reset: + alembic downgrade base + alembic upgrade head + # Docker commands docker-build: docker-compose build @@ -42,9 +105,66 @@ docker-down: docker-logs: docker-compose logs -f api +docker-restart: docker-down docker-up + # Production deployment deploy-staging: docker-compose -f docker-compose.staging.yml up -d deploy-prod: docker-compose -f docker-compose.prod.yml up -d + +# Clean up +clean: + rm -rf htmlcov/ + rm -rf .pytest_cache/ + rm -rf .coverage + rm -rf .mypy_cache/ + find . -type d -name "__pycache__" -exec rm -rf {} + + find . -type f -name "*.pyc" -delete + find . -type d -name "*.egg-info" -exec rm -rf {} + + +# Development workflow shortcuts +setup: install install-dev-deps install-test-deps migrate-up + @echo "Development environment setup complete!" + +full-test: format lint test-coverage + @echo "Full test suite completed!" + +# Help command +help: + @echo "Available commands:" + @echo " install - Install production dependencies" + @echo " install-dev-deps - Install development dependencies" + @echo " install-test-deps - Install testing dependencies" + @echo " setup - Complete development setup" + @echo " dev - Start development server" + @echo "" + @echo "Testing:" + @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 (exclude slow ones)" + @echo " test-slow - Run slow tests only" + @echo " full-test - Format, lint, and test with coverage" + @echo "" + @echo "Code Quality:" + @echo " format - Format code with black and isort" + @echo " lint - Run linting with flake8 and mypy" + @echo " check - Format and lint code" + @echo " ci - Full CI pipeline (format, lint, test)" + @echo "" + @echo "Database:" + @echo " migrate-up - Run database migrations" + @echo " migrate-down - Rollback last migration" + @echo " migrate-reset - Reset and rerun all migrations" + @echo "" + @echo "Docker:" + @echo " docker-build - Build Docker containers" + @echo " docker-up - Start Docker containers" + @echo " docker-down - Stop Docker containers" + @echo " docker-restart - Restart Docker containers" + @echo "" + @echo "Cleanup:" + @echo " clean - Remove test artifacts and cache files" diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 00000000..4117a9e4 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,10 @@ + +# Linting and formatting tools +black>=23.0.0 +isort>=5.12.0 +flake8>=6.0.0 +mypy>=1.0.0 + +# Optional: More advanced linting +flake8-docstrings>=1.7.0 +flake8-import-order>=0.18.2 \ No newline at end of file diff --git a/tests/requirements_test.txt b/tests/requirements_test.txt deleted file mode 100644 index 15d877fd..00000000 --- a/tests/requirements_test.txt +++ /dev/null @@ -1,9 +0,0 @@ -# tests/requirements_test.txt -# Testing dependencies -pytest>=7.4.0 -pytest-cov>=4.1.0 -pytest-asyncio>=0.21.0 -pytest-mock>=3.11.0 -httpx>=0.24.0 -faker>=19.0.0 -pytest-repeat>=0.9.4