Switch backend to uv package manager, update dependencies, and refactor Dockerfile for modern Python tooling

- Migrated dependency management to `uv` for faster, reproducible builds and added `uv.lock`.
- Updated `Dockerfile`: replaced pip with `uv`, added `uv` installation, and refined dependency installation for development and production.
- Enhanced `pyproject.toml`: reorganized dependencies, added support for `uv`.
- Updated docs and Makefile with `uv` usage instructions for streamlined setup and testing.
This commit is contained in:
2025-11-10 16:11:57 +01:00
parent 5c47be2ee5
commit 235c309e4e
5 changed files with 1709 additions and 46 deletions

View File

@@ -1,17 +1,13 @@
.PHONY: help lint lint-fix format format-check type-check test test-cov validate clean install-dev
# Virtual environment binaries
VENV_BIN = .venv/bin
PYTHON = $(VENV_BIN)/python
PIP = $(VENV_BIN)/pip
PYTEST = $(VENV_BIN)/pytest
RUFF = $(VENV_BIN)/ruff
MYPY = $(VENV_BIN)/mypy
.PHONY: help lint lint-fix format format-check type-check test test-cov validate clean install-dev sync
# Default target
help:
@echo "🚀 FastAPI Backend - Development Commands"
@echo ""
@echo "Setup:"
@echo " make install-dev - Install all dependencies with uv (includes dev)"
@echo " make sync - Sync dependencies from uv.lock"
@echo ""
@echo "Quality Checks:"
@echo " make lint - Run Ruff linter (check only)"
@echo " make lint-fix - Run Ruff linter with auto-fix"
@@ -24,33 +20,46 @@ help:
@echo " make test - Run pytest"
@echo " make test-cov - Run pytest with coverage report"
@echo ""
@echo "Setup:"
@echo " make install-dev - Install all development dependencies"
@echo "Cleanup:"
@echo " make clean - Remove cache and build artifacts"
# ============================================================================
# Setup & Cleanup
# ============================================================================
install-dev:
@echo "📦 Installing all dependencies with uv (includes dev)..."
@uv sync --extra dev
@echo "✅ Development environment ready!"
sync:
@echo "🔄 Syncing dependencies from uv.lock..."
@uv sync --extra dev
@echo "✅ Dependencies synced!"
# ============================================================================
# Code Quality
# ============================================================================
lint:
@echo "🔍 Running Ruff linter..."
@$(RUFF) check app/ tests/
@uv run ruff check app/ tests/
lint-fix:
@echo "🔧 Running Ruff linter with auto-fix..."
@$(RUFF) check --fix app/ tests/
@uv run ruff check --fix app/ tests/
format:
@echo "✨ Formatting code with Ruff..."
@$(RUFF) format app/ tests/
@uv run ruff format app/ tests/
format-check:
@echo "📋 Checking code formatting..."
@$(RUFF) format --check app/ tests/
@uv run ruff format --check app/ tests/
type-check:
@echo "🔎 Running mypy type checking..."
@$(MYPY) app/
@uv run mypy app/
validate: lint format-check type-check
@echo "✅ All quality checks passed!"
@@ -61,22 +70,17 @@ validate: lint format-check type-check
test:
@echo "🧪 Running tests..."
@IS_TEST=True PYTHONPATH=. $(PYTEST)
@IS_TEST=True PYTHONPATH=. uv run pytest
test-cov:
@echo "🧪 Running tests with coverage..."
@IS_TEST=True PYTHONPATH=. $(PYTEST) --cov=app --cov-report=term-missing --cov-report=html -n 16
@IS_TEST=True PYTHONPATH=. uv run pytest --cov=app --cov-report=term-missing --cov-report=html -n 16
@echo "📊 Coverage report generated in htmlcov/index.html"
# ============================================================================
# Setup & Cleanup
# Cleanup
# ============================================================================
install-dev:
@echo "📦 Installing development dependencies..."
@$(PIP) install -r requirements.txt
@echo "✅ Development environment ready!"
clean:
@echo "🧹 Cleaning up..."
@find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
@@ -85,6 +89,8 @@ clean:
@find . -type d -name ".ruff_cache" -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name "htmlcov" -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name "build" -exec rm -rf {} + 2>/dev/null || true
@find . -type d -name ".uv_cache" -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name ".coverage" -delete 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@echo "✅ Cleanup complete!"