Skip to content

Commit 1d37519

Browse files
committed
fix(api): clear ruff lint errors blocking CI
- remove unused imports + sort imports (ruff --fix) - contacts/models: TYPE_CHECKING import for Tag forward-ref (F821) - wrap long APIRouter/Query lines (E501) - ruff per-file-ignore E402 for tests/conftest (env set before src import)
1 parent c56d5e3 commit 1d37519

16 files changed

Lines changed: 24 additions & 27 deletions

‎apps/api/pyproject.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ extend-exclude = ["alembic"]
4242
[tool.ruff.lint]
4343
select = ["E", "F", "I", "W", "UP"]
4444

45+
[tool.ruff.lint.per-file-ignores]
46+
# conftest sets JWT_SIGNING_KEY in os.environ before importing src.* (auth.py
47+
# fails fast without it), so module-level imports cannot all sit at the top.
48+
"tests/conftest.py" = ["E402"]
49+
4550
[tool.mypy]
4651
python_version = "3.12"
4752
warn_return_any = true

‎apps/api/src/auth/router.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
from typing import Annotated
1818

1919
import httpx
20-
from fastapi import APIRouter, Depends, HTTPException, Query, Request
20+
from fastapi import APIRouter, Depends, HTTPException, Query
2121
from fastapi.responses import RedirectResponse
2222
from redis.asyncio import Redis
2323
from sqlalchemy.ext.asyncio import AsyncSession
2424

2525
from src.auth.oauth import (
26-
PROVIDER_CONFIG,
2726
SUPPORTED_PROVIDERS,
2827
_apple_credentials_present,
2928
build_authorization_url,

‎apps/api/src/contacts/models.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import datetime
2+
from typing import TYPE_CHECKING
23

34
import sqlalchemy as sa
45
from sqlalchemy import DateTime, Float, ForeignKey, PrimaryKeyConstraint, String, Text, func
56
from sqlalchemy.orm import Mapped, mapped_column, relationship
67

78
from src.lib.database import Base
89

10+
if TYPE_CHECKING:
11+
from src.tags.models import Tag
12+
913

1014
class ContactTag(Base):
1115
__tablename__ = "contact_tag"
@@ -49,7 +53,7 @@ class Contact(Base):
4953
# ORM then inserts only (contact_id, tag_id) and lets the DB apply the
5054
# server defaults for color and updated_at.
5155
# overlaps="contact_id,tag_id" silences the SA2.0 relationship overlap warning.
52-
tags: Mapped[list["Tag"]] = relationship( # type: ignore[name-defined]
56+
tags: Mapped[list["Tag"]] = relationship(
5357
"Tag",
5458
secondary=lambda: ContactTag.__table__,
5559
lazy="selectin",

‎apps/api/src/contacts/repository.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22

3-
from sqlalchemy import select
43
from sqlalchemy import func as sa_func
4+
from sqlalchemy import select
55
from sqlalchemy.ext.asyncio import AsyncSession
66

77
from src.contacts.models import Contact, ContactTag

‎apps/api/src/experiences/router.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
from src.lib.exceptions import ApiResponse
99
from src.lib.rate_limit import check_data_rate_limit
1010

11-
router = APIRouter(prefix="/contacts/{contact_id}/experiences", tags=["experiences"], dependencies=[Depends(check_data_rate_limit)])
11+
router = APIRouter(
12+
prefix="/contacts/{contact_id}/experiences",
13+
tags=["experiences"],
14+
dependencies=[Depends(check_data_rate_limit)],
15+
)
1216

1317

1418
@router.get("")

‎apps/api/src/graph/router.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
@router.get("/data")
1717
async def get_graph_data(
1818
search: str | None = Query(default=None, description="Filter nodes by contact name (case-insensitive)"),
19-
type: LinkType | None = Query(default=None, description="Filter links by LinkType (colleague|classmate|friend|other)"),
19+
type: LinkType | None = Query(
20+
default=None,
21+
description="Filter links by LinkType (colleague|classmate|friend|other)",
22+
),
2023
user_id: str = Depends(get_current_user_id),
2124
session: AsyncSession = Depends(get_session),
2225
redis: Redis = Depends(get_redis),

‎apps/api/src/main.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from src.tags.router import router as tags_router
2929
from src.upload.router import router as upload_router
3030

31-
3231
ENV = os.getenv("ENV", "dev")
3332
IS_PROD = ENV == "prod"
3433

‎apps/api/src/notifications/service.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ async def unregister(self, *, user_id: str, token: str) -> None:
2828
)
2929
if not deleted:
3030
raise NotFoundException(
31-
message=f"Device token not found for the current user"
31+
message="Device token not found for the current user"
3232
)

‎apps/api/tests/conftest.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from src.auth.models import User
2525
from src.contacts.models import Contact
2626
from src.experiences.models import Experience
27-
from src.tags.models import Tag
2827
from src.lib.auth import (
2928
JWT_ALGORITHM,
3029
JWT_AUDIENCE,
@@ -37,6 +36,7 @@
3736
from src.lib.redis import get_redis
3837
from src.main import app
3938
from src.organizations.models import Organization
39+
from src.tags.models import Tag
4040

4141
TEST_DATABASE_URL = os.getenv(
4242
"TEST_DATABASE_URL",

‎apps/api/tests/test_apple_auth.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import os
88
from unittest.mock import patch
99

10-
import pytest
11-
1210

1311
async def test_apple_exchange_returns_501_when_unconfigured(client):
1412
"""POST /auth/exchange with provider=apple must return 501 when Apple env vars are absent."""
@@ -24,7 +22,6 @@ async def test_apple_exchange_returns_501_when_unconfigured(client):
2422
clear=False,
2523
):
2624
# Force the module-level _apple_credentials_present() to see empty values.
27-
import importlib
2825

2926
import src.auth.oauth as oauth_mod
3027

@@ -80,7 +77,6 @@ async def test_unsupported_provider_returns_400(client):
8077

8178
async def test_apple_credentials_present_helper_false_when_env_empty():
8279
"""Unit test: _apple_credentials_present() returns False when env vars are unset."""
83-
import src.auth.oauth as oauth_mod
8480

8581
with patch.dict(
8682
os.environ,

0 commit comments

Comments
 (0)