refactor: convert f-string logging to lazy %-style format (G004)

Sweep all 1676 G004 violations across 112 files, converting
`logger.<level>(f"…{x}…")` to `logger.<level>("…%s…", x)`.

Why: ruff rule G004 was added to pyproject.toml to enforce lazy
%-style logging — defers formatting until the log level is enabled
and lets structured log tooling match the unformatted template.

Conversion preserves rendered output byte-for-byte:
- `{x}` → `%s` + `x`
- `{x!r}` / `{x!s}` / `{x!a}` → `%r` / `%s` / `%a`
- Format specs (`{x:.2f}`, `{x:>10}`) → `%s` + `format(x, 'spec')`
  (printf-style specs aren't 1:1 with Python format specs, so we
  delegate to `format()` to keep identical output)
- Literal `%` → `%%`
- Concatenated f-strings (`f"a {x} " "b"`) flattened
- Trailing kwargs (`exc_info=True`) preserved

Verified:
- `uv run ruff check --select G004` → 0 violations
- `uv run ty check -- nextcloud_mcp_server` → passes
- `uv run pytest tests/unit/` → 1010 passed

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-05-13 01:12:17 +02:00
co-authored by Claude Opus 4.7
parent a4e6125d28
commit 665cb9b1eb
112 changed files with 2534 additions and 1859 deletions
@@ -55,7 +55,7 @@ class CustomHTTPProcessor(DocumentProcessor):
self._name = name
self._supported_types = supported_types or set()
logger.info(f"Initialized CustomHTTPProcessor: {name} -> {api_url}")
logger.info("Initialized CustomHTTPProcessor: %s -> %s", name, api_url)
@property
def name(self) -> str:
@@ -114,7 +114,9 @@ class CustomHTTPProcessor(DocumentProcessor):
metadata = result.get("metadata", {})
logger.debug(
f"Custom processor '{self.name}' extracted {len(text)} characters"
"Custom processor '%s' extracted %s characters",
self.name,
len(text),
)
return ProcessingResult(
@@ -125,10 +127,10 @@ class CustomHTTPProcessor(DocumentProcessor):
)
except httpx.HTTPError as e:
logger.error(f"Custom processor '{self.name}' HTTP error: {e}")
logger.error("Custom processor '%s' HTTP error: %s", self.name, e)
raise ProcessorError(f"API call failed: {str(e)}") from e
except Exception as e:
logger.error(f"Custom processor '{self.name}' failed: {e}")
logger.error("Custom processor '%s' failed: %s", self.name, e)
raise ProcessorError(f"Processing failed: {str(e)}") from e
async def health_check(self) -> bool:
@@ -146,5 +148,7 @@ class CustomHTTPProcessor(DocumentProcessor):
)
return response.status_code < 500
except Exception as e:
logger.warning(f"Custom processor '{self.name}' health check failed: {e}")
logger.warning(
"Custom processor '%s' health check failed: %s", self.name, e
)
return False
@@ -59,7 +59,8 @@ class PyMuPDFProcessor(DocumentProcessor):
if self.extract_images:
self.image_dir.mkdir(exist_ok=True, parents=True)
logger.info(
f"Initialized PyMuPDFProcessor with image extraction to {self.image_dir}"
"Initialized PyMuPDFProcessor with image extraction to %s",
self.image_dir,
)
else:
logger.info("Initialized PyMuPDFProcessor without image extraction")
@@ -175,9 +176,11 @@ class PyMuPDFProcessor(DocumentProcessor):
await progress_callback(100, 100, "Processing complete")
logger.info(
f"Successfully processed PDF {filename or '<bytes>'}: "
f"{metadata['page_count']} pages, {len(md_text)} chars, "
f"{metadata.get('image_count', 0)} images"
"Successfully processed PDF %s: %s pages, %s chars, %s images",
filename or "<bytes>",
metadata["page_count"],
len(md_text),
metadata.get("image_count", 0),
)
return ProcessingResult(
@@ -250,5 +253,5 @@ class PyMuPDFProcessor(DocumentProcessor):
test_doc.close()
return True
except Exception as e:
logger.error(f"PyMuPDF health check failed: {e}")
logger.error("PyMuPDF health check failed: %s", e)
return False
@@ -41,7 +41,7 @@ class ProcessorRegistry:
name = processor.name
if name in self._processors:
logger.warning(f"Processor '{name}' already registered, replacing")
logger.warning("Processor '%s' already registered, replacing", name)
self._processors[name] = (processor, priority)
@@ -62,8 +62,10 @@ class ProcessorRegistry:
self._priority_order.append(name)
logger.info(
f"Registered processor: {name} "
f"(priority={priority}, supports={len(processor.supported_mime_types)} types)"
"Registered processor: %s (priority=%s, supports=%s types)",
name,
priority,
len(processor.supported_mime_types),
)
def get_processor(self, name: str) -> Optional[DocumentProcessor]:
@@ -93,10 +95,10 @@ class ProcessorRegistry:
for name in self._priority_order:
processor = self._processors[name][0]
if processor.supports(content_type):
logger.debug(f"Found processor '{name}' for type '{content_type}'")
logger.debug("Found processor '%s' for type '%s'", name, content_type)
return processor
logger.debug(f"No processor found for type '{content_type}'")
logger.debug("No processor found for type '%s'", content_type)
return None
def list_processors(self) -> list[str]:
@@ -150,7 +152,7 @@ class ProcessorRegistry:
f"Registered processors: {', '.join(self.list_processors())}"
)
logger.info(f"Processing with '{processor.name}' processor")
logger.info("Processing with '%s' processor", processor.name)
# Process
return await processor.process(
@@ -71,7 +71,7 @@ class TesseractProcessor(DocumentProcessor):
)
self.default_lang = default_lang
logger.info(f"Initialized TesseractProcessor: lang={default_lang}")
logger.info("Initialized TesseractProcessor: lang=%s", default_lang)
@property
def name(self) -> str:
@@ -137,8 +137,9 @@ class TesseractProcessor(DocumentProcessor):
}
logger.debug(
f"Tesseract OCR completed: {len(text)} chars, "
f"confidence={avg_confidence:.1f}%"
"Tesseract OCR completed: %s chars, confidence=%s%%",
len(text),
format(avg_confidence, ".1f"),
)
return ProcessingResult(
@@ -149,7 +150,7 @@ class TesseractProcessor(DocumentProcessor):
)
except Exception as e:
logger.error(f"Tesseract processing failed: {e}")
logger.error("Tesseract processing failed: %s", e)
raise ProcessorError(f"OCR failed: {str(e)}") from e
async def health_check(self) -> bool:
@@ -68,9 +68,11 @@ class UnstructuredProcessor(DocumentProcessor):
self.progress_interval = progress_interval
logger.info(
f"Initialized UnstructuredProcessor: {api_url}, "
f"strategy={default_strategy}, languages={self.default_languages}, "
f"progress_interval={progress_interval}s"
"Initialized UnstructuredProcessor: %s, strategy=%s, languages=%s, progress_interval=%ss",
api_url,
default_strategy,
self.default_languages,
progress_interval,
)
@property
@@ -117,9 +119,9 @@ class UnstructuredProcessor(DocumentProcessor):
total=None, # Unknown total duration # type: ignore
message=message, # type: ignore
)
logger.debug(f"Progress update sent: {elapsed}s elapsed")
logger.debug("Progress update sent: %ss elapsed", elapsed)
except Exception as e:
logger.warning(f"Failed to send progress update: {e}")
logger.warning("Failed to send progress update: %s", e)
logger.debug("Progress poller stopped")
async def _make_api_request(
@@ -165,7 +167,9 @@ class UnstructuredProcessor(DocumentProcessor):
data["extract_image_block_types"] = ",".join(extract_image_block_types)
logger.debug(
f"Processing with Unstructured API: strategy={strategy}, languages={languages}"
"Processing with Unstructured API: strategy=%s, languages=%s",
strategy,
languages,
)
try:
@@ -202,8 +206,9 @@ class UnstructuredProcessor(DocumentProcessor):
}
logger.debug(
f"Successfully processed: {len(elements)} elements, "
f"{len(parsed_text)} characters"
"Successfully processed: %s elements, %s characters",
len(elements),
len(parsed_text),
)
return ProcessingResult(
@@ -214,10 +219,10 @@ class UnstructuredProcessor(DocumentProcessor):
)
except httpx.HTTPError as e:
logger.error(f"Unstructured API HTTP error: {e}")
logger.error("Unstructured API HTTP error: %s", e)
raise ProcessorError(f"HTTP error: {str(e)}") from e
except Exception as e:
logger.error(f"Unstructured API processing failed: {e}")
logger.error("Unstructured API processing failed: %s", e)
raise ProcessorError(f"Processing failed: {str(e)}") from e
async def process(
@@ -306,5 +311,5 @@ class UnstructuredProcessor(DocumentProcessor):
response = await client.get(f"{self.api_url}/healthcheck")
return response.status_code == 200
except Exception as e:
logger.warning(f"Unstructured health check failed: {e}")
logger.warning("Unstructured health check failed: %s", e)
return False