Skip to content

Commit fa10c11

Browse files
committed
style: ruff format
1 parent 4c3ce98 commit fa10c11

17 files changed

Lines changed: 108 additions & 40 deletions

cubepi/checkpointer/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
def __getattr__(name: str) -> object:
77
if name == "PostgresCheckpointer":
88
from cubepi.checkpointer.postgres.checkpointer import PostgresCheckpointer
9+
910
return PostgresCheckpointer
1011
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
1112

cubepi/checkpointer/postgres/checkpointer.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Append-only message log + per-thread KV (extra). Uses asyncpg pool +
44
msgpack payload encoding. Schema version verified on context entry.
55
"""
6+
67
from __future__ import annotations
78

89
import json
@@ -156,31 +157,39 @@ async def append(self, thread_id: str, messages: list[Message]) -> None:
156157
async with conn.transaction():
157158
# Per-thread advisory lock for monotonic seq allocation
158159
await conn.execute(
159-
"SELECT pg_advisory_xact_lock(hashtext($1))", thread_id,
160+
"SELECT pg_advisory_xact_lock(hashtext($1))",
161+
thread_id,
160162
)
161163
# Lazy thread row creation
162164
await conn.execute(
163165
"INSERT INTO cubepi_threads (thread_id) "
164166
"VALUES ($1) ON CONFLICT DO NOTHING",
165167
thread_id,
166168
)
167-
last_seq = await conn.fetchval(
168-
"SELECT COALESCE(MAX(seq), 0) FROM cubepi_messages "
169-
"WHERE thread_id = $1",
170-
thread_id,
171-
) or 0
169+
last_seq = (
170+
await conn.fetchval(
171+
"SELECT COALESCE(MAX(seq), 0) FROM cubepi_messages "
172+
"WHERE thread_id = $1",
173+
thread_id,
174+
)
175+
or 0
176+
)
172177

173178
rows = []
174179
for i, m in enumerate(messages):
175180
seq = last_seq + i + 1
176-
payload = msgpack.packb(m.model_dump(mode="json"), use_bin_type=True)
177-
rows.append((
178-
thread_id,
179-
seq,
180-
_role_of(m),
181-
json.dumps(m.metadata),
182-
payload,
183-
))
181+
payload = msgpack.packb(
182+
m.model_dump(mode="json"), use_bin_type=True
183+
)
184+
rows.append(
185+
(
186+
thread_id,
187+
seq,
188+
_role_of(m),
189+
json.dumps(m.metadata),
190+
payload,
191+
)
192+
)
184193
await conn.executemany(
185194
"INSERT INTO cubepi_messages "
186195
"(thread_id, seq, role, metadata, payload) "

cubepi/checkpointer/postgres/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
they use. SQLAlchemy 2.0 declarative is the chosen style for cubepi
66
internal definitions.
77
"""
8+
89
from __future__ import annotations
910

