From baade2ec8cb308dffbf3b8c7beae8a156ec68934 Mon Sep 17 00:00:00 2001 From: kerry Date: Tue, 27 Oct 2026 00:11:20 +0000 Subject: [PATCH] fix: lint paths outside the repo root, sort imports Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm-proxy-extras/litellm_proxy_extras/utils.py | 9 ++++++--- tests/code_coverage_tests/check_spend_logs_folder.py | 11 +++++++---- tests/unit/test_check_spend_logs_folder.py | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/litellm-proxy-extras/litellm_proxy_extras/utils.py b/litellm-proxy-extras/litellm_proxy_extras/utils.py index 84912d6f9b5..0c332f00814 100644 --- a/litellm-proxy-extras/litellm_proxy_extras/utils.py +++ b/litellm-proxy-extras/litellm_proxy_extras/utils.py @@ -17,6 +17,7 @@ from litellm_proxy_extras import prisma_toolchain from litellm_proxy_extras._logging import logger from litellm_proxy_extras._redaction import _redact_credentials from litellm_proxy_extras.migration_lock import held_migration_lock +from litellm_proxy_extras.migration_sources import materialize_prisma_dir from litellm_proxy_extras.prisma_toolchain import ( PRISMA_COMMAND_TIMEOUT_ENV_VAR, PRISMA_MIGRATE_DEPLOY_TIMEOUT_ENV_VAR, @@ -28,8 +29,10 @@ from litellm_proxy_extras.replica_identity import ( REPLICA_IDENTITY_FULL_ENV_VAR, apply_replica_identity_full, ) -from litellm_proxy_extras.migration_sources import materialize_prisma_dir -from litellm_proxy_extras.spend_logs.request_log_indexes import ensure_request_log_indexes, filter_request_log_index_diff +from litellm_proxy_extras.spend_logs.request_log_indexes import ( + ensure_request_log_indexes, + filter_request_log_index_diff, +) if TYPE_CHECKING: import psycopg @@ -721,7 +724,7 @@ class ProxyExtrasDBManager: def _prisma_schema_param(url: str) -> Optional[str]: """The `schema` query param Prisma uses to pick its target schema, or None when the URL does not set one.""" - from urllib.parse import urlparse, parse_qsl + from urllib.parse import parse_qsl, urlparse return next( (v for k, v in parse_qsl(urlparse(url).query) if k == "schema"), diff --git a/tests/code_coverage_tests/check_spend_logs_folder.py b/tests/code_coverage_tests/check_spend_logs_folder.py index 2d70b40b385..013cf4d623b 100644 --- a/tests/code_coverage_tests/check_spend_logs_folder.py +++ b/tests/code_coverage_tests/check_spend_logs_folder.py @@ -22,11 +22,15 @@ TABLE_RE: Final = re.compile(r"\bLiteLLM_SpendLogs\b", re.IGNORECASE) MODEL_BLOCK_RE: Final = re.compile(r"^model LiteLLM_SpendLogs \{\n.*?^\}\n", re.MULTILINE | re.DOTALL) +def _shown(path: Path) -> Path: + return path.relative_to(REPO_ROOT) if path.is_relative_to(REPO_ROOT) else path + + def misplaced_migrations(shared_migrations: Path) -> tuple[str, ...]: scripts: Final = sorted(shared_migrations.glob("*/migration.sql")) return tuple( f"{script.parent.name}/migration.sql mentions LiteLLM_SpendLogs; move the migration to " - f"{SPEND_LOGS_DIR.relative_to(REPO_ROOT)}/migrations/" + f"{_shown(SPEND_LOGS_DIR)}/migrations/" for script in scripts if TABLE_RE.search(script.read_text(encoding="utf-8")) ) @@ -36,11 +40,10 @@ def schema_copy_drift(schema: Path, spend_logs_dir: Path) -> tuple[str, ...]: block: Final = MODEL_BLOCK_RE.search(schema.read_text(encoding="utf-8")) copy: Final = spend_logs_dir / "LiteLLM_SpendLogs.prisma" if block is None: - return (f"{schema.relative_to(REPO_ROOT)} has no `model LiteLLM_SpendLogs` block",) + return (f"{_shown(schema)} has no `model LiteLLM_SpendLogs` block",) if not copy.is_file() or copy.read_text(encoding="utf-8") != block.group(): return ( - f"{copy.relative_to(REPO_ROOT)} must equal the `model LiteLLM_SpendLogs` block in " - f"{schema.relative_to(REPO_ROOT)}; copy the block over", + f"{_shown(copy)} must equal the `model LiteLLM_SpendLogs` block in {_shown(schema)}; copy the block over", ) return () diff --git a/tests/unit/test_check_spend_logs_folder.py b/tests/unit/test_check_spend_logs_folder.py index a686a86b0b7..dcd38cf1ec2 100644 --- a/tests/unit/test_check_spend_logs_folder.py +++ b/tests/unit/test_check_spend_logs_folder.py @@ -69,7 +69,8 @@ class TestSchemaCopy: (tmp_path / "schema.prisma").write_text("model LiteLLM_Other {\n id String @id\n}\n", encoding="utf-8") (tmp_path / "spend_logs").mkdir() found: Final = checker.schema_copy_drift(tmp_path / "schema.prisma", tmp_path / "spend_logs") - assert found == ("schema.prisma has no `model LiteLLM_SpendLogs` block",) or "no `model LiteLLM_SpendLogs`" in found[0] + assert len(found) == 1 + assert "no `model LiteLLM_SpendLogs` block" in found[0] class TestExitCode: