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
+4 -4
View File
@@ -116,7 +116,7 @@ def register_auth_tools(mcp: FastMCP) -> None:
)
init_response = await flow_client.initiate()
except Exception as e:
logger.error(f"Failed to initiate Login Flow v2: {e}")
logger.error("Failed to initiate Login Flow v2: %s", e)
return ProvisionAccessResponse(
status="error",
message=f"Failed to start login flow: {e}",
@@ -227,7 +227,7 @@ def register_auth_tools(mcp: FastMCP) -> None:
try:
session = await storage.get_login_flow_session(user_id)
except Exception as e:
logger.error(f"Failed to check login flow session for {user_id}: {e}")
logger.error("Failed to check login flow session for %s: %s", user_id, e)
return ProvisionStatusResponse(
status="error",
message=f"Failed to check login flow session: {e}",
@@ -264,7 +264,7 @@ def register_auth_tools(mcp: FastMCP) -> None:
poll_token=session["poll_token"],
)
except Exception as e:
logger.error(f"Failed to poll Login Flow v2: {e}")
logger.error("Failed to poll Login Flow v2: %s", e)
return ProvisionStatusResponse(
status="error",
message=f"Failed to check login status: {e}",
@@ -434,7 +434,7 @@ def register_auth_tools(mcp: FastMCP) -> None:
)
init_response = await flow_client.initiate()
except Exception as e:
logger.error(f"Failed to initiate Login Flow v2 for scope update: {e}")
logger.error("Failed to initiate Login Flow v2 for scope update: %s", e)
return UpdateScopesResponse(
status="error",
message=f"Failed to start re-provisioning flow: {e}",
+7 -7
View File
@@ -215,7 +215,7 @@ def configure_calendar_tools(mcp: FastMCP):
try:
start_datetime = dt.datetime.fromisoformat(start_date)
except ValueError:
logger.warning(f"Invalid start_date format: {start_date}")
logger.warning("Invalid start_date format: %s", start_date)
if end_date:
try:
@@ -228,7 +228,7 @@ def configure_calendar_tools(mcp: FastMCP):
try:
end_datetime = dt.datetime.fromisoformat(end_date)
except ValueError:
logger.warning(f"Invalid end_date format: {end_date}")
logger.warning("Invalid end_date format: %s", end_date)
# Build filters dictionary
filters = {}
@@ -519,7 +519,7 @@ def configure_calendar_tools(mcp: FastMCP):
all_events.extend(cal_events)
except Exception as e:
logger.warning(
f"Error getting events from calendar {calendar['name']}: {e}"
"Error getting events from calendar %s: %s", calendar["name"], e
)
continue
@@ -593,7 +593,7 @@ def configure_calendar_tools(mcp: FastMCP):
try:
start_datetime = dt.datetime.strptime(date_range_start, "%Y-%m-%d")
except ValueError:
logger.warning(f"Invalid date_range_start format: {date_range_start}")
logger.warning("Invalid date_range_start format: %s", date_range_start)
if date_range_end:
try:
@@ -601,7 +601,7 @@ def configure_calendar_tools(mcp: FastMCP):
hour=23, minute=59, second=59
)
except ValueError:
logger.warning(f"Invalid date_range_end format: {date_range_end}")
logger.warning("Invalid date_range_end format: %s", date_range_end)
# Build constraints
constraints = {
@@ -686,7 +686,7 @@ def configure_calendar_tools(mcp: FastMCP):
try:
start_datetime = dt.datetime.strptime(start_date, "%Y-%m-%d")
except ValueError:
logger.warning(f"Invalid start_date format: {start_date}")
logger.warning("Invalid start_date format: %s", start_date)
if end_date:
try:
@@ -694,7 +694,7 @@ def configure_calendar_tools(mcp: FastMCP):
hour=23, minute=59, second=59
)
except ValueError:
logger.warning(f"Invalid end_date format: {end_date}")
logger.warning("Invalid end_date format: %s", end_date)
# Build filter criteria
filter_criteria = {}
+3 -3
View File
@@ -266,7 +266,7 @@ async def _provision_nextcloud_access(ctx: Context, user_id: str) -> Provisionin
)
except Exception as e:
logger.error(f"Failed to initiate provisioning: {e}")
logger.error("Failed to initiate provisioning: %s", e)
return ProvisioningResult(
success=False,
message=f"Failed to initiate provisioning: {str(e)}",
@@ -337,7 +337,7 @@ async def _revoke_nextcloud_access(ctx: Context, user_id: str) -> RevocationResu
)
except Exception as e:
logger.error(f"Failed to revoke access: {e}")
logger.error("Failed to revoke access: %s", e)
return RevocationResult(
success=False,
message=f"Failed to revoke access: {str(e)}",
@@ -542,7 +542,7 @@ async def _check_logged_in(ctx: Context, user_id: str) -> str:
return "Login cancelled by user."
except Exception as e:
logger.error(f"Failed to check login status: {e}")
logger.error("Failed to check login status: %s", e)
return f"Error checking login status: {str(e)}"