Skip to content

Commit 9c1882c

Browse files
committed
Add little function to detect unconnected COMs and ENUMs
1 parent 88ce8bc commit 9c1882c

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

docs/test_uml.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pathlib import Path
22

3-
from docs.uml import PlantUMLNetwork, build_network
3+
from docs.uml import PlantUMLNetwork, build_network, get_unconnected_coms_and_enums
44

55

66
def test_network_build() -> None:
@@ -10,3 +10,5 @@ def test_network_build() -> None:
1010
project_root_dir = Path(__file__).parent.parent
1111
module_dir = project_root_dir / "src/bo4e"
1212
_network, _namespaces_to_parse = build_network(module_dir, PlantUMLNetwork)
13+
unconnected_els = get_unconnected_coms_and_enums(_network)
14+
print(unconnected_els)

docs/uml.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import shlex
1515
import subprocess
1616
from abc import ABCMeta, abstractmethod
17+
from copy import copy
1718
from pathlib import Path
1819
from types import NoneType
1920
from typing import Any, Dict, List, Optional, Tuple, Type, Union, cast, get_args
@@ -594,3 +595,16 @@ def compile_files_plantuml(input_dir: Path, output_dir: Path, executable: Path)
594595
"""
595596
command = f'java -jar "{executable}" "{input_dir}" -svg -o "{output_dir}"'
596597
subprocess.call(shlex.split(command))
598+
599+
600+
def get_unconnected_coms_and_enums(graph: _UMLNetworkABC) -> set[str]:
601+
"""
602+
Detects all COMs and ENUMs which are not reachable from any BO inside the `graph`.
603+
"""
604+
all_nodes = set(graph.nodes)
605+
all_bos = set(filter(lambda modl_namespace: modl_namespace.startswith("bo4e.bo"), all_nodes))
606+
connected_nodes = copy(all_bos)
607+
for bo in all_bos:
608+
connected_nodes |= set(nx.descendants(graph, bo))
609+
610+
return all_nodes - connected_nodes

0 commit comments

Comments
 (0)