v0.5.3
Example document / build (push) Has been cancelled
Python application / build (push) Has been cancelled

- Мелкие исправления увеличивающие работу конвертера
This commit is contained in:
Igor20264
2026-09-10 10:50:15 +03:00
parent 510f7e7adf
commit e6b58efeb3
95 changed files with 7165 additions and 8771 deletions
+45 -3
View File
@@ -400,6 +400,43 @@ def _render_dot_local(dot: str, out_path: Path, fmt: str, *, context: bool) -> b
return out_path.is_file() and out_path.stat().st_size > 0
def _render_dot_local_combined(
dot: str,
targets: list[tuple[Path, str]],
*,
context: bool,
) -> set[str]:
"""
One Graphviz process for several formats (`-Tpng -o… -Tsvg -o…`).
Returns the formats actually written; the caller retries the rest one by one.
"""
if len(targets) < 2:
return set()
engine = resolve_graphviz_engine(context=context)
if not engine:
return set()
cmd = [engine]
for out_path, fmt in targets:
cmd += [f"-T{fmt}", f"-o{out_path}"]
try:
subprocess.run(
cmd,
input=_readable_dot(dot),
encoding="utf-8",
check=True,
capture_output=True,
timeout=180,
env=_graphviz_run_env(engine),
)
except (OSError, subprocess.CalledProcessError, subprocess.TimeoutExpired) as exc:
_log.warning("Graphviz %s (multi-format) failed: %s", engine, exc)
return set()
return {
fmt for out_path, fmt in targets
if Path(out_path).is_file() and Path(out_path).stat().st_size > 0
}
def _render_dot_kroki(dot: str, out_path: Path, fmt: str) -> bool:
try:
from .diagram_renderer import (
@@ -455,8 +492,14 @@ def write_dfd_outputs(
dot, is_context = _compile_dot(source)
out_png = Path(out_png)
out_png.parent.mkdir(parents=True, exist_ok=True)
out_svg = Path(out_svg) if out_svg is not None else None
ok_png = _render_dot_local(dot, out_png, "png", context=is_context)
targets: list[tuple[Path, str]] = [(out_png, "png")]
if out_svg is not None:
targets.append((out_svg, "svg"))
done = _render_dot_local_combined(dot, targets, context=is_context)
ok_png = "png" in done or _render_dot_local(dot, out_png, "png", context=is_context)
if not ok_png:
ok_png = _render_dot_kroki(dot, out_png, "png")
if not ok_png:
@@ -467,8 +510,7 @@ def write_dfd_outputs(
"DSL: https://github.com/pbauermeister/dfd"
)
if out_svg is not None:
out_svg = Path(out_svg)
if out_svg is not None and "svg" not in done:
ok_svg = _render_dot_local(dot, out_svg, "svg", context=is_context)
if not ok_svg:
_render_dot_kroki(dot, out_svg, "svg")