From fce0b8d9a1a86430b85770e31a5fe041995c982b Mon Sep 17 00:00:00 2001 From: Michael Stangl Date: Fri, 21 Aug 2026 12:08:41 +0200 Subject: [PATCH] Fix BOM breaking bin/*.bat and add early Graphviz check to --tosvg wrappers setenv.bat (and activate_venv/get_cmd/install_py.bat) had a UTF-8 BOM, which cmd.exe read as part of the @echo off line, breaking every bin script that calls setenv.bat via `call`. Stripped the BOM. material_flow.bat/.sh and tro_flow.bat/.sh now check up front whether the Graphviz engine --tosvg needs (dot, or neato with --use-cords) is resolvable, and print an early WARNUNG with fix instructions if not - before the CSV is even parsed. The Python scripts still run and report the same failure in detail if the SVG step is actually reached. --- bin/activate_venv.bat | 2 +- bin/get_cmd.bat | 2 +- bin/install_py.bat | 2 +- bin/material_flow.bat | 20 ++++++++++++++++++++ bin/material_flow.sh | 20 ++++++++++++++++++++ bin/setenv.bat | 2 +- bin/tro_flow.bat | 20 ++++++++++++++++++++ bin/tro_flow.sh | 20 ++++++++++++++++++++ doc/Python_Scripts.md | 6 +++++- 9 files changed, 89 insertions(+), 5 deletions(-) diff --git a/bin/activate_venv.bat b/bin/activate_venv.bat index d7bbe4e..9c89b06 100644 --- a/bin/activate_venv.bat +++ b/bin/activate_venv.bat @@ -1,4 +1,4 @@ -@echo off +@echo off REM ================================================================ REM SPS_SKEL - Python Virtual Environment aktivieren REM ================================================================ diff --git a/bin/get_cmd.bat b/bin/get_cmd.bat index 1d97463..82b5118 100644 --- a/bin/get_cmd.bat +++ b/bin/get_cmd.bat @@ -1,4 +1,4 @@ -@echo off +@echo off REM ================================================================ REM SPS_SKEL - Shell mit gesetzten Umgebungsvariablen oeffnen REM ================================================================ diff --git a/bin/install_py.bat b/bin/install_py.bat index a8958f7..412cf92 100644 --- a/bin/install_py.bat +++ b/bin/install_py.bat @@ -1,4 +1,4 @@ -@echo off +@echo off REM ================================================================ REM SPS_SKEL - Python Virtual Environment einrichten REM ================================================================ diff --git a/bin/material_flow.bat b/bin/material_flow.bat index 3f77368..fb606ed 100644 --- a/bin/material_flow.bat +++ b/bin/material_flow.bat @@ -24,6 +24,26 @@ REM Python-Interpreter bestimmen (py-Launcher bevorzugt, sonst python) set "PY=py" py --version >nul 2>&1 || set "PY=python" +REM Graphviz pruefen, wenn --tosvg SVG erzeugen soll (dot, bei --use-cords/ +REM --use-coords neato) - nur ein frueher Hinweis; das eigentliche Skript +REM meldet denselben Fehler beim Rendern noch einmal im Detail. +set "GV_ENGINE=dot" +echo %*| findstr /i /c:"--use-cords" /c:"--use-coords" >nul && set "GV_ENGINE=neato" +echo %*| findstr /i /c:"--tosvg" >nul +if not errorlevel 1 ( + where %GV_ENGINE%.exe >nul 2>&1 + if errorlevel 1 ( + set "GV_OK=" + if /i "%GV_ENGINE%"=="dot" if defined GRAPHVIZ_DOT set "GV_OK=1" + if not defined GV_OK ( + echo WARNUNG: Graphviz '%GV_ENGINE%' nicht im PATH gefunden - --tosvg wird vermutlich fehlschlagen. + echo Graphviz installieren ^(https://graphviz.org/download/^), den bin-Ordner + echo zum PATH hinzufuegen, oder GRAPHVIZ_DOT auf die dot.exe setzen ^(nur fuer 'dot'^). + echo. + ) + ) +) + "%PY%" "%SKEL_LIB%\material_flow.py" %* set "RC=%ERRORLEVEL%" diff --git a/bin/material_flow.sh b/bin/material_flow.sh index d457e51..90c26c4 100644 --- a/bin/material_flow.sh +++ b/bin/material_flow.sh @@ -28,4 +28,24 @@ fi PY="python3" command -v python3 >/dev/null 2>&1 || PY="python" +# Graphviz pruefen, wenn --tosvg SVG erzeugen soll (dot, bei --use-cords/ +# --use-coords neato) - nur ein frueher Hinweis; das eigentliche Skript +# meldet denselben Fehler beim Rendern noch einmal im Detail. +case " $* " in + *" --tosvg "*) + GV_ENGINE="dot" + case " $* " in + *" --use-cords "*|*" --use-coords "*) GV_ENGINE="neato" ;; + esac + if ! command -v "$GV_ENGINE" >/dev/null 2>&1; then + if [ "$GV_ENGINE" != "dot" ] || [ -z "${GRAPHVIZ_DOT:-}" ]; then + echo "WARNUNG: Graphviz '$GV_ENGINE' nicht im PATH gefunden - --tosvg wird vermutlich fehlschlagen." >&2 + echo " Graphviz installieren (https://graphviz.org/download/), PATH ergaenzen," >&2 + echo " oder GRAPHVIZ_DOT auf die dot-Programmdatei setzen (nur fuer 'dot')." >&2 + echo "" >&2 + fi + fi + ;; +esac + exec "$PY" "$SKEL_LIB/material_flow.py" "$@" diff --git a/bin/setenv.bat b/bin/setenv.bat index 610b437..2e14c33 100644 --- a/bin/setenv.bat +++ b/bin/setenv.bat @@ -1,4 +1,4 @@ -@echo off +@echo off REM ================================================================ REM SPS_SKEL - Umgebungsvariablen Setup diff --git a/bin/tro_flow.bat b/bin/tro_flow.bat index 9cd3ee9..19043db 100644 --- a/bin/tro_flow.bat +++ b/bin/tro_flow.bat @@ -27,6 +27,26 @@ REM Python-Interpreter bestimmen (py-Launcher bevorzugt, sonst python) set "PY=py" py --version >nul 2>&1 || set "PY=python" +REM Graphviz pruefen, wenn --tosvg SVG erzeugen soll (dot, bei --use-cords/ +REM --use-coords neato) - nur ein frueher Hinweis; das eigentliche Skript +REM meldet denselben Fehler beim Rendern noch einmal im Detail. +set "GV_ENGINE=dot" +echo %*| findstr /i /c:"--use-cords" /c:"--use-coords" >nul && set "GV_ENGINE=neato" +echo %*| findstr /i /c:"--tosvg" >nul +if not errorlevel 1 ( + where %GV_ENGINE%.exe >nul 2>&1 + if errorlevel 1 ( + set "GV_OK=" + if /i "%GV_ENGINE%"=="dot" if defined GRAPHVIZ_DOT set "GV_OK=1" + if not defined GV_OK ( + echo WARNUNG: Graphviz '%GV_ENGINE%' nicht im PATH gefunden - --tosvg wird vermutlich fehlschlagen. + echo Graphviz installieren ^(https://graphviz.org/download/^), den bin-Ordner + echo zum PATH hinzufuegen, oder GRAPHVIZ_DOT auf die dot.exe setzen ^(nur fuer 'dot'^). + echo. + ) + ) +) + "%PY%" "%SKEL_LIB%\tro_flow.py" %* set "RC=%ERRORLEVEL%" diff --git a/bin/tro_flow.sh b/bin/tro_flow.sh index a1b4745..72e1037 100644 --- a/bin/tro_flow.sh +++ b/bin/tro_flow.sh @@ -31,4 +31,24 @@ fi PY="python3" command -v python3 >/dev/null 2>&1 || PY="python" +# Graphviz pruefen, wenn --tosvg SVG erzeugen soll (dot, bei --use-cords/ +# --use-coords neato) - nur ein frueher Hinweis; das eigentliche Skript +# meldet denselben Fehler beim Rendern noch einmal im Detail. +case " $* " in + *" --tosvg "*) + GV_ENGINE="dot" + case " $* " in + *" --use-cords "*|*" --use-coords "*) GV_ENGINE="neato" ;; + esac + if ! command -v "$GV_ENGINE" >/dev/null 2>&1; then + if [ "$GV_ENGINE" != "dot" ] || [ -z "${GRAPHVIZ_DOT:-}" ]; then + echo "WARNUNG: Graphviz '$GV_ENGINE' nicht im PATH gefunden - --tosvg wird vermutlich fehlschlagen." >&2 + echo " Graphviz installieren (https://graphviz.org/download/), PATH ergaenzen," >&2 + echo " oder GRAPHVIZ_DOT auf die dot-Programmdatei setzen (nur fuer 'dot')." >&2 + echo "" >&2 + fi + fi + ;; +esac + exec "$PY" "$SKEL_LIB/tro_flow.py" "$@" diff --git a/doc/Python_Scripts.md b/doc/Python_Scripts.md index 09bd553..16fc36f 100644 --- a/doc/Python_Scripts.md +++ b/doc/Python_Scripts.md @@ -98,7 +98,11 @@ Conventions shared by the CLI tools: `ezdxf>=1.4.0` for `tro_annotate.py` only) — run `bin\install_py.bat` once. - `--tosvg` needs Graphviz's `dot` (or `neato`, for `tro_flow.py --use-cords`) on `PATH`, or the `GRAPHVIZ_DOT` environment variable pointing - at the `dot` executable. + at the `dot` executable. `bin/material_flow.bat`/`.sh` and `bin/tro_flow.bat`/`.sh` + check for the right engine up front when `--tosvg` is passed and print an early + `WARNUNG` if it's missing (`GRAPHVIZ_DOT` only covers `dot`, not `neato`) — this + is just a heads-up before the CSV is even parsed; the Python script still runs + and reports the same failure in detail (exit code `2`) if the SVG step is reached. ## 3. `material_flow.py` — material-flow graph of the mechanical layout