11import os
2+ from typing import TYPE_CHECKING , Optional , Union
23
34import plotly .graph_objects as go
45from networkx import Graph
78from codegen .sdk .core .interfaces .editable import Editable
89from codegen .shared .logging .get_logger import get_logger
910from codegen .visualizations .viz_utils import graph_to_json
10- from codegen .visualizations .module_dependency_viz import ModuleDependencyGraph , build_module_dependency_graph
11+
12+ if TYPE_CHECKING :
13+ from codegen .visualizations .module_dependency_viz import ModuleDependencyGraph
1114
1215logger = get_logger (__name__ )
1316
@@ -33,7 +36,7 @@ def clear_graphviz_data(self) -> None:
3336 if self .op .folder_exists (self .viz_path ):
3437 self .op .emptydir (self .viz_path )
3538
36- def write_graphviz_data (self , G : Graph | go .Figure | ModuleDependencyGraph , root : Editable | str | int | None = None ) -> None :
39+ def write_graphviz_data (self , G : Union [ Graph , go .Figure , " ModuleDependencyGraph" ] , root : Optional [ Union [ Editable , str , int ]] = None ) -> None :
3740 """Writes the graph data to a file.
3841
3942 Args:
@@ -50,8 +53,13 @@ def write_graphviz_data(self, G: Graph | go.Figure | ModuleDependencyGraph, root
5053 graph_json = graph_to_json (G , root )
5154 elif isinstance (G , go .Figure ):
5255 graph_json = G .to_json ()
53- elif isinstance (G , ModuleDependencyGraph ):
54- graph_json = G .to_json (root )
56+ else :
57+ # This is a ModuleDependencyGraph
58+ from codegen .visualizations .module_dependency_viz import ModuleDependencyGraph
59+ if isinstance (G , ModuleDependencyGraph ):
60+ graph_json = G .to_json (root )
61+ else :
62+ raise TypeError (f"Unsupported graph type: { type (G )} " )
5563
5664 # Check if the visualization path exists, if so, empty it
5765 if self .op .folder_exists (self .viz_path ):
0 commit comments