Format backend codebase with ruff

This commit is contained in:
Pier-Jean Malandrino 2026-04-02 12:04:57 +02:00
parent 29d36b9fc2
commit d42c97160d
8 changed files with 35 additions and 15 deletions

View file

@ -1,3 +1 @@
pytest_plugins = ["pytest_asyncio"]

View file

@ -43,7 +43,11 @@ def to_topleft_list(bbox: BoundingBox, page_height: float) -> list[float]:
if right <= left or bottom <= top:
logger.debug(
"Degenerate bbox skipped: [%.1f, %.1f, %.1f, %.1f] (page_height=%.1f)",
left, top, right, bottom, page_height,
left,
top,
right,
bottom,
page_height,
)
return list(EMPTY_BBOX)

View file

@ -71,7 +71,9 @@ class ServeConverter:
return headers
async def convert(
self, file_path: str, options: ConversionOptions,
self,
file_path: str,
options: ConversionOptions,
) -> ConversionResult:
"""Convert a document by uploading it to Docling Serve."""
path = Path(file_path)
@ -202,7 +204,9 @@ def _add_element(item: dict, pages: dict[int, PageDetail]) -> None:
page_no = prov.get("page_no", 1)
if page_no not in pages:
pages[page_no] = PageDetail(
page_number=page_no, width=612.0, height=792.0,
page_number=page_no,
width=612.0,
height=792.0,
)
bbox_data = prov.get("bbox", {})

View file

@ -14,7 +14,9 @@ class Settings:
conversion_timeout: int = 600
upload_dir: str = "./uploads"
db_path: str = "./data/docling_studio.db"
cors_origins: list[str] = field(default_factory=lambda: ["http://localhost:3000", "http://localhost:5173"])
cors_origins: list[str] = field(
default_factory=lambda: ["http://localhost:3000", "http://localhost:5173"]
)
@classmethod
def from_env(cls) -> Settings:

View file

@ -28,8 +28,15 @@ async def insert(doc: Document) -> None:
await db.execute(
"""INSERT INTO documents (id, filename, content_type, file_size, page_count, storage_path, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?)""",
(doc.id, doc.filename, doc.content_type, doc.file_size,
doc.page_count, doc.storage_path, str(doc.created_at)),
(
doc.id,
doc.filename,
doc.content_type,
doc.file_size,
doc.page_count,
doc.storage_path,
str(doc.created_at),
),
)
await db.commit()

View file

@ -14,6 +14,7 @@ from domain.bbox import EMPTY_BBOX, to_topleft_list
# Standard conversions
# ---------------------------------------------------------------------------
class TestToTopleftListStandard:
"""Normal bbox conversions (happy path)."""
@ -60,6 +61,7 @@ class TestToTopleftListStandard:
# Page format variations
# ---------------------------------------------------------------------------
class TestPageFormats:
"""Verify correct conversion across different page sizes."""
@ -105,6 +107,7 @@ class TestPageFormats:
# Degenerate / edge-case bboxes
# ---------------------------------------------------------------------------
class TestDegenerateBboxes:
"""Bboxes that are invalid or degenerate should return EMPTY_BBOX."""
@ -151,6 +154,7 @@ class TestDegenerateBboxes:
# Precision and boundary values
# ---------------------------------------------------------------------------
class TestPrecision:
"""Floating-point precision and edge values."""

View file

@ -1,6 +1,5 @@
"""Tests for persistence repositories using a temporary SQLite database."""
import pytest
from domain.models import AnalysisJob, AnalysisStatus, Document

View file

@ -1,6 +1,5 @@
"""Tests for API schemas — camelCase serialization and validation."""
import pytest
from api.schemas import (
@ -97,7 +96,10 @@ class TestPipelineOptionsRequest:
def test_custom_values(self):
opts = PipelineOptionsRequest(
do_ocr=False, table_mode="fast", do_code_enrichment=True, images_scale=2.0,
do_ocr=False,
table_mode="fast",
do_code_enrichment=True,
images_scale=2.0,
)
assert opts.do_ocr is False
assert opts.table_mode == "fast"