Coverage for lobster/common/graphviz_utils.py: 88%
8 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-07-15 06:41 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-07-15 06:41 +0000
1#!/usr/bin/env python3
2#
3# LOBSTER - Lightweight Open BMW Software Traceability Evidence Report
4# Copyright (C) 2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Affero General Public License as
8# published by the Free Software Foundation, either version 3 of the
9# License, or (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Affero General Public License for more details.
15#
16# You should have received a copy of the GNU Affero General Public
17# License along with this program. If not, see
18# <https://www.gnu.org/licenses/>.
19"""Shared Graphviz utilities for LOBSTER report tools."""
21import subprocess
22from typing import Optional
25def is_dot_available(dot: Optional[str] = None) -> bool:
26 """Return True if the ``dot`` executable (Graphviz) is on PATH.
28 Args:
29 dot: Optional explicit path to the ``dot`` binary. When ``None``
30 (default) the system PATH is searched.
32 Returns:
33 ``True`` if Graphviz ``dot`` is available, ``False`` otherwise.
34 """
35 try:
36 subprocess.run(
37 [dot if dot else "dot", "-V"],
38 stdout=subprocess.PIPE,
39 stderr=subprocess.PIPE,
40 encoding="UTF-8",
41 check=True,
42 timeout=5,
43 )
44 return True
45 except (FileNotFoundError, subprocess.TimeoutExpired,
46 subprocess.CalledProcessError):
47 return False