Skip to content

Commit c2a8495

Browse files
OriNachumclaude
andcommitted
fix(sonar): S3776 — extract doctor text-render helpers (behavior-preserving)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJc5yvfweHP2AEccKNeaVd
2 parents 0902469 + cc0c525 commit c2a8495

1 file changed

Lines changed: 31 additions & 22 deletions

File tree

lobes/cli/_commands/doctor.py

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -263,33 +263,42 @@ def _mark(check: dict) -> str:
263263
return "FAIL" if check["severity"] == "error" else check["severity"]
264264

265265

266-
def _render_text(report: dict) -> str:
267-
status = "healthy" if report["healthy"] else "unhealthy"
268-
lines = [f"lobes doctor: {status}", ""]
269-
for check in report["checks"]:
266+
def _render_check_lines(checks: list[dict]) -> list[str]:
267+
"""Render one ``[mark] id: message`` line per check, plus a remediation
268+
hint line for any that failed with one."""
269+
lines: list[str] = []
270+
for check in checks:
270271
lines.append(f"[{_mark(check)}] {check['id']}: {check['message']}")
271272
if not check["passed"] and check["remediation"]:
272273
lines.append(f" hint: {check['remediation']}")
274+
return lines
275+
276+
277+
def _render_machine_profile_lines(mp: dict) -> list[str]:
278+
"""Render the ``machine profile:`` section (detected card, active
279+
profile, and any mismatch/unknown-card warning)."""
280+
lines = ["", "machine profile:", f" detected card: {mp['detected_card']}"]
281+
if mp["device_name"]:
282+
lines.append(f" device: {mp['device_name']}")
283+
if mp["compute_capability"]:
284+
lines.append(f" compute: {mp['compute_capability']}")
285+
if mp["total_memory_gb"]:
286+
lines.append(f" memory: {mp['total_memory_gb']} GB")
287+
if mp["profile"]:
288+
lines.append(f" profile: {mp['profile']}")
289+
if not mp["validated"]:
290+
lines.append(" status: NOT VALIDATED FOR THIS CARD (forced/unvalidated)")
291+
if mp.get("warning"):
292+
lines.append(f" warning: {mp['warning']}")
293+
return lines
273294

274-
# Add machine profile section if present
275-
if "machine_profile" in report:
276-
mp = report["machine_profile"]
277-
lines.append("")
278-
lines.append("machine profile:")
279-
lines.append(f" detected card: {mp['detected_card']}")
280-
if mp["device_name"]:
281-
lines.append(f" device: {mp['device_name']}")
282-
if mp["compute_capability"]:
283-
lines.append(f" compute: {mp['compute_capability']}")
284-
if mp["total_memory_gb"]:
285-
lines.append(f" memory: {mp['total_memory_gb']} GB")
286-
if mp["profile"]:
287-
lines.append(f" profile: {mp['profile']}")
288-
if not mp["validated"]:
289-
lines.append(" status: NOT VALIDATED FOR THIS CARD (forced/unvalidated)")
290-
if mp.get("warning"):
291-
lines.append(f" warning: {mp['warning']}")
292295

296+
def _render_text(report: dict) -> str:
297+
status = "healthy" if report["healthy"] else "unhealthy"
298+
lines = [f"lobes doctor: {status}", ""]
299+
lines.extend(_render_check_lines(report["checks"]))
300+
if "machine_profile" in report:
301+
lines.extend(_render_machine_profile_lines(report["machine_profile"]))
293302
return "\n".join(lines)
294303

295304

0 commit comments

Comments
 (0)