From fc8acbc442bbc66898d73c91bc8de13cf7a3d0b6 Mon Sep 17 00:00:00 2001 From: Leynos Date: Thu, 7 Aug 2025 20:29:49 +0100 Subject: [PATCH 1/3] Merge file and CLI rendering helpers Consolidate temporary file creation and mermaid CLI invocation into _render_diagram, simplifying render_block. Update tests accordingly. --- nixie/cli.py | 2 +- nixie/unittests/test_render_diagram.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/nixie/cli.py b/nixie/cli.py index fb4df86..767c49e 100644 --- a/nixie/cli.py +++ b/nixie/cli.py @@ -219,7 +219,7 @@ async def render_block( ) except RuntimeError as exc: print(exc, file=sys.stderr) - except Exception as exc: + except Exception as exc: # pragma: no cover - unexpected print(f"{path}: unexpected error in diagram {idx}", file=sys.stderr) traceback.print_exception(type(exc), exc, exc.__traceback__, file=sys.stderr) else: diff --git a/nixie/unittests/test_render_diagram.py b/nixie/unittests/test_render_diagram.py index 1e5d21f..be58b83 100644 --- a/nixie/unittests/test_render_diagram.py +++ b/nixie/unittests/test_render_diagram.py @@ -1,5 +1,4 @@ from __future__ import annotations - import asyncio import logging import shlex From 5656e7859320fe6d39cb53047379967688481c35 Mon Sep 17 00:00:00 2001 From: Payton McIntosh Date: Fri, 8 Aug 2025 00:14:20 +0100 Subject: [PATCH 2/3] Apply PyUpgrade --- nixie/cli.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/nixie/cli.py b/nixie/cli.py index 767c49e..2408025 100644 --- a/nixie/cli.py +++ b/nixie/cli.py @@ -108,7 +108,7 @@ async def wait_for_proc( """Wait for a process to complete and return its success status and stderr.""" try: _, stderr = await asyncio.wait_for(proc.communicate(), timeout) - except asyncio.TimeoutError: + except TimeoutError: proc.kill() await proc.wait() print(f"{path}: diagram {idx} timed out", file=sys.stderr) @@ -212,9 +212,7 @@ async def render_block( except FileNotFoundError as exc: cli = exc.filename or "mmdc" print( - "Error: '{0}' not found. Install Node.js with npx or Bun to use @mermaid-js/mermaid-cli.".format( - cli - ), + f"Error: '{cli}' not found. Install Node.js with npx or Bun to use @mermaid-js/mermaid-cli.", file=sys.stderr, ) except RuntimeError as exc: From bb13e4ef98501cf57ce28f54ce5c4e19cdf9d7a1 Mon Sep 17 00:00:00 2001 From: Payton McIntosh Date: Fri, 8 Aug 2025 00:23:40 +0100 Subject: [PATCH 3/3] Remove broad except in render_block and unused import --- nixie/cli.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nixie/cli.py b/nixie/cli.py index 2408025..e560bfc 100644 --- a/nixie/cli.py +++ b/nixie/cli.py @@ -22,7 +22,6 @@ import shutil import sys import tempfile -import traceback import typing from contextlib import contextmanager from pathlib import Path @@ -217,9 +216,6 @@ async def render_block( ) except RuntimeError as exc: print(exc, file=sys.stderr) - except Exception as exc: # pragma: no cover - unexpected - print(f"{path}: unexpected error in diagram {idx}", file=sys.stderr) - traceback.print_exception(type(exc), exc, exc.__traceback__, file=sys.stderr) else: return True return False