Update session cleanup logic, pyproject.toml, and Makefile for consistency and improved tooling support
- Replaced `not UserSession.is_active` with `UserSession.is_active == False` in cleanup queries for explicit comparison. - Added `mypy` overrides for `app.alembic` and external libraries (`starlette`). - Refactored `Makefile` to use virtual environment binaries for commands like `ruff`, `mypy`, and `pytest`.
This commit is contained in:
@@ -1,5 +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
|
||||
|
||||
# Default target
|
||||
help:
|
||||
@echo "🚀 FastAPI Backend - Development Commands"
|
||||
@@ -26,23 +34,23 @@ help:
|
||||
|
||||
lint:
|
||||
@echo "🔍 Running Ruff linter..."
|
||||
@ruff check app/ tests/
|
||||
@$(RUFF) check app/ tests/
|
||||
|
||||
lint-fix:
|
||||
@echo "🔧 Running Ruff linter with auto-fix..."
|
||||
@ruff check --fix app/ tests/
|
||||
@$(RUFF) check --fix app/ tests/
|
||||
|
||||
format:
|
||||
@echo "✨ Formatting code with Ruff..."
|
||||
@ruff format app/ tests/
|
||||
@$(RUFF) format app/ tests/
|
||||
|
||||
format-check:
|
||||
@echo "📋 Checking code formatting..."
|
||||
@ruff format --check app/ tests/
|
||||
@$(RUFF) format --check app/ tests/
|
||||
|
||||
type-check:
|
||||
@echo "🔎 Running mypy type checking..."
|
||||
@mypy app/
|
||||
@$(MYPY) app/
|
||||
|
||||
validate: lint format-check type-check
|
||||
@echo "✅ All quality checks passed!"
|
||||
@@ -53,11 +61,11 @@ validate: lint format-check type-check
|
||||
|
||||
test:
|
||||
@echo "🧪 Running tests..."
|
||||
@IS_TEST=True pytest
|
||||
@IS_TEST=True PYTHONPATH=. $(PYTEST)
|
||||
|
||||
test-cov:
|
||||
@echo "🧪 Running tests with coverage..."
|
||||
@IS_TEST=True pytest --cov=app --cov-report=term-missing --cov-report=html -n 0
|
||||
@IS_TEST=True PYTHONPATH=. $(PYTEST) --cov=app --cov-report=term-missing --cov-report=html -n 0
|
||||
@echo "📊 Coverage report generated in htmlcov/index.html"
|
||||
|
||||
# ============================================================================
|
||||
@@ -66,7 +74,7 @@ test-cov:
|
||||
|
||||
install-dev:
|
||||
@echo "📦 Installing development dependencies..."
|
||||
@pip install -r requirements.txt
|
||||
@$(PIP) install -r requirements.txt
|
||||
@echo "✅ Development environment ready!"
|
||||
|
||||
clean:
|
||||
|
||||
@@ -309,7 +309,7 @@ class CRUDSession(CRUDBase[UserSession, SessionCreate, SessionUpdate]):
|
||||
# Use bulk DELETE with WHERE clause - single query
|
||||
stmt = delete(UserSession).where(
|
||||
and_(
|
||||
not UserSession.is_active,
|
||||
UserSession.is_active == False, # noqa: E712
|
||||
UserSession.expires_at < now,
|
||||
UserSession.created_at < cutoff_date,
|
||||
)
|
||||
@@ -356,7 +356,7 @@ class CRUDSession(CRUDBase[UserSession, SessionCreate, SessionUpdate]):
|
||||
stmt = delete(UserSession).where(
|
||||
and_(
|
||||
UserSession.user_id == uuid_obj,
|
||||
not UserSession.is_active,
|
||||
UserSession.is_active == False, # noqa: E712
|
||||
UserSession.expires_at < now,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -139,6 +139,10 @@ plugins = ["pydantic.mypy"]
|
||||
module = "alembic.*"
|
||||
ignore_errors = true
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = "app.alembic.*"
|
||||
ignore_errors = true
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = "sqlalchemy.*"
|
||||
ignore_missing_imports = true
|
||||
@@ -171,6 +175,10 @@ ignore_missing_imports = true
|
||||
module = "apscheduler.*"
|
||||
ignore_missing_imports = true
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
module = "starlette.*"
|
||||
ignore_missing_imports = true
|
||||
|
||||
# ============================================================================
|
||||
# Pydantic mypy plugin configuration
|
||||
# ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user