Skip to content

Commit 728e4ae

Browse files
committed
style: apply ruff format to src, tests, and plugins
Reformat 10 files to comply with ruff format checks: - Split long function arguments across multiple lines - Merge unnecessarily split short strings - Use parenthesized with-statements for multiple context managers - Remove extra blank lines and adjust indentation No logic changes. All 618 tests still pass.
1 parent b7d3882 commit 728e4ae

10 files changed

Lines changed: 142 additions & 106 deletions

File tree

plugins/mcp-server-sqlseed/src/mcp_server_sqlseed/server.py

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ def sqlseed_list_gemma_models() -> dict[str, Any]:
347347
return {
348348
"models": [],
349349
"backends": [
350-
{"id": bid, "description": desc, "available": False}
351-
for bid, desc in backend_descriptions.items()
350+
{"id": bid, "description": desc, "available": False} for bid, desc in backend_descriptions.items()
352351
],
353352
"hardware": {},
354353
"error": "sqlseed-ai plugin not installed. Install with: pip install sqlseed-ai",
@@ -363,12 +362,14 @@ def sqlseed_list_gemma_models() -> dict[str, Any]:
363362

364363
# Google AI Studio: check API key
365364
has_api_key = ai_config.has_real_api_key
366-
backends_result.append({
367-
"id": "google_ai_studio",
368-
"description": backend_descriptions["google_ai_studio"],
369-
"available": has_api_key,
370-
"reason": "API key configured" if has_api_key else "No API key (set GOOGLE_API_KEY or SQLSEED_AI_API_KEY)",
371-
})
365+
backends_result.append(
366+
{
367+
"id": "google_ai_studio",
368+
"description": backend_descriptions["google_ai_studio"],
369+
"available": has_api_key,
370+
"reason": "API key configured" if has_api_key else "No API key (set GOOGLE_API_KEY or SQLSEED_AI_API_KEY)",
371+
}
372+
)
372373

373374
# LM Studio / Ollama: check service reachability + loaded models
374375
local_urls: dict[str, str] = {
@@ -394,22 +395,26 @@ def sqlseed_list_gemma_models() -> dict[str, Any]:
394395
else:
395396
reason = "Service not running"
396397

397-
backends_result.append({
398-
"id": backend_id,
399-
"description": backend_descriptions[backend_id],
400-
"available": reachable and bool(loaded),
401-
"reachable": reachable,
402-
"loaded_models": loaded,
403-
"reason": reason,
404-
})
398+
backends_result.append(
399+
{
400+
"id": backend_id,
401+
"description": backend_descriptions[backend_id],
402+
"available": reachable and bool(loaded),
403+
"reachable": reachable,
404+
"loaded_models": loaded,
405+
"reason": reason,
406+
}
407+
)
405408

406409
# OpenAI-compatible: informational only
407-
backends_result.append({
408-
"id": "openai_compat",
409-
"description": backend_descriptions["openai_compat"],
410-
"available": False,
411-
"reason": "Requires explicit base_url configuration",
412-
})
410+
backends_result.append(
411+
{
412+
"id": "openai_compat",
413+
"description": backend_descriptions["openai_compat"],
414+
"available": False,
415+
"reason": "Requires explicit base_url configuration",
416+
}
417+
)
413418

414419
# ── 3. Build model list with compatibility status ──
415420
status_icons: dict[str, str] = {
@@ -425,18 +430,20 @@ def sqlseed_list_gemma_models() -> dict[str, Any]:
425430
for member in GemmaModel:
426431
status = evaluate_model_status(member.value, hw)
427432
model_req = MODEL_REQUIREMENTS.get(member.value, {})
428-
models.append({
429-
"id": member.value,
430-
"display_name": member.display_name,
431-
"status": status,
432-
"status_description": status_icons.get(status, status),
433-
"local_only": member.is_local_only,
434-
"requirements": {
435-
"min_ram_gb": model_req.get("min_ram_gb", 0),
436-
"min_vram_gb": model_req.get("min_vram_gb", 0),
437-
"recommended_vram_gb": model_req.get("recommended_vram_gb", 0),
438-
},
439-
})
433+
models.append(
434+
{
435+
"id": member.value,
436+
"display_name": member.display_name,
437+
"status": status,
438+
"status_description": status_icons.get(status, status),
439+
"local_only": member.is_local_only,
440+
"requirements": {
441+
"min_ram_gb": model_req.get("min_ram_gb", 0),
442+
"min_vram_gb": model_req.get("min_vram_gb", 0),
443+
"recommended_vram_gb": model_req.get("recommended_vram_gb", 0),
444+
},
445+
}
446+
)
440447

441448
# ── 4. Determine best default ──
442449
# Pick the largest capable model (iterate from largest to smallest)

plugins/sqlseed-ai/src/sqlseed_ai/_hardware.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
Supported platforms: Windows, Linux, macOS (Intel + Apple Silicon).
77
"""
8+
89
from __future__ import annotations
910

1011
import ctypes
@@ -30,9 +31,11 @@ class _HardwareCache:
3031

3132
# ── System RAM ───────────────────────────────────────────────────────
3233

34+
3335
def _get_ram_windows() -> tuple[float, float] | None:
3436
"""Get RAM via Win32 API (ctypes). Returns (total_gb, available_gb)."""
3537
try:
38+
3639
class MEMORYSTATUSEX(ctypes.Structure):
3740
_fields_ = [
3841
("dwLength", ctypes.c_ulong),
@@ -78,7 +81,10 @@ def _get_ram_macos() -> tuple[float, float] | None:
7881
try:
7982
result = subprocess.run(
8083
["sysctl", "-n", "hw.memsize"],
81-
capture_output=True, text=True, timeout=5, check=False,
84+
capture_output=True,
85+
text=True,
86+
timeout=5,
87+
check=False,
8288
)
8389
if result.returncode != 0 or not result.stdout:
8490
return None
@@ -87,7 +93,11 @@ def _get_ram_macos() -> tuple[float, float] | None:
8793

8894
avail_gb = 0.0
8995
result = subprocess.run(
90-
["vm_stat"], capture_output=True, text=True, timeout=5, check=False,
96+
["vm_stat"],
97+
capture_output=True,
98+
text=True,
99+
timeout=5,
100+
check=False,
91101
)
92102
if result.returncode == 0 and result.stdout:
93103
# Default page size: Apple Silicon = 16384, Intel Mac = 4096
@@ -124,6 +134,7 @@ def _detect_system_ram() -> dict[str, Any]:
124134

125135
# ── GPU / VRAM ───────────────────────────────────────────────────────
126136

137+
127138
def _detect_gpu_nvidia() -> list[dict[str, Any]]:
128139
"""Detect NVIDIA GPUs via nvidia-smi (works on all platforms)."""
129140
try:
@@ -133,7 +144,10 @@ def _detect_gpu_nvidia() -> list[dict[str, Any]]:
133144
"--query-gpu=name,memory.total,memory.free,driver_version",
134145
"--format=csv,noheader,nounits",
135146
],
136-
capture_output=True, text=True, timeout=5, check=False,
147+
capture_output=True,
148+
text=True,
149+
timeout=5,
150+
check=False,
137151
)
138152
if result.returncode != 0 or not result.stdout:
139153
return []
@@ -144,14 +158,16 @@ def _detect_gpu_nvidia() -> list[dict[str, Any]]:
144158
if len(parts) >= 4:
145159
vram_total = int(parts[1])
146160
vram_free = int(parts[2])
147-
gpus.append({
148-
"name": parts[0],
149-
"vram_total_mb": vram_total,
150-
"vram_free_mb": vram_free,
151-
"vram_total_gb": round(vram_total / 1024, 1),
152-
"driver_version": parts[3],
153-
"vendor": "nvidia",
154-
})
161+
gpus.append(
162+
{
163+
"name": parts[0],
164+
"vram_total_mb": vram_total,
165+
"vram_free_mb": vram_free,
166+
"vram_total_gb": round(vram_total / 1024, 1),
167+
"driver_version": parts[3],
168+
"vendor": "nvidia",
169+
}
170+
)
155171
return gpus
156172
except (FileNotFoundError, subprocess.TimeoutExpired, ValueError):
157173
return []
@@ -162,7 +178,10 @@ def _detect_gpu_macos() -> list[dict[str, Any]]:
162178
try:
163179
result = subprocess.run(
164180
["system_profiler", "SPDisplaysDataType", "-json"],
165-
capture_output=True, text=True, timeout=10, check=False,
181+
capture_output=True,
182+
text=True,
183+
timeout=10,
184+
check=False,
166185
)
167186
if result.returncode != 0 or not result.stdout:
168187
return []
@@ -181,13 +200,15 @@ def _detect_gpu_macos() -> list[dict[str, Any]]:
181200
unit = parts[1].upper()
182201
vram_mb = val * 1024 if "GB" in unit else val
183202

184-
gpus.append({
185-
"name": name,
186-
"vram_total_mb": vram_mb,
187-
"vram_free_mb": 0, # Apple Silicon uses unified memory; discrete VRAM is always 0
188-
"vram_total_gb": round(vram_mb / 1024, 1),
189-
"vendor": "apple",
190-
})
203+
gpus.append(
204+
{
205+
"name": name,
206+
"vram_total_mb": vram_mb,
207+
"vram_free_mb": 0, # Apple Silicon uses unified memory; discrete VRAM is always 0
208+
"vram_total_gb": round(vram_mb / 1024, 1),
209+
"vendor": "apple",
210+
}
211+
)
191212
return gpus
192213
except (FileNotFoundError, json.JSONDecodeError, subprocess.TimeoutExpired, ValueError):
193214
return []
@@ -207,6 +228,7 @@ def _detect_gpus() -> list[dict[str, Any]]:
207228

208229
# ── Public API ───────────────────────────────────────────────────────
209230

231+
210232
def detect_hardware() -> dict[str, Any]:
211233
"""Detect hardware environment. Results are cached for 5 minutes.
212234

src/sqlseed/core/enrichment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def _build_enriched_spec(
147147
if self.is_enumeration_column(col_name, col_info, distinct_count, row_count, is_unique):
148148
choices = distinct_values
149149
if col_info and "INT" in col_info.type.upper():
150+
150151
def _safe_int(v: Any) -> Any:
151152
if isinstance(v, (int, float)):
152153
return int(v)

src/sqlseed/core/mapper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ def map_column(
303303
return snake_pattern
304304

305305
fallback_spec = self._map_from_default(
306-
column_info, column_type, enrich, force_type_infer, include_nullable=True,
306+
column_info,
307+
column_type,
308+
enrich,
309+
force_type_infer,
310+
include_nullable=True,
307311
)
308312
if fallback_spec:
309313
return fallback_spec

src/sqlseed/core/orchestrator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,11 @@ def get_column_mapping(self, table_name: str) -> dict[str, Any]:
565565
"""
566566
self._ensure_connected()
567567
specs, _, _ = self._resolve_specs(
568-
table_name, count=1, columns=None, column_configs=None, enrich=False,
568+
table_name,
569+
count=1,
570+
columns=None,
571+
column_configs=None,
572+
enrich=False,
569573
)
570574
return specs
571575

src/sqlseed/generators/_dispatch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def verify_dispatch_sync() -> None:
5757
import warnings # noqa: PLC0415
5858

5959
warnings.warn(
60-
f"GENERATOR_MAP['{gen_name}'] references '{method_name}' "
61-
f"which does not exist on BaseProvider",
60+
f"GENERATOR_MAP['{gen_name}'] references '{method_name}' which does not exist on BaseProvider",
6261
stacklevel=1,
6362
)

src/sqlseed/generators/base_provider.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,7 @@ def _gen_pattern(self, *, pattern: str | None = None, regex: str | None = None)
354354
import rstr as _rstr # noqa: PLC0415
355355
except ImportError as err:
356356
raise ImportError(
357-
"The 'rstr' package is required for pattern generation. "
358-
"Install it with: pip install rstr"
357+
"The 'rstr' package is required for pattern generation. Install it with: pip install rstr"
359358
) from err
360359
r = _rstr.Rstr(self._rng)
361360
return r.xeger(effective)

tests/test_doc_sync.py

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def _find_marker_claims(marker_name: str) -> list[tuple[Path, str]]:
5656
return claims
5757

5858

59-
6059
def _find_doc_files() -> list[Path]:
6160
"""Collect all .md files that may contain code-derived facts."""
6261
candidates = [
@@ -276,14 +275,7 @@ def _get_mcp_tool_names() -> list[str]:
276275
277276
Looks for @mcp.tool() decorated functions.
278277
"""
279-
code = _read(
280-
ROOT
281-
/ "plugins"
282-
/ "mcp-server-sqlseed"
283-
/ "src"
284-
/ "mcp_server_sqlseed"
285-
/ "server.py"
286-
)
278+
code = _read(ROOT / "plugins" / "mcp-server-sqlseed" / "src" / "mcp_server_sqlseed" / "server.py")
287279
tools: list[str] = []
288280
lines = code.splitlines()
289281
for i, line in enumerate(lines):
@@ -424,8 +416,7 @@ def test_count_in_docs(self):
424416
)
425417
for doc_path, value in marker_claims:
426418
assert int(value) == rule_count, (
427-
f"{doc_path}: marker claims {value} exact-match rules, "
428-
f"but EXACT_MATCH_RULES has {rule_count}"
419+
f"{doc_path}: marker claims {value} exact-match rules, but EXACT_MATCH_RULES has {rule_count}"
429420
)
430421

431422
# Secondary protection: keyword-based search for unmarked claims.
@@ -545,8 +536,7 @@ def test_count_in_docs(self):
545536
)
546537
for doc_path, value in marker_claims:
547538
assert int(value) == rule_count, (
548-
f"{doc_path}: marker claims {value} pattern-match rules, "
549-
f"but PATTERN_MATCH_RULES has {rule_count}"
539+
f"{doc_path}: marker claims {value} pattern-match rules, but PATTERN_MATCH_RULES has {rule_count}"
550540
)
551541

552542
# Secondary protection: keyword-based search for unmarked claims.
@@ -572,9 +562,7 @@ def test_count_in_docs(self):
572562
text = _read(doc_path)
573563
matches = _extract_number_before_keyword(text, ["个枚举", "enum pattern", "enum name"])
574564
for m in matches:
575-
assert int(m) == count, (
576-
f"{doc_path}: claims {m} enum patterns, but ENUM_NAME_PATTERNS has {count}"
577-
)
565+
assert int(m) == count, f"{doc_path}: claims {m} enum patterns, but ENUM_NAME_PATTERNS has {count}"
578566

579567

580568
class TestMcpToolNames:
@@ -584,9 +572,7 @@ def test_tools_documented(self):
584572
tools = _get_mcp_tool_names()
585573
readme = _read(ROOT / "plugins" / "mcp-server-sqlseed" / "README.md")
586574
for tool in tools:
587-
assert tool in readme, (
588-
f"MCP tool '{tool}' not mentioned in mcp-server-sqlseed README.md"
589-
)
575+
assert tool in readme, f"MCP tool '{tool}' not mentioned in mcp-server-sqlseed README.md"
590576

591577

592578
class TestAutoGeneratedMarkers:
@@ -602,6 +588,4 @@ def test_markers_balanced(self):
602588
text = _read(doc_path)
603589
begins = text.count("<!-- BEGIN:AUTO-GENERATED")
604590
ends = text.count("<!-- END:AUTO-GENERATED")
605-
assert begins == ends, (
606-
f"{doc_path}: {begins} BEGIN markers but {ends} END markers"
607-
)
591+
assert begins == ends, f"{doc_path}: {begins} BEGIN markers but {ends} END markers"

tests/test_generators/test_dispatch_sync.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Verify GENERATOR_MAP stays in sync with BaseProvider methods."""
2+
23
from __future__ import annotations
34

45
import warnings

0 commit comments

Comments
 (0)