generated from john/python-template
Repair the pre-commit quality gate and clear the ruff backlog
Quality Gate / gate (push) Failing after 47s
Quality Gate / gate (push) Failing after 47s
The pre-commit hooks declared `language: system` with bare `ruff`/`ty` entries, but both are uv-managed dev dependencies and are not on PATH, so every commit failed with `Executable 'ruff' not found`. Route both through `uv run`; keep ruff blocking and make ty advisory (verbose) until its 18 whole-project diagnostics are cleared. With the gate working, clear `ruff check .` to zero: - 18 auto-fixes (import sorting, blank lines, `max()` simplification, `with` merging, unused imports). - Real defects: `SourceNavigation` annotated but never imported in sources_page; two naive `datetime.now()` calls in migration.py now use `datetime.now(UTC)`. - Dead parameters removed: `source_has_photo_table` (computed, passed, never read), `_serialize_value(key=...)`, and unused `request` on two NiceGUI page handlers where the framework injects it optionally. - Mechanical line-length wrapping and one `startswith` tuple collapse. - `# noqa: PLR0915` / `# noqa: PLR1702` on five long UI/migration functions, following the convention already used in jobs_page and settings_page, rather than refactoring during stabilization. Full suite green (377 tests, `-m "not external"`). Co-authored-by: Copilot App <[email protected]>
This commit is contained in:
co-authored by
Copilot App
parent
c6ed3126e0
commit
67feeb28af
@@ -12,10 +12,10 @@ from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlmodel import select
|
||||
|
||||
from transcription.api.errors import register_error_handlers
|
||||
from transcription.api.documents_api import get_document_service
|
||||
from transcription.api.documents_api import get_people_service
|
||||
from transcription.api.documents_api import router
|
||||
from transcription.api.errors import register_error_handlers
|
||||
from transcription.config import Settings
|
||||
from transcription.config import SqliteSettings
|
||||
from transcription.db import create_all
|
||||
|
||||
@@ -14,9 +14,9 @@ from transcription.db.models import DocumentTag
|
||||
from transcription.db.models import Job
|
||||
from transcription.db.models import Person
|
||||
from transcription.db.models import PersonTag
|
||||
from transcription.db.models import Photo
|
||||
from transcription.db.models import Source
|
||||
from transcription.db.models import Tag
|
||||
from transcription.db.models import Photo
|
||||
from transcription.services.documents import DocumentDeleteBlockedError
|
||||
from transcription.services.documents import DocumentError
|
||||
from transcription.services.documents import DocumentService
|
||||
|
||||
@@ -61,15 +61,21 @@ async def test_people_service_handles_person_and_document_person_crud(default_se
|
||||
async def test_people_service_normalizes_and_rejects_duplicate_family_search_ids(default_session_factory):
|
||||
people_service = PeopleService(session_factory=default_session_factory)
|
||||
|
||||
created = await people_service.create_person(Person(given_names="Hig", last_name="Higgins", family_search_id=" g8t4-mdq "))
|
||||
created = await people_service.create_person(
|
||||
Person(given_names="Hig", last_name="Higgins", family_search_id=" g8t4-mdq ")
|
||||
)
|
||||
assert created.family_search_id == "G8T4-MDQ"
|
||||
|
||||
with pytest.raises(PeopleError) as duplicate:
|
||||
await people_service.create_person(Person(given_names="Duplicate", last_name="Hig", family_search_id="G8T4-MDQ"))
|
||||
await people_service.create_person(
|
||||
Person(given_names="Duplicate", last_name="Hig", family_search_id="G8T4-MDQ")
|
||||
)
|
||||
assert duplicate.value.category == ErrorCategory.CONFLICT
|
||||
|
||||
with pytest.raises(PeopleError) as malformed:
|
||||
await people_service.create_person(Person(given_names="Malformed", last_name="Person", family_search_id="not-an-id"))
|
||||
await people_service.create_person(
|
||||
Person(given_names="Malformed", last_name="Person", family_search_id="not-an-id")
|
||||
)
|
||||
assert malformed.value.category == ErrorCategory.VALIDATION
|
||||
|
||||
|
||||
|
||||
@@ -174,8 +174,8 @@ def _relationship_loading_strategies() -> dict[str, dict[str, str | None]]:
|
||||
if keyword.arg != "sa_relationship_kwargs" or not isinstance(keyword.value, ast.Dict):
|
||||
continue
|
||||
for key, value in zip(keyword.value.keys, keyword.value.values, strict=True):
|
||||
if isinstance(key, ast.Constant) and key.value == "lazy" and isinstance(value, ast.Constant):
|
||||
lazy = value.value
|
||||
if isinstance(key, ast.Constant) and key.value == "lazy":
|
||||
lazy = _string_constant(value)
|
||||
strategies.setdefault(class_node.name, {})[attribute] = lazy
|
||||
return strategies
|
||||
|
||||
|
||||
@@ -2,23 +2,21 @@ from __future__ import annotations
|
||||
|
||||
from datetime import UTC
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import text
|
||||
from sqlmodel import SQLModel
|
||||
|
||||
# Register table metadata.
|
||||
from transcription.db import models as _models # noqa: F401
|
||||
from transcription.db.migration import MigrationPaths
|
||||
from transcription.db.migration import export_bundle
|
||||
from transcription.db.migration import import_bundle
|
||||
from transcription.db.migration import migrate_via_bundle
|
||||
from transcription.db.migration import sqlite_url_from_path
|
||||
|
||||
# Register table metadata.
|
||||
from transcription.db import models as _models # noqa: F401
|
||||
|
||||
|
||||
def test_export_import_migration_round_trips_db_and_uploads(tmp_path):
|
||||
source_db_path = tmp_path / "source.db"
|
||||
@@ -173,7 +171,10 @@ def test_export_import_migration_backfills_legacy_portraits_and_homepage_images(
|
||||
{"id": person_id},
|
||||
).one()
|
||||
photos = connection.execute(
|
||||
text('select person_id, path, is_primary from "photo" order by person_id is not null desc, created_at asc')
|
||||
text(
|
||||
'select person_id, path, is_primary from "photo" '
|
||||
"order by person_id is not null desc, created_at asc"
|
||||
)
|
||||
).all()
|
||||
assert person_name[0] == "Legacy"
|
||||
assert person_name[1] == "Portrait"
|
||||
@@ -291,7 +292,9 @@ def test_migration_backfills_legacy_media_when_photo_table_contains_stale_rows(t
|
||||
target_engine = create_engine(target_db_url)
|
||||
try:
|
||||
with target_engine.connect() as connection:
|
||||
photos = connection.execute(text('select person_id, path from "photo" order by person_id is null, path')).all()
|
||||
photos = connection.execute(
|
||||
text('select person_id, path from "photo" order by person_id is null, path')
|
||||
).all()
|
||||
# stale row must not survive; legacy portrait + homepage should be backfilled
|
||||
assert len(photos) == 2
|
||||
assert any(row[0] is not None for row in photos)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""Tests for the documents page routes and action handlers."""
|
||||
|
||||
from datetime import date
|
||||
import re
|
||||
from datetime import date
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
@@ -10,13 +10,13 @@ from sqlmodel import select
|
||||
from transcription.db import session_scope
|
||||
from transcription.db.models import Document
|
||||
from transcription.db.models import DocumentPerson
|
||||
from transcription.db.models import DocumentTag
|
||||
from transcription.db.models import DocumentType
|
||||
from transcription.db.models import Job
|
||||
from transcription.db.models import Person
|
||||
from transcription.db.models import PersonRole
|
||||
from transcription.db.models import Tag
|
||||
from transcription.db.models import DocumentTag
|
||||
from transcription.db.models import Source
|
||||
from transcription.db.models import Tag
|
||||
from transcription.ui.pages.documents_page import _resolve_selected_tag_labels
|
||||
|
||||
# --- Helper Fixtures ---
|
||||
|
||||
@@ -11,8 +11,8 @@ from transcription.db import session_scope
|
||||
from transcription.db.models import Document
|
||||
from transcription.db.models import DocumentPerson
|
||||
from transcription.db.models import Person
|
||||
from transcription.db.models import PersonTag
|
||||
from transcription.db.models import PersonRole
|
||||
from transcription.db.models import PersonTag
|
||||
from transcription.db.models import Photo
|
||||
from transcription.db.models import Source
|
||||
from transcription.db.models import Tag
|
||||
|
||||
Reference in New Issue
Block a user