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