1011
import datetime as _dt
@@ -35,7 +36,9 @@ class CubepiThread(CubepiBase):
3536
)
3637
forked_at_seq: Mapped[int | None] = mapped_column(sa.BigInteger, nullable=True)
3738
extra: Mapped[dict[str, Any]] = mapped_column(
38-
JSONB, nullable=False, server_default=sa.text("'{}'::jsonb"),
39+
JSONB,
40+
nullable=False,
41+
server_default=sa.text("'{}'::jsonb"),
3942
)
4043
created_at: Mapped[_dt.datetime] = mapped_column(
4144
sa.TIMESTAMP(timezone=True),

cubepi/mcp/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
cubepi[mcp] extra required.
44
"""
5+
56
from cubepi.mcp.http_loader import load_mcp_tools_http
67
from cubepi.mcp.stdio_loader import load_mcp_tools_stdio
78

cubepi/mcp/_adapter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""MCP tool descriptor → cubepi.AgentTool adapter."""
2+
23
from __future__ import annotations
34

45
from typing import Any, Awaitable, Callable
@@ -67,7 +68,8 @@ def make_mcp_agent_tool(
6768
{"content": [{"type": "text", "text": ...}, ...], "isError": bool}
6869
"""
6970
parameters_model = mcp_schema_to_pydantic_model(
70-
tool_name=name, input_schema=input_schema,
71+
tool_name=name,
72+
input_schema=input_schema,
7173
)
7274

7375
async def _execute(args) -> AgentToolResult:

cubepi/mcp/http_loader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""HTTP/SSE transport MCP tool loader."""
2+
23
from __future__ import annotations
34

45
from typing import Any
@@ -48,7 +49,7 @@ async def _call_remote(tool_name: str, args: dict[str, Any]) -> dict[str, Any]:
4849
def _serialize_call_tool_response(resp: Any) -> dict[str, Any]:
4950
"""Normalize mcp SDK CallToolResult → dict for adapter."""
5051
content = []
51-
for c in (resp.content or []):
52+
for c in resp.content or []:
5253
if getattr(c, "type", None) == "text":
5354
content.append({"type": "text", "text": c.text})
5455
return {

cubepi/mcp/stdio_loader.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""stdio transport MCP tool loader."""
2+
23
from __future__ import annotations
34

45
from typing import Any
@@ -31,7 +32,10 @@ async def load_mcp_tools_stdio(
3132
from mcp.client.stdio import stdio_client
3233

3334
server_params = StdioServerParameters(
34-
command=command, args=args, env=env, cwd=cwd,
35+
command=command,
36+
args=args,
37+
env=env,
38+
cwd=cwd,
3539
)
3640

3741
async def _call_remote(tool_name: str, args_dict: dict[str, Any]) -> dict[str, Any]:
@@ -60,7 +64,7 @@ async def _call_remote(tool_name: str, args_dict: dict[str, Any]) -> dict[str, A
6064

6165
def _serialize_call_tool_response(resp: Any) -> dict[str, Any]:
6266
content = []
63-
for c in (resp.content or []):
67+
for c in resp.content or []:
6468
if getattr(c, "type", None) == "text":
6569
content.append({"type": "text", "text": c.text})
6670
return {

cubepi/providers/anthropic.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def __init__(
6969

7070
self._client = anthropic.AsyncAnthropic(api_key=api_key)
7171
self._cache_retention = cache_retention
72-
self._cache_policy: CacheMarkerPolicy = cache_policy or DefaultCacheMarkerPolicy()
72+
self._cache_policy: CacheMarkerPolicy = (
73+
cache_policy or DefaultCacheMarkerPolicy()
74+
)
7375

7476
async def stream(
7577
self,
@@ -219,7 +221,11 @@ def _apply_indices_markers(
219221
content[-1] = {**last_block, "cache_control": cache_control}
220222
elif isinstance(content, str):
221223
msg["content"] = [
222-
{"type": "text", "text": content, "cache_control": cache_control}
224+
{
225+
"type": "text",
226+
"text": content,
227+
"cache_control": cache_control,
228+
}
223229
]
224230

225231
@staticmethod

tests/checkpointer/test_postgres.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def test_models_import() -> None:
1313
CubepiThread,
1414
cubepi_metadata,
1515
)
16+
1617
assert EXPECTED_SCHEMA_VERSION == 1
1718
assert PARTITION_COUNT == 64
1819
# All three model classes are reachable via the public model module
@@ -45,15 +46,21 @@ def test_cubepi_message_has_gin_index() -> None:
4546

4647

4748
def test_create_message_partitions_op_yields_64_statements() -> None:
48-
from cubepi.checkpointer.postgres.alembic_helpers import create_message_partitions_op
49+
from cubepi.checkpointer.postgres.alembic_helpers import (
50+
create_message_partitions_op,
51+
)
52+
4953
sql = create_message_partitions_op()
5054
assert sql.count("CREATE TABLE cubepi_messages_p") == 64
5155
assert "modulus 64, remainder 0" in sql
5256
assert "modulus 64, remainder 63" in sql
5357

5458

5559
def test_create_message_partitions_op_partitions_are_zero_padded() -> None:
56-
from cubepi.checkpointer.postgres.alembic_helpers import create_message_partitions_op
60+
from cubepi.checkpointer.postgres.alembic_helpers import (
61+
create_message_partitions_op,
62+
)
63+
5764
sql = create_message_partitions_op()
5865
# Partition names use 2-digit padding so they sort lexicographically
5966
assert "cubepi_messages_p00 " in sql
@@ -62,6 +69,7 @@ def test_create_message_partitions_op_partitions_are_zero_padded() -> None:
6269

6370
def test_write_schema_version_op_includes_expected_version() -> None:
6471
from cubepi.checkpointer.postgres.alembic_helpers import write_schema_version_op
72+
6573
sql = write_schema_version_op()
6674
assert "INSERT INTO cubepi_schema_version" in sql
6775
assert "VALUES (1)" in sql
@@ -73,12 +81,14 @@ def test_schema_uninitialized_is_schema_error() -> None:
7381
CubepiSchemaError,
7482
CubepiSchemaUninitialized,
7583
)
84+
7685
err = CubepiSchemaUninitialized("tables missing")
7786
assert isinstance(err, CubepiSchemaError)
7887

7988

8089
def test_schema_mismatch_carries_expected_actual() -> None:
8190
from cubepi.checkpointer.postgres.exceptions import CubepiSchemaMismatch
91+
8292
err = CubepiSchemaMismatch(expected=2, actual=1, hint="run alembic")
8393
assert err.expected == 2
8494
assert err.actual == 1
@@ -89,6 +99,7 @@ def test_schema_mismatch_carries_expected_actual() -> None:
8999

90100
def test_schema_mismatch_without_hint() -> None:
91101
from cubepi.checkpointer.postgres.exceptions import CubepiSchemaMismatch
102+
92103
err = CubepiSchemaMismatch(expected=2, actual=1)
93104
# No hint suffix
94105
assert "expected=2" in str(err)
@@ -132,6 +143,7 @@ async def _setup_schema(dsn: str) -> None:
132143
create_message_partitions_op,
133144
write_schema_version_op,
134145
)
146+
135147
await conn.execute(create_message_partitions_op())
136148
await conn.execute("""
137149
CREATE INDEX ix_cubepi_messages_metadata_gin
@@ -152,7 +164,10 @@ async def test_postgres_checkpointer_round_trip(clean_db) -> None:
152164
"""Append + load round-trips messages with metadata."""
153165
from cubepi.checkpointer.postgres import PostgresCheckpointer
154166
from cubepi.providers.base import (
155-
AssistantMessage, TextContent, Usage, UserMessage,
167+
AssistantMessage,
168+
TextContent,
169+
Usage,
170+
UserMessage,
156171
)
157172

158173
await _setup_schema(clean_db)

tests/mcp/_fake_stdio_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Run as: python -m tests.mcp._fake_stdio_server
66
"""
7+
78
import asyncio
89

910

0 commit comments

Comments
 (0)